public function test_navigationAndLs()
 {
     $fs = new FileSystem(__DIR__);
     $thisFile = basename(__FILE__);
     $list = $fs->ls();
     $this->assertTrue(isset($thisFile, $list));
     $this->assertTrue(is_array($list[$thisFile]));
     $this->assertEquals($list[$thisFile]['type'], 'file');
     $this->assertTrue(isset($list['files']));
     $this->assertEquals($list['files']['type'], 'dir');
     $this->assertTrue((bool) $fs->cd('files'));
     $this->assertEquals($fs->cwd, '/files');
     $this->assertEquals($fs->realcwd, dirname(__FILE__) . '/files');
     $this->assertTrue($fs->cdup());
     $this->assertEquals($fs->cwd, '/');
     $this->assertEquals(preg_replace('~/$~', '', $fs->realcwd), dirname(__FILE__));
     //this should fail, because it's higher than allowed.
     $this->assertFalse($fs->cdup());
     $this->assertEquals($fs->cwd, '/');
     $this->assertEquals(preg_replace('~/$~', '', $fs->realcwd), dirname(__FILE__));
     $this->assertTrue((bool) $fs->cd('/'));
     $this->assertEquals($fs->cwd, '/');
     $this->assertEquals(preg_replace('~/$~', '', $fs->realcwd), dirname(__FILE__));
     //make sure we can still find just this file.
     $fileInfo = $fs->ls(basename(__FILE__));
     $this->assertTrue(is_array($fileInfo));
     $this->assertEquals(count($fileInfo), 1, "too many files in the array...");
     $this->assertTrue(isset($fileInfo[basename(__FILE__)]));
     $this->assertTrue(isset($fileInfo[basename(__FILE__)]['type']), "malformed array, should ONLY contain info about this file::: " . ToolBox::debug_print($fileInfo, 0));
 }
 public function test_basics()
 {
     $fs = new _fs_testProtectedMethods(__DIR__ . '/files');
     $this->assertEquals('/', $fs->cwd);
     $this->assertEquals(__DIR__ . '/files', $fs->realcwd);
     // just the directory name for CWD (no leading slash)
     $validCwd = new crazedsanity\filesystem\FileSystem(__DIR__);
     $this->assertEquals($validCwd->cd("files"), 1);
     $this->assertEquals(__DIR__ . '/files', $validCwd->realcwd);
     $this->assertEquals('/files', $validCwd->cwd, "invalid cwd... " . ToolBox::debug_print($validCwd, 0));
     $this->assertTrue(is_dir(__DIR__ . '/files'), "required directory does not exist");
     //use a leading slash in CWD
     $validCwd2 = new crazedsanity\filesystem\FileSystem(__DIR__);
     $this->assertEquals($validCwd2->cd('/files'), 1);
     $this->assertEquals(__DIR__ . '/files', $validCwd2->realcwd);
     $this->assertEquals('/files', $validCwd2->cwd);
     $invalidCwd = new FileSystem(__DIR__, '/xDoEsn0tEx15t');
     $this->assertEquals('/', $invalidCwd->cwd);
     $this->assertEquals(__DIR__, $invalidCwd->realcwd);
     $this->assertEquals($invalidCwd->root, $invalidCwd->realcwd);
     $validModes = array('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+');
     $invalidModes = array('b', 'b+', 'd', 'd+', 'e', 'e+');
     $testMe = new FileSystem(__DIR__);
     foreach ($validModes as $x) {
         //				$testMe = new FileSystem(__DIR__, null, $x, "failed to test valid mode (". $x ."), dir=(". __DIR__ .")");
         $testMe->setMode($x);
         $this->assertEquals($x, $testMe->mode);
     }
     foreach ($invalidModes as $x) {
         $testMe->mode = "r+";
         try {
             $this->assertNotEquals($x, $testMe->mode);
         } catch (InvalidArgumentException $e) {
             $this->assertTrue((bool) preg_match('~invalid mode~', $e->getMessage()));
         }
         $this->assertEquals('r+', $testMe->mode);
     }
 }
 /**
  * Pulls a list of files in the current directory, & arranges them by section & 
  * 	name, or vice-versa.
  */
 private function arrange_directory_contents($dir, $primaryIndex = 'section', $secondaryIndex = 'name')
 {
     $fsObj = new FileSystem($this->tmplFs->root);
     if ($fsObj->cd($dir)) {
         $directoryInfo = $fsObj->ls(null, false);
         $arrangedArr = array();
         if (is_array($directoryInfo)) {
             foreach ($directoryInfo as $index => $data) {
                 $myType = $data['type'];
                 if ($myType == 'file' && !in_array($index, $this->ignoredList[$myType])) {
                     $filename = ToolBox::create_list($fsObj->cwd, $index, '/');
                     $filename = preg_replace('/^\\/templates/', '', $filename);
                     $filename = preg_replace('/^\\/\\//', '/', $filename);
                     //call another method to rip the filename apart properly, then arrange things as needed.
                     $pieces = $this->parse_filename($index);
                     $myPriIndex = $pieces[$primaryIndex];
                     $mySecIndex = $pieces[$secondaryIndex];
                     if (strlen($myPriIndex) && strlen($mySecIndex)) {
                         //only load if it's got BOTH parts of the filename.
                         $arrangedArr[$myPriIndex][$mySecIndex] = $filename;
                     }
                 }
             }
         }
     } else {
         $arrangedArr = array();
     }
     return $arrangedArr;
 }