ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

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
38 function connect( $ConfigRow )
39 {
40 if( $ConfigRow == '1' )
41 {
42 return( true );
43 }
44 else
45 {
46 throw( new Exception( 'Connection failed' ) );
47 }
48 }
49
60 function get_connection()
61 {
62 return( true );
63 }
64
79 function validate_test_connection_without_errors( $MTime )
80 {
81 if( filemtime( dirname( __FILE__ ).'/cf_config' ) != $MTime )
82 {
83 return( 'ERROR: file was changed' );
84 }
85 else
86 {
87 return( 'TEST PASSED' );
88 }
89
90 unlink( dirname( __FILE__ ).'/cf_config' );
91 }
92
103 function test_connection_without_errors()
104 {
105 try
106 {
107 $CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
108 $CachedMultyFS->file_put_contents( dirname( __FILE__ ).'/cf_config' , "1\r\n2" );
109
110 $MTime = filemtime( dirname( __FILE__ ).'/cf_config' );
111
112 $DBConfigSet = get_package( 'database::db_config_set' , 'last' , __FILE__ );
113 $DBConfigSet->load_config( dirname( __FILE__ ).'/cf_config' );
114
115 $Connection = $DBConfigSet->connect( $this );
116
117 return( $this->validate_test_connection_without_errors( $MTime ) );
118 }
119 catch( Exception $e )
120 {
121 unlink( dirname( __FILE__ ).'/cf_config' );
122 return( 'ERROR: exception was thrown' );
123 }
124 }
125
136 function validate_test_connection_with_errors()
137 {
138 try
139 {
140 $CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
141 $Content = $CachedMultyFS->file_get_contents( dirname( __FILE__ ).'/cf_config' );
142 if( $Content != "1\r\n2\r\n" )
143 {
144 unlink( dirname( __FILE__ ).'/cf_config' );
145 return( "ERROR: illegal config content : $Content" );
146 }
147 else
148 {
149 /* $DBConfigSet->connect эксепшена не кинула и файл конфига не изменился */
150 unlink( dirname( __FILE__ ).'/cf_config' );
151 return( 'TEST PASSED' );
152 }
153 }
154 catch( Exception $e )
155 {
156 unlink( dirname( __FILE__ ).'/cf_config' );
157 return( 'ERROR: exception was thrown' );
158 }
159 }
160
171 function test_connection_with_errors()
172 {
173 try
174 {
175 $CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
176 $CachedMultyFS->file_put_contents( dirname( __FILE__ ).'/cf_config' , "2\r\n1" );
177
178 $DBConfigSet = get_package( 'database::db_config_set' , 'last' , __FILE__ );
179
180 $DBConfigSet->load_config( dirname( __FILE__ ).'/cf_config' );
181
182 $Connection = $DBConfigSet->connect( $this );
183
184 return( $this->validate_test_connection_with_errors() );
185 }
186 catch( Exception $e )
187 {
188 unlink( dirname( __FILE__ ).'/cf_config' );
189 return( 'ERROR: exception was thrown' );
190 }
191 }
192
203 function test_no_connection()
204 {
205 $Path = dirname( __FILE__ );
206 try
207 {
208 $CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
209 $CachedMultyFS->file_put_contents( $Path.'/cf_config' , "2\r\n3" );
210
211 $DBConfigSet = get_package( 'database::db_config_set' , 'last' , __FILE__ );
212
213 $DBConfigSet->load_config( $Path.'/cf_config' );
214
215 $Connection = $DBConfigSet->connect( $this );
216
217 unlink( $Path.'/cf_config' );
218 return( 'ERROR: exception must be thrown' );
219 }
220 catch( Exception $e )
221 {
222 if( $CachedMultyFS->file_get_contents( $Path.'/cf_config' ) != "2\r\n3" )
223 {
224 unlink( $Path.'/cf_config' );
225 return( 'ERROR: illegal config content' );
226 }
227 unlink( $Path.'/cf_config' );
228 return( 'TEST PASSED' );
229 }
230 }
231 }
232
233 ?>