function find_subitems($dir, $types = 'dfl', $exclude_regex = '', $add_path = true, $include_hidden = false) { $dir = fs :: clean_path($dir); $dir = fs :: chop($dir); $items = array(); $separator = fs :: separator(); if ($handle = opendir($dir)) { while(($element = readdir($handle)) !== false) { if ($element == '.' || $element == '..') continue; if (!$include_hidden && $element[0] == '.') continue; if ($exclude_regex && preg_match($exclude_regex, $element)) continue; if (is_dir($dir . $separator . $element) && strpos($types, 'd') === false) continue; if (is_link($dir . $separator . $element) && strpos($types, 'l') === false) continue; if (is_file( $dir . $separator . $element ) && strpos($types, 'f') === false) continue; if ($add_path) { if (is_string($add_path)) $items[] = $add_path . $separator . $element; else $items[] = $dir . $separator . $element; } else $items[] = $element; } closedir($handle); } return $items; }
function test_path() { $this->assertEqual(fs :: path(array('test')), 'test'); $this->assertEqual(fs :: path(array('test', 'wow')), 'test' . fs :: separator() . 'wow'); $this->assertEqual(fs :: path(array('test', 'wow/')), 'test' . fs :: separator() . 'wow'); $this->assertEqual(fs :: path(array('test'), true), 'test' . fs :: separator()); $this->assertEqual(fs :: path(array('test', 'wow'), true), 'test' . fs :: separator() . 'wow' . fs :: separator()); }
function test_walk_dir() { $this->_create_file_system(); $mock =& new special_dir_walker($this); $mock->expectCallCount('walk', 9+2); if(sys :: os_type() == 'win32') { $mock->expectArgumentsAt(0, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'test1_1', array('test', 'separator' => fs :: separator()), array(0))); $mock->expectArgumentsAt(1, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'test1_2', array('test', 'separator' => fs :: separator()), array(0, 1))); $mock->expectArgumentsAt(2, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'test1_3', array('test', 'separator' => fs :: separator()), array(0, 1, 2))); $mock->expectArgumentsAt(3, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'wow', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3))); $mock->expectArgumentsAt(4, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'hey', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4))); $mock->expectArgumentsAt(5, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey'), 'test3_1', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5))); $mock->expectArgumentsAt(6, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey'), 'test3_2', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6))); $mock->expectArgumentsAt(7, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey'), 'test3_3', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7))); $mock->expectArgumentsAt(8, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'test2_1', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7, 8))); $mock->expectArgumentsAt(9, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'test2_2', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))); $mock->expectArgumentsAt(10, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'test2_3', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))); } elseif(sys :: os_type() == 'unix') { $mock->expectArgumentsAt(0, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'wow', array('test', 'separator' => fs :: separator()), array(0))); $mock->expectArgumentsAt(1, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'hey', array('test', 'separator' => fs :: separator()), array(0, 1))); $mock->expectArgumentsAt(2, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey'), 'test3_1', array('test', 'separator' => fs :: separator()), array(0, 1, 2))); $mock->expectArgumentsAt(3, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey'), 'test3_2', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3))); $mock->expectArgumentsAt(4, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow/hey'), 'test3_3', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4))); $mock->expectArgumentsAt(5, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'test2_1', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5))); $mock->expectArgumentsAt(6, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'test2_2', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6))); $mock->expectArgumentsAt(7, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp/wow'), 'test2_3', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7))); $mock->expectArgumentsAt(8, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'test1_1', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7, 8))); $mock->expectArgumentsAt(9, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'test1_2', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))); $mock->expectArgumentsAt(10, 'walk', array(fs :: clean_path(TEST_DIR_ABSOLUTE_PATH . '/tmp'), 'test1_3', array('test', 'separator' => fs :: separator()), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))); } $this->assertEqual( fs :: walk_dir(TEST_DIR_ABSOLUTE_PATH . '/tmp/', array(&$mock, 'walk'), array('test')), array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) ); $mock->tally(); $this->_remove_file_system(); }
function test_flush() { $this->_write_simple_cache('f_test1', $content1 = 'test-content1'); $this->_write_simple_cache('f_test2', $content2 ='test-content2'); $this->_write_simple_cache('not_page_file', $content3 ='test-content3'); $cache_manager =& new full_page_cache_manager(); $cache_manager->flush(); $files = fs :: find(PAGE_CACHE_DIR); $this->assertEqual(sizeof($files), 1); $file = reset($files); $this->assertEqual(fs :: normalize_path($file), fs :: normalize_path(PAGE_CACHE_DIR . fs :: separator() . 'not_page_file')); $this->_clean_simple_cache('not_page_file'); }
function walk_dir($dir, $function_def, $params=array(), $include_first=false) { $return_params = array(); $separator = fs :: separator(); $dir = fs :: normalize_path($dir); $dir = fs :: chop($dir); $params['separator'] = $separator; fs :: _do_walk_dir($dir, $separator, $function_def, $return_params, $params, $include_first); return $return_params; }