* @license PHP License * @package WB * @subpackage unittest */ WBClass::load( 'WBException_Datasource' ); /** * Unit Test * * Test table * * @version 0.3.0 * @package WB * @subpackage unittest */ class TestCaseVFSFolder extends UnitTestCase { /** * table options * @var WBVFS_Explorer */ protected $explorer; /** * constructor * * - start objects * - source SQL * */ public function __construct() { WBClass::load('WBUnitTest_SQLUte'); $param = array( 'user' => 42 ); WBUnitTest_SQLUte::source(__FILE__, 'construct'); $this->explorer = WBClass::create('WBVFS_Explorer', $param); } /** * destruct * * Remove testing tables */ public function __destruct() { WBUnitTest_SQLUte::source( __FILE__, 'destruct' ); } /** * check instance * */ public function testInit() { $this->assertTrue(class_exists( 'WBVFS_Explorer', false)); $this->assertIsA($this->explorer, 'WBVFS_Explorer'); } public function testMkdir() { $primary = $this->explorer->getDirIdentifier(); $first = $this->explorer->mkDir(null, 'first'); $node = $this->explorer->getDir($first); $this->assertEqual($node[$primary], $first); $second = $this->explorer->mkDir(null, 'second'); $node = $this->explorer->getDir($second); $this->assertEqual($node[$primary], $second); $third = $this->explorer->mkDir(null, 'same'); $node = $this->explorer->getDir($third); $this->assertEqual($node[$primary], $third); $this->assertEqual('same', $node['name']); $fourth = $this->explorer->mkDir(null, 'same'); $node = $this->explorer->getDir($fourth); $this->assertEqual($node[$primary], $fourth); $this->assertEqual('same (2)', $node['name']); $fifth = $this->explorer->mkDir(null, 'same'); $node = $this->explorer->getDir($fifth); $this->assertEqual($node[$primary], $fifth); $this->assertEqual('same (3)', $node['name']); $sixth = $this->explorer->mkDir(null, 'same'); $node = $this->explorer->getDir($sixth); $this->assertEqual($node[$primary], $sixth); $this->assertEqual('same (4)', $node['name']); } public function testRenameDir() { $primary = $this->explorer->getDirIdentifier(); $inRoot = $this->explorer->mkDir(null, 'inRoot'); $node = $this->explorer->getDir($inRoot); $this->assertEqual($node[$primary], $inRoot); $child = $this->explorer->mkDir($inRoot, 'child'); $node = $this->explorer->getDir($child); $this->assertEqual($node[$primary], $child); $this->assertEqual('child', $node['name']); $this->explorer->renameDir($child, 'other'); $node = $this->explorer->getDir($child); $this->assertEqual('other', $node['name']); $this->explorer->renameDir($child, 'rename'); $node = $this->explorer->getDir($child); $this->assertEqual('rename', $node['name']); $this->explorer->renameDir($child, 'rename'); $node = $this->explorer->getDir($child); $this->assertEqual('rename', $node['name']); } public function testMoveDir() { $primary = $this->explorer->getDirIdentifier(); $inRoot = $this->explorer->mkDir(null, 'inRoot'); $node = $this->explorer->getDir($inRoot); $this->assertEqual($node[$primary], $inRoot); $first = $this->explorer->mkDir($inRoot, 'first'); $node = $this->explorer->getDir($first); $this->assertEqual($node[$primary], $first); $second = $this->explorer->mkDir($inRoot, 'first'); $node = $this->explorer->getDir($second); $this->assertEqual($node[$primary], $second); $x = $this->explorer->mkDir($first, 'move me'); $node = $this->explorer->getDir($x); $this->assertEqual($node[$primary], $x); $parent = $this->explorer->getParentDir($x); $this->assertEqual($parent[$primary], $first); $this->explorer->mvDir($x, $second); $parent = $this->explorer->getParentDir($x); $this->assertEqual($parent[$primary], $second); } public function testRemoveDir() { $primary = $this->explorer->getDirIdentifier(); $inRoot = $this->explorer->mkDir(null, 'inRoot'); $node = $this->explorer->getDir($inRoot); $this->assertEqual($node[$primary], $inRoot); $first = $this->explorer->mkDir($inRoot, 'first'); $node = $this->explorer->getDir($first); $this->assertEqual($node[$primary], $first); $second = $this->explorer->mkDir($first, 'first'); $node = $this->explorer->getDir($second); $this->assertEqual($node[$primary], $second); $this->explorer->rmDir($first); } public function testFindPath() { $root = $this->explorer->findPath('/'); $this->assertNull($root); $root = $this->explorer->findPath(array()); $this->assertNull($root); $inRoot = $this->explorer->mkDir(null, 'rootfolder'); $find = $this->explorer->findPath('rootfolder'); $this->assertEqual($inRoot, $find); $foo = $this->explorer->mkDir($inRoot, 'foo'); $foo2 = $this->explorer->mkDir($inRoot, 'foo2'); $foo3 = $this->explorer->mkDir($inRoot, 'foo3'); $find = $this->explorer->findPath('rootfolder/foo'); $this->assertEqual($foo, $find); $bar = $this->explorer->mkDir($foo, 'bar'); $bar2 = $this->explorer->mkDir($foo, 'bar2'); $bar3 = $this->explorer->mkDir($foo, 'bar3'); $find = $this->explorer->findPath('rootfolder/foo/bar'); $this->assertEqual($bar, $find); $foo = $this->explorer->mkDir($bar, 'foo'); $foo2 = $this->explorer->mkDir($bar, 'foo2'); $foo3 = $this->explorer->mkDir($bar, 'foo3'); $find = $this->explorer->findPath('rootfolder/foo/bar/foo'); $this->assertEqual($foo, $find); $bar = $this->explorer->mkDir($foo, 'bar'); $bar2 = $this->explorer->mkDir($foo, 'bar2'); $bar3 = $this->explorer->mkDir($foo, 'bar3'); $find = $this->explorer->findPath('rootfolder/foo/bar/foo/bar'); $this->assertEqual($bar, $find); $this->explorer->rmDir($inRoot); } public function testGetPath() { $inRoot = $this->explorer->mkDir(null, 'rootfolder'); $find = $this->explorer->findPath('rootfolder'); $this->assertEqual($inRoot, $find); $foo = $this->explorer->mkDir($inRoot, 'foo'); $foo2 = $this->explorer->mkDir($inRoot, 'foo2'); $foo3 = $this->explorer->mkDir($inRoot, 'foo3'); $path = $this->explorer->getPath($foo); $this->assertTrue(is_array($path)); $this->assertEqual(count($path), 2); $this->assertEqual($path[0], 'rootfolder'); $this->assertEqual($path[1], 'foo'); $bar = $this->explorer->mkDir($foo, 'bar'); $bar2 = $this->explorer->mkDir($foo, 'bar2'); $bar3 = $this->explorer->mkDir($foo, 'bar3'); $path = $this->explorer->getPath($bar); $this->assertTrue(is_array($path)); $this->assertEqual(count($path), 3); $this->assertEqual($path[0], 'rootfolder'); $this->assertEqual($path[1], 'foo'); $this->assertEqual($path[2], 'bar'); $path = $this->explorer->getPath($bar, true); $this->assertTrue(!is_array($path)); $path = explode('/', $path); $this->assertEqual(count($path), 3); $this->assertEqual($path[0], 'rootfolder'); $this->assertEqual($path[1], 'foo'); $this->assertEqual($path[2], 'bar'); } } ?>