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 | { |
vlakoff | 464ffae | 2013-07-16 18:11:59 +0200 | [diff] [blame] | 17 | $ds = DIRECTORY_SEPARATOR; |
| 18 | |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 19 | $structure = array( |
| 20 | 'libraries' => array( |
| 21 | 'benchmark.html' => '', |
| 22 | 'database' => array('active_record.html' => '', 'binds.html' => ''), |
| 23 | 'email.html' => '', |
vlakoff | 8280885 | 2012-09-13 05:19:59 +0200 | [diff] [blame] | 24 | '0' => '', |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 25 | '.hiddenfile.txt' => '' |
| 26 | ) |
| 27 | ); |
| 28 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 29 | vfsStream::create($structure, $this->_test_dir); |
| 30 | |
vlakoff | 7761fa6 | 2013-07-19 13:46:37 +0200 | [diff] [blame] | 31 | // is_dir(), opendir(), etc. seem to fail on Windows + vfsStream when there are trailing backslashes in directory names |
vlakoff | 69088d8 | 2013-07-19 20:13:51 +0200 | [diff] [blame] | 32 | if ( ! is_dir(vfsStream::url('testDir').DIRECTORY_SEPARATOR)) |
Andrey Andreev | a42f155 | 2013-07-19 13:02:03 +0300 | [diff] [blame] | 33 | { |
Andrey Andreev | 3ddd564 | 2014-02-17 17:31:23 +0200 | [diff] [blame] | 34 | $this->markTestSkipped("Can't test this under Windows"); |
Andrey Andreev | a42f155 | 2013-07-19 13:02:03 +0300 | [diff] [blame] | 35 | return; |
| 36 | } |
| 37 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 38 | // test default recursive behavior |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 39 | $expected = array( |
vlakoff | 464ffae | 2013-07-16 18:11:59 +0200 | [diff] [blame] | 40 | 'libraries'.$ds => array( |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 41 | 'benchmark.html', |
vlakoff | 464ffae | 2013-07-16 18:11:59 +0200 | [diff] [blame] | 42 | 'database'.$ds => array('active_record.html', 'binds.html'), |
vlakoff | 8280885 | 2012-09-13 05:19:59 +0200 | [diff] [blame] | 43 | 'email.html', |
| 44 | '0' |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 45 | ) |
| 46 | ); |
| 47 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 48 | $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); |
| 49 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 50 | // test detection of hidden files |
vlakoff | 464ffae | 2013-07-16 18:11:59 +0200 | [diff] [blame] | 51 | $expected['libraries'.$ds][] = '.hiddenfile.txt'; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 52 | |
vlakoff | 09b75b1 | 2013-07-19 11:05:23 +0200 | [diff] [blame] | 53 | $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 0, TRUE)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 54 | |
| 55 | // test recursion depth behavior |
vlakoff | 464ffae | 2013-07-16 18:11:59 +0200 | [diff] [blame] | 56 | $this->assertEquals(array('libraries'.$ds), directory_map(vfsStream::url('testDir'), 1)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 57 | } |
| 58 | |
Hamza Bhatti | 575895f | 2012-03-11 11:58:31 +0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* End of file directory_helper_test.php */ |