ultimix
unit_tests.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 
26  class unit_tests{
27 
28  var $CacheSwitch;
29 
40  function set_up()
41  {
42  $Settings = get_package_object( 'settings::package_settings' , 'last' , __FILE__ );
43  $this->CacheSwitch = $Settings->get_package_setting(
44  'cache' , 'last' , 'cf_cache' , 'cache_switch' , 'off'
45  );
46  $Settings->set_package_setting( 'cache' , 'last' , 'cf_cache' , 'cache_switch' , 'on' );
47  }
48 
59  function tear_down()
60  {
61  $Settings = get_package_object( 'settings::package_settings' , 'last' , __FILE__ );
62  $Settings->set_package_setting( 'cache' , 'last' , 'cf_cache' , 'cache_switch' , $this->CacheSwitch );
63 
64  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
65  $Cache->drop_cache();
66  }
67 
79  {
80  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
81  $Data = $Cache->get_data( 'unexisting_data' );
82 
83  if( $Data === false )
84  {
85  return( 'TEST PASSED' );
86  }
87  else
88  {
89  return( 'ERROR' );
90  }
91  }
92 
104  {
105  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
106  $Data = $Cache->add_data( 'existing_data' , '5678' );
107  $Data = $Cache->set_data( 'existing_data' , '1234' );
108  $Data = $Cache->get_data( 'existing_data' );
109 
110  if( $Data === '1234' )
111  {
112  return( 'TEST PASSED' );
113  }
114  else
115  {
116  return( 'ERROR' );
117  }
118  }
119 
131  {
132  try
133  {
134  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
135  $Cache->delete_data( 'existing_data' );
136  $Data = $Cache->set_data( 'existing_data' , '1234' );
137 
138  return( 'ERROR' );
139  }
140  catch( Exception $e )
141  {
142  return( 'TEST PASSED' );
143  }
144  }
145 
157  {
158  try
159  {
160  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
161  if( $Cache->data_exists( 'existing_data' ) )
162  {
163  return( 'ERROR (1)' );
164  }
165 
166  $Data = $Cache->add_data( 'existing_data' , '1234' );
167  if( $Cache->data_exists( 'existing_data' ) === false )
168  {
169  return( 'ERROR (2)' );
170  }
171 
172  $Cache->delete_data( 'existing_data' );
173  if( $Cache->data_exists( 'existing_data' ) === false )
174  {
175  return( 'TEST PASSED' );
176  }
177  else
178  {
179  return( 'ERROR (3)' );
180  }
181  }
182  catch( Exception $e )
183  {
184  return( 'TEST PASSED' );
185  }
186  }
187 
199  {
200  try
201  {
202  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
203  $Cache->delete_data( 'existing_data' );
204  if( $Cache->data_exists( 'existing_data' ) )
205  {
206  return( 'ERROR (1)' );
207  }
208  $Data = $Cache->add_data( 'existing_data' , '1234' , array( 'one' , 'two' , 'three' ) );
209  if( $Cache->data_exists( 'existing_data' ) === false )
210  {
211  return( 'ERROR (2)' );
212  }
213  $Cache->delete_data_by_tag( 'two' );
214  if( $Cache->data_exists( 'existing_data' ) === false )
215  {
216  return( 'TEST PASSED' );
217  }
218  else
219  {
220  return( 'ERROR (3)' );
221  }
222  }
223  catch( Exception $e )
224  {
225  return( 'TEST PASSED' );
226  }
227  }
228  }
229 
230 ?>