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' => '', |
| 22 | '.hiddenfile.txt' => '' |
| 23 | ) |
| 24 | ); |
| 25 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 26 | vfsStream::create($structure, $this->_test_dir); |
| 27 | |
| 28 | // test default recursive behavior |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 29 | $expected = array( |
| 30 | 'libraries' => array( |
| 31 | 'benchmark.html', |
| 32 | 'database' => array('active_record.html', 'binds.html'), |
| 33 | 'email.html' |
| 34 | ) |
| 35 | ); |
| 36 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 37 | $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); |
| 38 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 39 | // test detection of hidden files |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 40 | $expected['libraries'][] = '.hiddenfile.txt'; |
| 41 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 42 | $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 43 | |
| 44 | // test recursion depth behavior |
| 45 | $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1)); |
| 46 | } |
| 47 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* End of file directory_helper_test.php */ |