Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 1 | <?php |
| 2 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 3 | class Directory_helper_test extends CI_TestCase { |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 4 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 5 | public function set_up() |
| 6 | { |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 7 | $this->helper('directory'); |
| 8 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 9 | vfsStreamWrapper::register(); |
| 10 | vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 11 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 12 | $this->_test_dir = vfsStreamWrapper::getRoot(); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 13 | } |
| 14 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 15 | public function test_directory_map() |
| 16 | { |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 17 | $structure = array( |
| 18 | 'libraries' => array( |
| 19 | 'benchmark.html' => '', |
| 20 | 'database' => array('active_record.html' => '', 'binds.html' => ''), |
| 21 | 'email.html' => '', |
vlakoff | 8280885 | 2012-09-13 05:19:59 +0200 | [diff] [blame] | 22 | '0' => '', |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 23 | '.hiddenfile.txt' => '' |
| 24 | ) |
| 25 | ); |
| 26 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 27 | vfsStream::create($structure, $this->_test_dir); |
| 28 | |
| 29 | // test default recursive behavior |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 30 | $expected = array( |
Andrey Andreev | ac68a3c | 2012-11-06 15:44:00 +0200 | [diff] [blame] | 31 | 'libraries/' => array( |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 32 | 'benchmark.html', |
Andrey Andreev | e8b8904 | 2012-11-06 15:50:17 +0200 | [diff] [blame^] | 33 | 'database/' => array('active_record.html', 'binds.html'), |
vlakoff | 8280885 | 2012-09-13 05:19:59 +0200 | [diff] [blame] | 34 | 'email.html', |
| 35 | '0' |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 36 | ) |
| 37 | ); |
| 38 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 39 | $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); |
| 40 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 41 | // test detection of hidden files |
Andrey Andreev | ac68a3c | 2012-11-06 15:44:00 +0200 | [diff] [blame] | 42 | $expected['libraries/'][] = '.hiddenfile.txt'; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 43 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 44 | $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 45 | |
| 46 | // test recursion depth behavior |
Andrey Andreev | ac68a3c | 2012-11-06 15:44:00 +0200 | [diff] [blame] | 47 | $this->assertEquals(array('libraries/'), directory_map(vfsStream::url('testDir'), 1)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 48 | } |
| 49 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* End of file directory_helper_test.php */ |