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  $Cache = get_package( 'cache' , 'last' , __FILE__ );
49  $Cache->flush();
50  $Cache->reset();
51  }
52 
63  function tear_down()
64  {
65  $Settings = get_package_object( 'settings::package_settings' , 'last' , __FILE__ );
66  $Settings->set_package_setting( 'cache' , 'last' , 'cf_cache' , 'cache_switch' , $this->CacheSwitch );
67 
68  $Cache = get_package_object( 'cache' , 'last' , __FILE__ );
69  $Cache->drop_cache();
70  }
71 
83  {
84  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
85  $CachedFS->Cache->delete_data( './packages/index.html' );
86 
87  if( $CachedFS->file_exists( './packages/index.html' ) === true &&
88  $CachedFS->Cache->data_exists( './packages/index.html' ) === false )
89  {
90  return( 'TEST PASSED' );
91  }
92  else
93  {
94  return( 'ERROR' );
95  }
96  }
97 
109  {
110  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
111  $CachedFS->file_exists( './unexisting' );
112 
113  if( $CachedFS->Cache->data_exists( './unexisting' ) === true &&
114  $CachedFS->Cache->get_data( './unexisting' ) == '_file_was_not_found' )
115  {
116  return( 'TEST PASSED' );
117  }
118  else
119  {
120  return( 'ERROR' );
121  }
122  }
123 
135  {
136  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
137  $CachedFS->file_exists( './packages/index.html' );
138 
139  $DataExists = $CachedFS->Cache->data_exists( './packages/index.html' );
140  $Data = $CachedFS->Cache->get_data( './packages/index.html' );
141 
142  if( $DataExists === false && $Data === false )
143  {
144  return( 'TEST PASSED' );
145  }
146  else
147  {
148  return( 'ERROR : Data exists : '.( $DataExists ? 1 : 0 ).' Data : '.htmlspecialchars( $Data ) );
149  }
150  }
151 
163  {
164  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
165  $CachedFS->Cache->delete_data( './packages/index.html' );
166  $Result = $CachedFS->file_get_contents( './packages/index.html' );
167 
168  if( $Result == '<html><head></head><body></body></html>' )
169  {
170  return( 'TEST PASSED' );
171  }
172  else
173  {
174  return( 'ERROR' );
175  }
176  }
177 
189  {
190  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
191 
192  $CachedFS->file_get_contents( './packages/index.html' );
193 
194  file_put_contents( './packages/index.html' , '' );
195 
196  $Result = $CachedFS->file_get_contents( './packages/index.html' );
197 
198  file_put_contents( './packages/index.html' , '<html><head></head><body></body></html>' );
199 
200  if( $Result == '<html><head></head><body></body></html>' )
201  {
202  return( 'TEST PASSED' );
203  }
204  else
205  {
206  return( 'ERROR : Content : '.htmlspecialchars( $Result ) );
207  }
208  }
209 
221  {
222  try
223  {
224  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
225  $CachedFS->Cache->delete_data( './unexisting' );
226  $CachedFS->file_get_contents( './unexisting' );
227 
228  return( 'ERROR' );
229  }
230  catch( Exception $e )
231  {
232  return( 'TEST PASSED' );
233  }
234  }
235 
247  {
248  $CachedFS = get_package_object( 'cached_fs' , 'last' , __FILE__ );
249 
250  $CachedFS->file_put_contents( './exception.log' , '' );
251 
252  // проверим что информация сохранилась в кэше
253  if( $CachedFS->file_exists( './exception.log' ) === false )
254  {
255  return( 'ERROR' );
256  }
257 
258  // проверим что информация сохранилась на диске
259  $CachedFS->Cache->delete_data( './packages/index.html' );
260  if( $CachedFS->file_exists( './exception.log' ) === false )
261  {
262  return( 'ERROR' );
263  }
264 
265  return( 'TEST PASSED' );
266  }
267  }
268 
269 ?>