| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 class lmbIncludePathSupportTest extends UnitTestCase 11 { 12 var $old_include_path; 13 14 function setUp() 15 { 16 if(!is_dir(LIMB_VAR_DIR)) 17 mkdir(LIMB_VAR_DIR); 18 19 if(!is_dir(LIMB_VAR_DIR . '/tmp')) 20 mkdir(LIMB_VAR_DIR . '/tmp'); 21 22 $this->old_include_path = get_include_path(); 23 set_include_path(LIMB_VAR_DIR . '/tmp' . PATH_SEPARATOR . get_include_path()); 24 } 25 26 function tearDown() 27 { 28 $this->rm_dir(LIMB_VAR_DIR . '/tmp'); 29 set_include_path($this->old_include_path); 30 } 31 32 function testResolveIncludePathFileFailed() 33 { 34 $_ = $this->_rnd(); 35 $this->assertNull(lmb_resolve_include_path("{$_}bar.inc.php")); 36 } 37 38 function testResolveIncludePathFile() 39 { 40 $_ = $this->_rnd(); 41 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}foo.inc.php", "foo"); 42 43 $resolved = lmb_resolve_include_path("{$_}foo.inc.php"); 44 45 $this->assertEqual(file_get_contents($resolved), "foo"); 46 } 47 48 function testResolveIncludePathDir() 49 { 50 $_ = $this->_rnd(); 51 mkdir(LIMB_VAR_DIR . '/tmp/' . $_); 52 53 $resolved = lmb_resolve_include_path($_); 54 $this->assertEqual($resolved, LIMB_VAR_DIR . '/tmp/' . $_); 55 56 rmdir(LIMB_VAR_DIR . '/tmp/' . $_); 57 } 58 59 function testGlobFailedForRelativePath() 60 { 61 $_ = $this->_rnd(); 62 $files = lmb_glob("{$_}*.inc.php"); 63 $this->assertEqual($files, array()); 64 } 65 66 function testGlobFailedForAbsolutePath() 67 { 68 $_ = $this->_rnd(); 69 $files = lmb_glob(LIMB_VAR_DIR . "/tmp/{$_}*.inc.php"); 70 $this->assertEqual($files, array()); 71 } 72 73 function testGlobForRelativePath() 74 { 75 $_ = $this->_rnd(); 76 77 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}bar.inc.php", "bar"); 78 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}foo.inc.php", "foo"); 79 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}zoo.inc.php", "zoo"); 80 81 $files = lmb_glob("{$_}*.inc.php"); 82 83 sort($files); 84 85 $this->assertEqual(sizeof($files), 3); 86 $this->assertEqual(file_get_contents($files[0]), "bar"); 87 $this->assertEqual(file_get_contents($files[1]), "foo"); 88 $this->assertEqual(file_get_contents($files[2]), "zoo"); 89 } 90 91 function testGlobForAbsolutePath() 92 { 93 $_ = $this->_rnd(); 94 95 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}bar.inc.php", "bar"); 96 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}foo.inc.php", "foo"); 97 file_put_contents(LIMB_VAR_DIR . "/tmp/{$_}zoo.inc.php", "zoo"); 98 99 $files = lmb_glob(LIMB_VAR_DIR . "/tmp/{$_}*.inc.php"); 100 101 sort($files); 102 103 $this->assertEqual(sizeof($files), 3); 104 $this->assertEqual(file_get_contents($files[0]), "bar"); 105 $this->assertEqual(file_get_contents($files[1]), "foo"); 106 $this->assertEqual(file_get_contents($files[2]), "zoo"); 107 } 108 109 function _rnd() 110 { 111 return mt_rand(1, 1000); 112 } 113 114 function rm_dir($path) 115 { 116 $dir = opendir($path); 117 while($entry = readdir($dir)) 118 { 119 if(is_file("$path/$entry")) 120 { 121 unlink("$path/$entry"); 122 } 123 elseif(is_dir("$path/$entry") && $entry != '.' && $entry != '..') 124 { 125 $this->rm_dir("$path/$entry"); 126 } 127 } 128 129 closedir($dir); 130 return rmdir($path); 131 } 132 } 133 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Aug 29 04:49:26 2008 | Cross-referenced by PHPXref 0.7 |