blob: ac71dfaf8ff73db30dbab0bd8da12ff80fe3235e [file] [log] [blame]
Hamza Bhatti575895f2012-03-11 11:58:31 +04001<?php
2
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07003class Directory_helper_test extends CI_TestCase {
Andrey Andreev99b782d2012-06-09 22:24:46 +03004
Hamza Bhatti575895f2012-03-11 11:58:31 +04005 public function set_up()
6 {
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07007 $this->helper('directory');
8
Hamza Bhatti575895f2012-03-11 11:58:31 +04009 vfsStreamWrapper::register();
10 vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030011
Hamza Bhatti575895f2012-03-11 11:58:31 +040012 $this->_test_dir = vfsStreamWrapper::getRoot();
Andrey Andreev99b782d2012-06-09 22:24:46 +030013 }
14
Hamza Bhatti575895f2012-03-11 11:58:31 +040015 public function test_directory_map()
16 {
vlakoff464ffae2013-07-16 18:11:59 +020017 $ds = DIRECTORY_SEPARATOR;
18
Andrey Andreev99b782d2012-06-09 22:24:46 +030019 $structure = array(
20 'libraries' => array(
21 'benchmark.html' => '',
22 'database' => array('active_record.html' => '', 'binds.html' => ''),
23 'email.html' => '',
vlakoff82808852012-09-13 05:19:59 +020024 '0' => '',
Andrey Andreev99b782d2012-06-09 22:24:46 +030025 '.hiddenfile.txt' => ''
26 )
27 );
28
Hamza Bhatti575895f2012-03-11 11:58:31 +040029 vfsStream::create($structure, $this->_test_dir);
30
vlakoff7761fa62013-07-19 13:46:37 +020031 // is_dir(), opendir(), etc. seem to fail on Windows + vfsStream when there are trailing backslashes in directory names
vlakoff69088d82013-07-19 20:13:51 +020032 if ( ! is_dir(vfsStream::url('testDir').DIRECTORY_SEPARATOR))
Andrey Andreeva42f1552013-07-19 13:02:03 +030033 {
Andrey Andreev3ddd5642014-02-17 17:31:23 +020034 $this->markTestSkipped("Can't test this under Windows");
Andrey Andreeva42f1552013-07-19 13:02:03 +030035 return;
36 }
37
Hamza Bhatti575895f2012-03-11 11:58:31 +040038 // test default recursive behavior
Andrey Andreev99b782d2012-06-09 22:24:46 +030039 $expected = array(
vlakoff464ffae2013-07-16 18:11:59 +020040 'libraries'.$ds => array(
Andrey Andreev99b782d2012-06-09 22:24:46 +030041 'benchmark.html',
vlakoff464ffae2013-07-16 18:11:59 +020042 'database'.$ds => array('active_record.html', 'binds.html'),
vlakoff82808852012-09-13 05:19:59 +020043 'email.html',
44 '0'
Andrey Andreev99b782d2012-06-09 22:24:46 +030045 )
46 );
47
Hamza Bhatti575895f2012-03-11 11:58:31 +040048 $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
49
Hamza Bhatti575895f2012-03-11 11:58:31 +040050 // test detection of hidden files
vlakoff464ffae2013-07-16 18:11:59 +020051 $expected['libraries'.$ds][] = '.hiddenfile.txt';
Andrey Andreev99b782d2012-06-09 22:24:46 +030052
vlakoff09b75b12013-07-19 11:05:23 +020053 $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 0, TRUE));
Andrey Andreev99b782d2012-06-09 22:24:46 +030054
55 // test recursion depth behavior
vlakoff464ffae2013-07-16 18:11:59 +020056 $this->assertEquals(array('libraries'.$ds), directory_map(vfsStream::url('testDir'), 1));
Andrey Andreev99b782d2012-06-09 22:24:46 +030057 }
58
Hamza Bhatti575895f2012-03-11 11:58:31 +040059}
60
61/* End of file directory_helper_test.php */