blob: c39ccd8d0d9b59a9726c1a1858073f0ca218aca7 [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 {
Andrey Andreev99b782d2012-06-09 22:24:46 +030017 $structure = array(
18 'libraries' => array(
19 'benchmark.html' => '',
20 'database' => array('active_record.html' => '', 'binds.html' => ''),
21 'email.html' => '',
vlakoff82808852012-09-13 05:19:59 +020022 '0' => '',
Andrey Andreev99b782d2012-06-09 22:24:46 +030023 '.hiddenfile.txt' => ''
24 )
25 );
26
Hamza Bhatti575895f2012-03-11 11:58:31 +040027 vfsStream::create($structure, $this->_test_dir);
28
29 // test default recursive behavior
Andrey Andreev99b782d2012-06-09 22:24:46 +030030 $expected = array(
31 'libraries' => array(
32 'benchmark.html',
33 'database' => array('active_record.html', 'binds.html'),
vlakoff82808852012-09-13 05:19:59 +020034 'email.html',
35 '0'
Andrey Andreev99b782d2012-06-09 22:24:46 +030036 )
37 );
38
Hamza Bhatti575895f2012-03-11 11:58:31 +040039 $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
40
Hamza Bhatti575895f2012-03-11 11:58:31 +040041 // test detection of hidden files
Andrey Andreev99b782d2012-06-09 22:24:46 +030042 $expected['libraries'][] = '.hiddenfile.txt';
43
Hamza Bhatti575895f2012-03-11 11:58:31 +040044 $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
Andrey Andreev99b782d2012-06-09 22:24:46 +030045
46 // test recursion depth behavior
47 $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1));
48 }
49
Hamza Bhatti575895f2012-03-11 11:58:31 +040050}
51
52/* End of file directory_helper_test.php */