/** * testInPath method * * @access public * @return void */ function testInPath() { $path = dirname(dirname(__FILE__)); $inside = dirname($path) . DS; $Folder = new Folder($path); $result = $Folder->pwd(); $this->assertEqual($result, $path); $result = Folder::isSlashTerm($inside); $this->assertTrue($result); $result = $Folder->realpath('tests/'); $this->assertEqual($result, $path . DS . 'tests' . DS); $result = $Folder->inPath('tests' . DS); $this->assertTrue($result); $result = $Folder->inPath(DS . 'non-existing' . $inside); $this->assertFalse($result); }
/** * testInPath method * * @return void */ public function testInPath() { $path = dirname(dirname(__FILE__)); $inside = dirname($path) . DS; $Folder = new Folder($path); $result = $Folder->pwd(); $this->assertEquals($path, $result); $result = Folder::isSlashTerm($inside); $this->assertTrue($result); $result = $Folder->realpath('Test/'); $this->assertEquals($path . DS . 'Test' . DS, $result); $result = $Folder->inPath('Test' . DS); $this->assertTrue($result); $result = $Folder->inPath(DS . 'non-existing' . $inside); $this->assertFalse($result); $result = $Folder->inPath($path . DS . 'Model', true); $this->assertTrue($result); }
/** * Checks if path is within given locations * * @param string $check Absolute path * @param mixed $allow True or * allows any location, * an array containing absolute paths to locations * @return boolean */ function location($check, $allow = false) { $allow = self::_normalize($allow); if ($allow === true) { return true; } elseif ($allow === false) { return false; } if (!is_array($allow)) { $allow = array($allow); } else { $allow = array_unique($allow); } if (Validation::url($check)) { foreach ($allow as $path) { if (preg_match('/^' . preg_quote($path, '/') . '/', $check)) { return true; } } } elseif (MediaValidation::file($check, false)) { $check = dirname($check); if (!Folder::isAbsolute($check)) { return false; } $Check = new Folder($check); foreach ($allow as $path) { if (!Folder::isAbsolute($path) || Validation::url($path)) { continue; } if ($Check->inPath($path)) { return true; } } } return false; }
/** * @dataProvider inPathInvalidPathArgumentDataProvider * @param string $path * @expectedException \InvalidArgumentException * @expectedExceptionMessage The $path argument is expected to be an absolute path. */ public function testInPathInvalidPathArgument($path) { $Folder = new Folder(); $Folder->inPath($path); }