ultimix
testing.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $TestingObject = false;
39 
59  {
60  try
61  {
62  $Security = get_package( 'security' , 'last' );
63 
64  $PackageDirectory = _get_package_relative_path_ex(
65  $Security->get_gp( 'testing_package_name' , 'command' ) ,
66  $Security->get_gp( 'testing_package_version' , 'command' , 'last' )
67  );
68 
69  return( $PackageDirectory );
70  }
71  catch( Exception $e )
72  {
73  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
74  }
75  }
76 
95  function get_testing_object()
96  {
97  try
98  {
99  if( $this->TestingObject === false )
100  {
101  $PackageDirectory = $this->get_package_directory();
102 
103  if( file_exists( "$PackageDirectory/include/php/unit_tests.php" ) === false )
104  {
105  return( false );
106  }
107 
108  require_once( "$PackageDirectory/include/php/unit_tests.php" );
109  $this->TestingObject = new unit_tests();
110  }
111 
112  if( $this->TestingObject === false )
113  {
114  throw( new Exception( "Testing class was not found" ) );
115  }
116  }
117  catch( Exception $e )
118  {
119  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
120  }
121  }
122 
145  function security( $Options )
146  {
147  try
148  {
149  $UserController = get_package( 'user::user_controller' , 'last' , __FILE__ );
150  $UserController->login( $Options );
151 
152  $Permits = get_package( 'permit::permit_algorithms' , 'last' , __FILE__ );
153  if( $Permits->object_has_permit( false , 'user' , 'tester' ) === false )
154  {
155  $UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
156  print( $UserAlgorithms->get_login() );
157  return( 'No permits' );
158  }
159 
160  return( false );
161  }
162  catch( Exception $e )
163  {
164  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
165  }
166  }
167 
187  {
188  try
189  {
190  /* gettting count of tests */
191  $this->get_testing_object();
192 
193  $Methods = get_class_methods( get_class( $this->TestingObject ) );
194 
195  $Counter = 0;
196  foreach( $Methods as $key => $m )
197  {
198  if( strpos( $m , 'test' ) === 0 )
199  {
200  $Counter++;
201  }
202  }
203 
204  return( $Counter );
205  }
206  catch( Exception $e )
207  {
208  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
209  }
210  }
211 
230  function get_sub_test_name()
231  {
232  try
233  {
234  $this->get_testing_object();
235 
236  $Methods = get_class_methods( get_class( $this->TestingObject ) );
237 
238  $Counter = 0;
239  $Security = get_package( 'security' , 'last' );
240  foreach( $Methods as $key => $m )
241  {
242  if( strpos( $m , 'test' ) === 0 )
243  {
244  if( $Counter == $Security->get_gp( 'test_id' , 'integer' ) )
245  {
246  return( $m );
247  }
248  $Counter++;
249  }
250  }
251  if( $Security->get_gp( 'test_id' , 'integer' , 0 ) >= $Counter )
252  {
253  return( 'Value test_id is too big. It mast be less than '.$Counter );
254  }
255  }
256  catch( Exception $e )
257  {
258  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
259  }
260  }
261 
280  function run_exact_test( $Methods , $m )
281  {
282  try
283  {
284  if( in_array( 'set_up' , $Methods ) )
285  {
286  call_user_func_array( array( $this->TestingObject , 'set_up' ) , array() );
287  }
288 
289  $Result = call_user_func_array( array( $this->TestingObject , $m ) , array() );
290 
291  if( in_array( 'tear_down' , $Methods ) )
292  {
293  call_user_func_array( array( $this->TestingObject , 'tear_down' ) , array() );
294  }
295 
296  return( $Result );
297  }
298  catch( Exception $e )
299  {
300  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
301  }
302  }
303 
326  function find_test_and_run( $Methods )
327  {
328  try
329  {
330  $Counter = 0;
331  $Security = get_package( 'security' , 'last' );
332 
333  foreach( $Methods as $key => $m )
334  {
335  if( strpos( $m , 'test' ) === 0 && $Counter++ == $Security->get_gp( 'test_id' , 'integer' ) )
336  {
337  return( $this->run_exact_test( $Methods , $m ) );
338  }
339  }
340 
341  if( $Security->get_gp( 'test_id' , 'integer' , 0 ) >= $Counter )
342  {
343  return( 'Value test_id is too big. It mast be less than '.$Counter );
344  }
345  else
346  {
347  return( 'Test was not called' );
348  }
349  }
350  catch( Exception $e )
351  {
352  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
353  }
354  }
355 
374  function run_sub_test()
375  {
376  try
377  {
378  /* running subtest */
379  $this->get_testing_object();
380  $Methods = get_class_methods( get_class( $this->TestingObject ) );
381 
382  if( isset( $Methods[ 0 ] ) == false )
383  {
384  return( 'No test were found' );
385  }
386 
387  return( $this->find_test_and_run( $Methods ) );
388  }
389  catch( Exception $e )
390  {
391  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
392  }
393  }
394 
413  function run_views()
414  {
415  try
416  {
417  $Security = get_package( 'security' , 'last' );
418 
419  if( $Security->get_gp( 'action' , 'command' , 'none' ) === 'get_sub_test_count' )
420  {
421  return( $this->get_sub_test_count() );
422  }
423 
424  if( $Security->get_gp( 'action' , 'command' , 'none' ) === 'get_sub_test_name' )
425  {
426  return( $this->get_sub_test_name() );
427  }
428 
429  if( $Security->get_gp( 'action' , 'command' , 'none' ) === 'run_sub_test' )
430  {
431  return( $this->run_sub_test() );
432  }
433 
434  return( 'Illegal request parameters' );
435  }
436  catch( Exception $e )
437  {
438  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
439  }
440  }
441 
464  function view( $Options )
465  {
466  try
467  {
468  if( ( $Result = $this->security( $Options ) ) !== false )
469  {
470  return( $Result );
471  }
472 
473  return( $this->run_views() );
474  }
475  catch( Exception $e )
476  {
477  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
478  }
479  }
480  }
481 
482 ?>