[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/fs/tests/cases/ -> lmbFsRecursiveIteratorTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/fs/src/lmbFsRecursiveIterator.class.php');
  10  lmb_require('limb/fs/src/lmbFs.class.php');
  11  
  12  class lmbFsRecursiveIteratorTest extends UnitTestCase
  13  {
  14    var $dir;
  15  
  16    function lmbFsRecursiveIteratorTest()
  17    {
  18      $this->dir = LIMB_VAR_DIR . '/tmp/';
  19      parent :: UnitTestCase();
  20    }
  21  
  22    function _createFileSystem()
  23    {
  24      lmbFs :: mkdir($this->dir);
  25      touch($this->dir . '/a');
  26  
  27      lmbFs :: mkdir($this->dir . '/nested/.sub-nested/');
  28      touch($this->dir . '/nested/.sub-nested/d');
  29  
  30      lmbFs :: mkdir($this->dir . '/nested/b');
  31      touch($this->dir . '/nested/c');
  32    }
  33  
  34    function _removeFileSystem()
  35    {
  36      lmbFs :: rm($this->dir);
  37    }
  38  
  39    function testExceptionIterate()
  40    {
  41      $it = new lmbFsRecursiveIterator('no-such-a-dir');
  42  
  43      try
  44      {
  45        $it->rewind();
  46        $this->assertTrue(false);
  47      }
  48      catch(lmbFsException $e){}
  49    }
  50  
  51    function testSimpleIterate()
  52    {
  53      lmbFs :: rm($this->dir);
  54      lmbFs :: mkdir($this->dir);
  55  
  56      $it = new lmbFsRecursiveIterator($this->dir);
  57  
  58      $it->rewind();
  59      $this->_assertDotDir($it, $this->dir . '/.', __LINE__);
  60  
  61      $it->next();
  62      $this->_assertDotDir($it, $this->dir . '/..', __LINE__);
  63  
  64      $it->next();
  65      $this->assertFalse($it->valid());
  66  
  67      lmbFs :: rm($this->dir);
  68    }
  69  
  70    function testComplexIterate()
  71    {
  72      $this->_removeFileSystem();
  73      $this->_createFileSystem();
  74  
  75      $it = new lmbFsRecursiveIterator($this->dir);
  76  
  77      $it->rewind();
  78      $this->_assertDotDir($it, $this->dir . '/.', __LINE__);
  79  
  80      $it->next();
  81      $this->_assertDotDir($it, $this->dir . '/..', __LINE__);
  82  
  83      $it->next();
  84      $this->_assertFile($it, $this->dir . '/a', __LINE__);
  85  
  86      $it->next();
  87      $this->_assertDir($it, $this->dir . '/nested', __LINE__);
  88  
  89      $it->next();
  90      $this->_assertDotDir($it, $this->dir . '/nested/.', __LINE__);
  91  
  92      $it->next();
  93      $this->_assertDotDir($it, $this->dir . '/nested/..', __LINE__);
  94  
  95      if(lmbSys :: isWin32())
  96      {
  97        $it->next();
  98        $this->_assertDir($it, $this->dir . '/nested/.sub-nested', __LINE__);
  99  
 100        $it->next();
 101        $this->_assertDotDir($it, $this->dir . '/nested/.sub-nested/.', __LINE__);
 102  
 103        $it->next();
 104        $this->_assertDotDir($it, $this->dir . '/nested/.sub-nested/..', __LINE__);
 105  
 106        $it->next();
 107        $this->_assertFile($it, $this->dir . '/nested/.sub-nested/d', __LINE__);
 108  
 109        $it->next();
 110        $this->_assertDir($it, $this->dir . '/nested/b', __LINE__);
 111  
 112        $it->next();
 113        $this->_assertDotDir($it, $this->dir . '/nested/b/.', __LINE__);
 114  
 115        $it->next();
 116        $this->_assertDotDir($it, $this->dir . '/nested/b/..', __LINE__);
 117  
 118        $it->next();
 119        $this->_assertFile($it, $this->dir . '/nested/c', __LINE__);
 120      }
 121      else
 122      {
 123        $it->next();
 124        $this->_assertDir($it, $this->dir . '/nested/b', __LINE__);
 125  
 126        $it->next();
 127        $this->_assertDotDir($it, $this->dir . '/nested/b/.', __LINE__);
 128  
 129        $it->next();
 130        $this->_assertDotDir($it, $this->dir . '/nested/b/..', __LINE__);
 131  
 132        $it->next();
 133        $this->_assertFile($it, $this->dir . '/nested/c', __LINE__);
 134  
 135        $it->next();
 136        $this->_assertDir($it, $this->dir . '/nested/.sub-nested', __LINE__);
 137  
 138        $it->next();
 139        $this->_assertDotDir($it, $this->dir . '/nested/.sub-nested/.', __LINE__);
 140  
 141        $it->next();
 142        $this->_assertDotDir($it, $this->dir . '/nested/.sub-nested/..', __LINE__);
 143  
 144        $it->next();
 145        $this->_assertFile($it, $this->dir . '/nested/.sub-nested/d', __LINE__);
 146      }
 147  
 148      $it->next();
 149      $this->assertFalse($it->valid());
 150  
 151      $this->_removeFileSystem();
 152    }
 153  
 154    function testLoop()
 155    {
 156      $this->_removeFileSystem();
 157      $this->_createFileSystem();
 158  
 159      $it = new lmbFsRecursiveIterator($this->dir);
 160      $res = array();
 161      for($it->rewind(); $it->valid(); $it->next())
 162      {
 163        $res[] = $it->getPathName();
 164      }
 165  
 166      $res = array_map(array('lmbFs', 'normalizePath'), $res);
 167  
 168      if(lmbSys :: isWin32())
 169      {
 170        $this->assertEqual($res,
 171                           array(lmbFs :: normalizePath($this->dir . '/.'),
 172                                 lmbFs :: normalizePath($this->dir . '/..'),
 173                                 lmbFs :: normalizePath($this->dir . '/a'),
 174                                 lmbFs :: normalizePath($this->dir . '/nested'),
 175                                 lmbFs :: normalizePath($this->dir . '/nested/.'),
 176                                 lmbFs :: normalizePath($this->dir . '/nested/..'),
 177                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested'),
 178                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/.'),
 179                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/..'),
 180                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/d'),
 181                                 lmbFs :: normalizePath($this->dir . '/nested/b'),
 182                                 lmbFs :: normalizePath($this->dir . '/nested/b/.'),
 183                                 lmbFs :: normalizePath($this->dir . '/nested/b/..'),
 184                                 lmbFs :: normalizePath($this->dir . '/nested/c'),
 185                           ));
 186      }
 187      else
 188      {
 189        $this->assertEqual($res,
 190                           array(lmbFs :: normalizePath($this->dir . '/.'),
 191                                 lmbFs :: normalizePath($this->dir . '/..'),
 192                                 lmbFs :: normalizePath($this->dir . '/a'),
 193                                 lmbFs :: normalizePath($this->dir . '/nested'),
 194                                 lmbFs :: normalizePath($this->dir . '/nested/.'),
 195                                 lmbFs :: normalizePath($this->dir . '/nested/..'),
 196                                 lmbFs :: normalizePath($this->dir . '/nested/b'),
 197                                 lmbFs :: normalizePath($this->dir . '/nested/b/.'),
 198                                 lmbFs :: normalizePath($this->dir . '/nested/b/..'),
 199                                 lmbFs :: normalizePath($this->dir . '/nested/c'),
 200                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested'),
 201                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/.'),
 202                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/..'),
 203                                 lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/d'),
 204                           ));
 205      }
 206  
 207      $this->_removeFileSystem();
 208    }
 209  
 210    function _assertDir($it, $path, $line='')
 211    {
 212      $this->assertTrue($it->valid(), '%s ' . $line);
 213      $this->assertFalse($it->isDot(), '%s ' . $line);
 214      $this->assertTrue($it->isDir(), '%s ' . $line);
 215      $this->assertFalse($it->isFile(), '%s ' . $line);
 216      $this->assertEqual(lmbFs :: normalizePath($it->getPathName()),
 217                         lmbFs :: normalizePath($path), '%s ' . $line);
 218    }
 219  
 220    function _assertDotDir($it, $path, $line='')
 221    {
 222      $this->assertTrue($it->valid(), '%s ' . $line);
 223      $this->assertTrue($it->isDot(), '%s ' . $line);
 224      $this->assertTrue($it->isDir(), '%s ' . $line);
 225      $this->assertFalse($it->isFile(), '%s ' . $line);
 226      $this->assertEqual(lmbFs :: normalizePath($it->getPathName()),
 227                         lmbFs :: normalizePath($path), '%s ' . $line);
 228    }
 229  
 230    function _assertFile($it, $path, $line='')
 231    {
 232      $this->assertTrue($it->valid(), '%s ' . $line);
 233      $this->assertFalse($it->isDot(), '%s ' . $line);
 234      $this->assertFalse($it->isDir(), '%s ' . $line);
 235      $this->assertTrue($it->isFile(), '%s ' . $line);
 236      $this->assertEqual(lmbFs :: normalizePath($it->getPathName()),
 237                         lmbFs :: normalizePath($path), '%s ' . $line);
 238    }
 239  }
 240  
 241  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7