blob: 214ad2c1c338fe9d57640c7c27fd179c25d9b914 [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
31 // test default recursive behavior
Andrey Andreev99b782d2012-06-09 22:24:46 +030032 $expected = array(
vlakoff464ffae2013-07-16 18:11:59 +020033 'libraries'.$ds => array(
Andrey Andreev99b782d2012-06-09 22:24:46 +030034 'benchmark.html',
vlakoff464ffae2013-07-16 18:11:59 +020035 'database'.$ds => array('active_record.html', 'binds.html'),
vlakoff82808852012-09-13 05:19:59 +020036 'email.html',
37 '0'
Andrey Andreev99b782d2012-06-09 22:24:46 +030038 )
39 );
40
Hamza Bhatti575895f2012-03-11 11:58:31 +040041 $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
42
Hamza Bhatti575895f2012-03-11 11:58:31 +040043 // test detection of hidden files
vlakoff464ffae2013-07-16 18:11:59 +020044 $expected['libraries'.$ds][] = '.hiddenfile.txt';
Andrey Andreev99b782d2012-06-09 22:24:46 +030045
Hamza Bhatti575895f2012-03-11 11:58:31 +040046 $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
Andrey Andreev99b782d2012-06-09 22:24:46 +030047
48 // test recursion depth behavior
vlakoff464ffae2013-07-16 18:11:59 +020049 $this->assertEquals(array('libraries'.$ds), directory_map(vfsStream::url('testDir'), 1));
Andrey Andreev99b782d2012-06-09 22:24:46 +030050 }
51
Hamza Bhatti575895f2012-03-11 11:58:31 +040052}
53
54/* End of file directory_helper_test.php */