3 define('AK_UPLOAD_FILES_USING_FTP', true);
4 define('AK_READ_FILES_USING_FTP', true);
5 define('AK_DELETE_FILES_USING_FTP', true);
6 define('AK_FTP_PATH', 'ftp://tests:tests@tests.akelos.com');
7 define('AK_FTP_AUTO_DISCONNECT', true);
9 require_once(dirname(__FILE__
).'/../../../fixtures/config/config.php');
11 require_once(AK_LIB_DIR
.DS
.'Ak.php');
13 class test_AkFileFunctionsUsingFtp
extends UnitTestCase
15 function Test_file_put_contents()
17 $file_name = AK_TMP_DIR
.DS
.'test_file_1.txt';
18 $content = 'This is the content of file 1';
19 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
21 $file_name = '/cache'.DS
.'test_file_1.txt';
22 $content = 'This is the NEW content for file 1';
23 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
25 $file_name = AK_TMP_DIR
.DS
.'test_file_2.txt';
26 $content = "\n\rThis is the content of file 2\n";
27 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
29 $file_name = 'cache'.DS
.'test_file_3.txt';
30 $content = "\rThis is the content of file 3\r\n";
31 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
33 $file_name = 'cache\test_file_4.txt';
34 $content = "\rThis is the content of file 4\r\n";
35 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
37 $file_name = 'ak_test_folder/test_file.txt';
38 $content = "\rThis is the content of the test file";
39 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
41 $file_name = 'ak_test_folder/new_folder/test_file.txt';
42 $content = "\rThis is the content of the test file";
43 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
46 $file_name = 'ak_test_folder/folder with space/test file.txt';
47 $content = "\rThis is the content of the test file";
48 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
52 function Test_file_get_contents()
54 $file_name = AK_TMP_DIR
.DS
.'test_file_1.txt';
55 $content = 'This is the NEW content for file 1';
56 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
58 $file_name = AK_TMP_DIR
.DS
.'test_file_2.txt';
59 $content = "\n\rThis is the content of file 2\n";
60 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
62 $file_name = 'cache'.DS
.'test_file_3.txt';
63 $content = "\rThis is the content of file 3\r\n";
64 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
66 $file_name = 'cache\test_file_4.txt';
67 $content = "\rThis is the content of file 4\r\n";
68 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
70 $file_name = 'ak_test_folder/folder with space/test file.txt';
71 $content = "\rThis is the content of the test file";
72 $this->assertEqual(Ak
::file_get_contents($file_name), $content);
76 function Test_file_delete()
78 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.DS
.'test_file_1.txt'));
79 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.DS
.'test_file_2.txt'));
80 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.DS
.'test_file_3.txt'));
81 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.'\test_file_4.txt'));
82 $this->assertTrue(Ak
::file_delete('ak_test_folder/new_folder/test_file.txt'));
83 $this->assertTrue(Ak
::file_delete('ak_test_folder/folder with space/test file.txt'));
87 function Test_directory_delete()
89 $this->assertTrue(Ak
::directory_delete('ak_test_folder'));
90 $this->assertFalse(Ak
::directory_delete('../../'));
91 $this->assertFalse(Ak
::directory_delete('..\..\\'));
92 $this->assertFalse(Ak
::directory_delete(' '));
93 $this->assertFalse(Ak
::directory_delete('/'));
94 $this->assertFalse(Ak
::directory_delete('./'));
99 class Test_of_Ak_static_file_functions_using_ftp
extends UnitTestCase
101 function Test_connect()
103 $connection = AkFtp
::connect();
104 $this->assertTrue($connection);
105 $this->assertTrue(is_resource($connection) && get_resource_type($connection) == 'FTP Buffer');
106 $this->assertIdentical($connection, AkFtp
::connect());
109 function Test_disconnect()
111 $this->assertTrue(AkFtp
::disconnect());
115 function Test_file_put_contents()
117 $file_name = AK_TMP_DIR
.DS
.'test_file_1.txt';
118 $content = 'This is the content of file 1';
119 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
121 $file_name = '/cache'.DS
.'test_file_1.txt';
122 $content = 'This is the NEW content for file 1';
123 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
125 $file_name = AK_TMP_DIR
.DS
.'test_file_2.txt';
126 $content = "\n\rThis is the content of file 2\n";
127 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
129 $file_name = 'cache'.DS
.'test_file_3.txt';
130 $content = "\rThis is the content of file 3\r\n";
131 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
133 $file_name = 'cache\test_file_4.txt';
134 $content = "\rThis is the content of file 4\r\n";
135 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
137 $file_name = 'ak_test_folder/test_file.txt';
138 $content = "\rThis is the content of the test file";
139 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
141 $file_name = 'ak_test_folder/new_folder/test_file.txt';
142 $content = "\rThis is the content of the test file";
143 $this->assertTrue(Ak
::file_put_contents($file_name, $content));
146 function Test_file_get_contents()
148 $file_name = AK_TMP_DIR
.DS
.'test_file_1.txt';
149 $content = 'This is the NEW content for file 1';
150 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
152 $file_name = AK_TMP_DIR
.DS
.'test_file_2.txt';
153 $content = "\n\rThis is the content of file 2\n";
154 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
156 $file_name = 'cache'.DS
.'test_file_3.txt';
157 $content = "\rThis is the content of file 3\r\n";
158 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
160 $file_name = 'cache\test_file_4.txt';
161 $content = "\rThis is the content of file 4\r\n";
162 $this->assertTrue(Ak
::file_get_contents($file_name) === $content);
166 function Test_file_delete()
168 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.DS
.'test_file_1.txt'));
169 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.DS
.'test_file_2.txt'));
170 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.DS
.'test_file_3.txt'));
171 $this->assertTrue(Ak
::file_delete(AK_TMP_DIR
.'\test_file_4.txt'));
172 $this->assertTrue(Ak
::file_delete('ak_test_folder/new_folder/test_file.txt'));
176 function Test_directory_delete()
178 $this->assertTrue(Ak
::directory_delete('ak_test_folder'));
179 $this->assertFalse(Ak
::directory_delete('../../'));
180 $this->assertFalse(Ak
::directory_delete('..\..\\'));
181 $this->assertFalse(Ak
::directory_delete(' '));
182 $this->assertFalse(Ak
::directory_delete('/'));
183 $this->assertFalse(Ak
::directory_delete('./'));
187 function Test_make_dir()
189 $this->assertTrue(AkFtp
::make_dir('new_dir_1'));
190 $this->assertTrue(AkFtp
::make_dir('/new_dir_2'));
191 $this->assertTrue(AkFtp
::make_dir('new_dir_3/'));
192 $this->assertTrue(AkFtp
::make_dir('./new_dir_4'));
193 $this->assertTrue(AkFtp
::make_dir('../new_dir_5'));
194 $this->assertTrue(AkFtp
::make_dir('./new_dir_6/'));
195 $this->assertTrue(AkFtp
::make_dir('../new_dir_7/'));
197 $this->assertTrue(AkFtp
::make_dir('new_dir_1/subdir_1'));
198 $this->assertTrue(AkFtp
::make_dir('/new_dir_2/subdir_1'));
199 $this->assertTrue(AkFtp
::make_dir('new_dir_3/subdir_1'));
200 $this->assertTrue(AkFtp
::make_dir('./new_dir_4/subdir_1'));
201 $this->assertTrue(AkFtp
::make_dir('../new_dir_5/subdir_1'));
202 $this->assertTrue(AkFtp
::make_dir('./new_dir_6/subdir_1'));
203 $this->assertTrue(AkFtp
::make_dir('../new_dir_7/subdir_1'));
205 $this->assertTrue(AkFtp
::make_dir('new_dir_1/subdir_2/subsubdir2'));
206 $this->assertTrue(AkFtp
::make_dir('/new_dir_2/subdir_2/subsubdir2'));
207 $this->assertTrue(AkFtp
::make_dir('new_dir_3/subdir_2/subsubdir2'));
208 $this->assertTrue(AkFtp
::make_dir('./new_dir_4/subdir_2/subsubdir2'));
209 $this->assertTrue(AkFtp
::make_dir('../new_dir_5/subdir_2/subsubdir2'));
210 $this->assertTrue(AkFtp
::make_dir('./new_dir_6/subdir_2/subsubdir2'));
211 $this->assertTrue(AkFtp
::make_dir('../new_dir_7/subdir_2/subsubdir2'));
213 $this->assertTrue(AkFtp
::make_dir('new_dir_8/subdir_1/subsubdir1'));
217 function Test_delete()
219 $this->assertTrue(AkFtp
::delete('new_dir_8/*'));
221 $this->assertTrue(Ak
::file_put_contents('prueba.txt', ''));
222 $this->assertTrue(AkFtp
::delete('prueba.txt'));
224 $this->assertTrue(Ak
::file_put_contents('new_dir_1/prueba.txt', ''));
225 $this->assertTrue(AkFtp
::delete('new_dir_1/prueba.txt'));
227 $this->assertTrue(AkFtp
::delete('new_dir_2/subdir_1'));
229 $this->assertError(AkFtp
::delete('new_dir_2/subdir'));
230 $this->assertError(AkFtp
::delete('new_dir_2/subdir_1'));
232 $this->assertTrue(AkFtp
::delete('new_dir_1'));
233 $this->assertTrue(AkFtp
::delete('new_dir_2'));
234 $this->assertTrue(AkFtp
::delete('../new_dir_3'));
235 $this->assertTrue(AkFtp
::delete('./new_dir_4'));
236 $this->assertTrue(AkFtp
::delete('./new_dir_5/'));
237 $this->assertTrue(AkFtp
::delete('new_dir_6/'));
238 $this->assertTrue(AkFtp
::delete('/new_dir_7'));
239 $this->assertTrue(AkFtp
::delete('/new_dir_8/'));
242 function Test_is_dir()
244 $path = 'invalid path';
245 $this->assertFalse(AkFtp
::is_dir($path));
247 $path = 'this_is_a_file.txt';
248 Ak
::file_put_contents('this_is_a_file.txt', '');
250 $this->assertFalse(AkFtp
::is_dir($path));
252 AkFtp
::make_dir('tmp_test_dir');
253 Ak
::file_put_contents('tmp_test_dir/file_inside.txt', '');
255 $path = 'tmp_test_dir/file_inside.txt';
256 $this->assertFalse(AkFtp
::is_dir($path));
259 AkFtp
::make_dir('real_dir/another/dir');
262 $this->assertTrue(AkFtp
::is_dir($path));
264 $path = 'real_dir/another/dir';
265 $this->assertTrue(AkFtp
::is_dir($path));
267 AkFtp
::delete('real_dir');
268 AkFtp
::delete('this_is_a_file.txt');
269 AkFtp
::delete('tmp_test_dir');
274 ak_test('test_AkFileFunctionsUsingFtp');