From 8e07d4aec12831e762d36fedde9a3bd4911a3535 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 19 May 2015 14:18:55 +0200 Subject: [PATCH 1/6] enabled version history tests --- tests/ImplementationLoader.php | 1 - .../Test/Fixture/DBUnitFixtureXML.php | 260 ++++++++++++------ 2 files changed, 175 insertions(+), 86 deletions(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 63ea69f5..604c2530 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -55,7 +55,6 @@ protected function __construct(Connection $connection, $fixturePath) 'Writing\\CloneMethodsTest', // TODO: Support for workspace->clone, node->update, node->getCorrespondingNodePath // TODO fully implement versioning - 'Versioning\\VersionHistoryTest', 'Versioning\\VersionManagerTest', 'Versioning\\VersionTest', ); diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index 671fdfb3..9938015f 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -47,17 +47,17 @@ class DBUnitFixtureXML extends XMLDocument private $rootNodes; /** - * @param string $file - file path - * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php + * @param string $file - file path + * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php */ public function __construct($file, $options = null) { parent::__construct($file, $options); - $this->tables = array(); - $this->ids = array(); - $this->references = array(); - $this->expectedNodes = array(); + $this->tables = array(); + $this->ids = array(); + $this->references = array(); + $this->expectedNodes = array(); } public function addDataset() @@ -65,13 +65,16 @@ public function addDataset() $this->appendChild($this->createElement('dataset')); // purge binary in case no binary properties are in fixture - $this->ensureTableExists('phpcr_binarydata', array( - 'node_id', - 'property_name', - 'workspace_name', - 'idx', - 'data', - )); + $this->ensureTableExists( + 'phpcr_binarydata', + array( + 'node_id', + 'property_name', + 'workspace_name', + 'idx', + 'data', + ) + ); return $this; } @@ -99,7 +102,7 @@ public function addNamespaces(array $namespaces) * * If the root node is not called jcr:root, autogenerate a root node. * - * @param string $workspaceName + * @param string $workspaceName * @param \DOMNodeList $nodes * * @return DBUnitFixtureXML @@ -114,7 +117,9 @@ public function addNodes($workspaceName, \DOMNodeList $nodes) $this->rootNodes[$workspaceName] = true; } - $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml'); + $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML( + __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml' + ); foreach ($srcDom->load()->getNodes() as $node) { $this->addNode($workspaceName, $node); } @@ -131,40 +136,43 @@ public function addRootNode($workspaceName = 'default') $uuid = UUIDHelper::generateUUID(); $this->ids[$uuid] = self::$idCounter++; - return $this->addRow('phpcr_nodes', array( - 'id' => $this->ids[$uuid], - 'path' => '/', - 'parent' => '', - 'local_name' => '', - 'namespace' => '', - 'workspace_name'=> $workspaceName, - 'identifier' => $uuid, - 'type' => 'nt:unstructured', - 'props' => '' - . '', - 'depth' => 0, - 'sort_order' => 0, - )); + return $this->addRow( + 'phpcr_nodes', + array( + 'id' => $this->ids[$uuid], + 'path' => '/', + 'parent' => '', + 'local_name' => '', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => 'nt:unstructured', + 'props' => '' + . '', + 'depth' => 0, + 'sort_order' => 0, + ) + ); } public function addNode($workspaceName, \DOMElement $node) { $properties = $this->getAttributes($node); $uuid = isset($properties['jcr:uuid']['value'][0]) - ? (string) $properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); + ? (string)$properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); $this->ids[$uuid] = $id = isset($this->expectedNodes[$uuid]) ? $this->expectedNodes[$uuid] : self::$idCounter++; @@ -184,23 +192,25 @@ public function addNode($workspaceName, \DOMElement $node) throw new \InvalidArgumentException('"' . $propertyData['type'] . '" is not a valid JCR type.'); } - $phpcrNode->appendChild($this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode)); + $phpcrNode->appendChild( + $this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode) + ); } list ($parentPath, $childPath) = $this->getPath($node); - $namespace = ''; - $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); + $namespace = ''; + $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); if (count($parts = explode(':', $name, 2)) == 2) { list($namespace, $name) = $parts; } if ($namespace == 'jcr' && $name == 'root') { - $id = 1; - $childPath = '/'; + $id = 1; + $childPath = '/'; $parentPath = ''; - $name = ''; - $namespace = ''; + $name = ''; + $namespace = ''; } if (isset($properties['jcr:mixinTypes']) @@ -209,19 +219,22 @@ public function addNode($workspaceName, \DOMElement $node) $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id); } - $this->addRow('phpcr_nodes', array( - 'id' => $id, - 'path' => $childPath, - 'parent' => $parentPath, - 'local_name' => $name, - 'namespace' => $namespace, - 'workspace_name'=> $workspaceName, - 'identifier' => $uuid, - 'type' => $properties['jcr:primaryType']['value'][0], - 'props' => $dom->saveXML(), - 'depth' => PathHelper::getPathDepth($childPath), - 'sort_order' => $id - 2, - )); + $this->addRow( + 'phpcr_nodes', + array( + 'id' => $id, + 'path' => $childPath, + 'parent' => $parentPath, + 'local_name' => $name, + 'namespace' => $namespace, + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => $properties['jcr:primaryType']['value'][0], + 'props' => $dom->saveXML(), + 'depth' => PathHelper::getPathDepth($childPath), + 'sort_order' => $id - 2, + ) + ); return $this; } @@ -229,7 +242,7 @@ public function addNode($workspaceName, \DOMElement $node) public function addReferences() { foreach ($this->references as $type => $references) { - $table = 'phpcr_nodes_'.$type.'s'; + $table = 'phpcr_nodes_' . $type . 's'; // make sure we have the references even if there is not a single entry in it to have it truncated $this->ensureTableExists($table, array('source_id', 'source_property_name', 'target_id')); @@ -277,7 +290,10 @@ public function getChildAttribute(\DOMElement $node) $isMultiValue = false; if ($name == 'jcr:mixinTypes' || count($values) > 1 - || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS($this->namespaces['sv'], 'multiple') == 'true') + || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS( + $this->namespaces['sv'], + 'multiple' + ) == 'true') ) { $isMultiValue = true; } @@ -294,14 +310,31 @@ public function createPropertyNode($workspaceName, $propertyName, $propertyData, $binaryDataIdx = 0; foreach ($propertyData['value'] as $value) { - $propertyNode->appendChild($this->createValueNodeByType($workspaceName, $propertyData['type'], $value, $id, $propertyName, $binaryDataIdx++, $dom)); + $propertyNode->appendChild( + $this->createValueNodeByType( + $workspaceName, + $propertyData['type'], + $value, + $id, + $propertyName, + $binaryDataIdx++, + $dom + ) + ); } return $propertyNode; } - public function createValueNodeByType($workspaceName, $type, $value, $id, $propertyName, $binaryDataIdx, \DOMDocument $dom) - { + public function createValueNodeByType( + $workspaceName, + $type, + $value, + $id, + $propertyName, + $binaryDataIdx, + \DOMDocument $dom + ) { $length = is_scalar($value) ? strlen($value) : null; switch ($type) { case 'binary': @@ -329,9 +362,9 @@ public function createValueNodeByType($workspaceName, $type, $value, $id, $prope } // do not repeat references $this->references[$type][$value][$id . $propertyName . $targetId] = array( - 'source_id' => $id, - 'source_property_name' => $propertyName, - 'target_id' => $targetId, + 'source_id' => $id, + 'source_property_name' => $propertyName, + 'target_id' => $targetId, ); break; } @@ -360,7 +393,7 @@ public function createValueNode($value, \DOMDocument $dom, $length) public function getPath(\DOMElement $node) { - $childPath = ''; + $childPath = ''; $parent = $node; do { @@ -379,10 +412,10 @@ public function getPath(\DOMElement $node) } /** - * @param int $id + * @param int $id * @param string $propertyName * @param string $workspaceName - * @param int $idx + * @param int $idx * @param string $data * * @return int - length of base64 decoded string @@ -391,13 +424,16 @@ public function addBinaryNode($id, $propertyName, $workspaceName, $idx, $data) { $data = base64_decode($data); - $this->addRow('phpcr_binarydata', array( - 'node_id' => $id, - 'property_name' => $propertyName, - 'workspace_name' => $workspaceName, - 'idx' => $idx, - 'data' => $data, - )); + $this->addRow( + 'phpcr_binarydata', + array( + 'node_id' => $id, + 'property_name' => $propertyName, + 'workspace_name' => $workspaceName, + 'idx' => $idx, + 'data' => $data, + ) + ); return strlen($data); } @@ -447,6 +483,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ ) ); + // version node in version storage $versionNodeUuid = UUIDHelper::generateUUID(); $versionParentPath = '/jcr:system/jcr:versionStorage'; $versionPath = $versionParentPath . '/' . $versionNodeUuid; @@ -462,12 +499,36 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ 'identifier' => $versionNodeUuid, 'type' => 'nt:unstructured', 'props' => '' - . '', + . '' + . '' + . '' . $versionNodeUuid . '' + . '' + . '', 'depth' => PathHelper::getPathDepth($versionPath), 'sort_order' => $id - 2, ) ); + $this->addRow( + 'phpcr_nodes_references', + array( + 'source_id' => $id, + 'source_property_name' => 'jcr:versionHistory', + 'target_id' => self::$idCounter - 1 + ) + ); + + $node->appendChild( + $this->createPropertyNode( + $workspaceName, + 'jcr:versionHistory', + array('type' => 'reference', 'value' => array($versionNodeUuid), 'multiValued' => false), + $id, + $dom + ) + ); + + // root version $rootVersionPath = $versionPath . '/jcr:rootVersion'; $rootVersionUuid = UUIDHelper::generateUUID(); $this->addRow( @@ -482,7 +543,11 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ 'identifier' => $rootVersionUuid, 'type' => 'nt:version', 'props' => '' - . '', + . '' + . '' + . '' . $rootVersionUuid . '' + . '' + . '', 'depth' => PathHelper::getPathDepth($rootVersionPath), 'sort_order' => $id - 2, ) @@ -491,8 +556,8 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ $node->appendChild( $this->createPropertyNode( $workspaceName, - 'jcr:versionHistory', - array('type' => 'reference', 'value' => array($versionNodeUuid), 'multiValued' => false), + 'jcr:baseVersion', + array('type' => 'reference', 'value' => array($rootVersionUuid), 'multiValued' => false), $id, $dom ) @@ -507,5 +572,30 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ $dom ) ); + + // frozen node for root version + $rootVersionFrozenNodePath = $rootVersionPath . '/jcr:frozenNode'; + $rootVersionFrozenNodeUuid = UUIDHelper::generateUUID(); + $this->addRow( + 'phpcr_nodes', + array( + 'id' => self::$idCounter++, + 'path' => $rootVersionFrozenNodePath, + 'parent' => $rootVersionPath, + 'local_name' => 'jcr:rootVersion', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $rootVersionFrozenNodeUuid, + 'type' => 'nt:version', + 'props' => '' + . '' + . '' + . '' . $rootVersionFrozenNodeUuid . '' + . '' + . '', + 'depth' => PathHelper::getPathDepth($rootVersionFrozenNodePath), + 'sort_order' => $id - 2, + ) + ); } } From 639a45d9dd50cfe7a5e264673eda1ecb0c7b7369 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Tue, 19 May 2015 15:21:15 +0200 Subject: [PATCH 2/6] added required versioning properties to test fixtures --- composer.json | 2 +- tests/ImplementationLoader.php | 5 +++++ tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 0af86216..0281eb8d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "doctrine/dbal": ">=2.4.5,<3.0.x-dev", "phpcr/phpcr": "~2.1.2", "phpcr/phpcr-utils": "~1.2,>=1.2.6", - "jackalope/jackalope": "dev-versioning as 1.3.0" + "jackalope/jackalope": "dev-version-history as 1.3.0" }, "provide": { "jackalope/jackalope-transport": "1.1.0" diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 604c2530..c89fa767 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -86,6 +86,11 @@ protected function __construct(Connection $connection, $fixturePath) // TODO: implement creating workspace with source 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithSource', 'WorkspaceManagement\\WorkspaceManagementTest::testCreateWorkspaceWithInvalidSource', + + // TODO: implement remove version + 'Versioning\\VersionHistoryTest::testDeleteVersion', + 'Versioning\\VersionHistoryTest::testDeleteLatestVersion', + 'Versioning\\VersionHistoryTest::testDeleteUnexistingVersion', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index 9938015f..84d413c5 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -216,7 +216,7 @@ public function addNode($workspaceName, \DOMElement $node) if (isset($properties['jcr:mixinTypes']) && in_array('mix:versionable', $properties['jcr:mixinTypes']['value']) ) { - $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id); + $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id, $uuid); } $this->addRow( @@ -471,7 +471,7 @@ protected function ensureTableExists($tableName, $columns) return $this; } - private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $workspaceName, $id) + private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $workspaceName, $id, $uuid) { $node->appendChild( $this->createPropertyNode( @@ -503,6 +503,9 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ . '' . '' . $versionNodeUuid . '' . '' + . '' + . '' . $uuid . '' + . '' . '', 'depth' => PathHelper::getPathDepth($versionPath), 'sort_order' => $id - 2, @@ -547,6 +550,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ . '' . '' . $rootVersionUuid . '' . '' + . '' . '', 'depth' => PathHelper::getPathDepth($rootVersionPath), 'sort_order' => $id - 2, From 2daa8106a64badbaad099322eaf989b9b510630b Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Sat, 30 May 2015 13:16:33 +0200 Subject: [PATCH 3/6] enabled VerstionTests --- tests/ImplementationLoader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index c89fa767..612d4803 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -56,7 +56,6 @@ protected function __construct(Connection $connection, $fixturePath) // TODO fully implement versioning 'Versioning\\VersionManagerTest', - 'Versioning\\VersionTest', ); $this->unsupportedTests = array( From e00cb379132a4ef530bff53125791d4e89a2df4f Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Fri, 5 Jun 2015 17:52:22 +0200 Subject: [PATCH 4/6] added new tests and adapted fixtures --- tests/ImplementationLoader.php | 6 +++--- tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index 612d4803..de004b28 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -53,9 +53,6 @@ protected function __construct(Connection $connection, $fixturePath) 'Query\\XPath', // Query language 'xpath' not implemented. 'Query\\Sql1', // Query language 'sql' is legacy and only makes sense with jackrabbit 'Writing\\CloneMethodsTest', // TODO: Support for workspace->clone, node->update, node->getCorrespondingNodePath - - // TODO fully implement versioning - 'Versioning\\VersionManagerTest', ); $this->unsupportedTests = array( @@ -90,6 +87,9 @@ protected function __construct(Connection $connection, $fixturePath) 'Versioning\\VersionHistoryTest::testDeleteVersion', 'Versioning\\VersionHistoryTest::testDeleteLatestVersion', 'Versioning\\VersionHistoryTest::testDeleteUnexistingVersion', + 'Versioning\\VersionManagerTest::testRestoreByPathAndName', + 'Versioning\\VersionManagerTest::testRestoreByVersionObject', + 'Versioning\\VersionManagerTest::testRestoreRootVersion', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index 84d413c5..201accd3 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -551,6 +551,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $ . '' . $rootVersionUuid . '' . '' . '' + . '' . '', 'depth' => PathHelper::getPathDepth($rootVersionPath), 'sort_order' => $id - 2, From 8106bb2ca970bf1f664ed17763811177d55ce970 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Wed, 10 Jun 2015 21:13:58 +0200 Subject: [PATCH 5/6] removed the test for write protection --- composer.json | 8 +++++++- tests/ImplementationLoader.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0281eb8d..376e6408 100644 --- a/composer.json +++ b/composer.json @@ -39,5 +39,11 @@ "branch-alias": { "dev-master": "1.2-dev" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/danrot/jackalope.git" + } + ] } diff --git a/tests/ImplementationLoader.php b/tests/ImplementationLoader.php index de004b28..9da991c8 100644 --- a/tests/ImplementationLoader.php +++ b/tests/ImplementationLoader.php @@ -90,6 +90,7 @@ protected function __construct(Connection $connection, $fixturePath) 'Versioning\\VersionManagerTest::testRestoreByPathAndName', 'Versioning\\VersionManagerTest::testRestoreByVersionObject', 'Versioning\\VersionManagerTest::testRestoreRootVersion', + 'Versioning\\VersionManagerTest::testWriteNotCheckedOutVersion', ); if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) { From 1e8ba0be1df0224b57f2485064d141b41c369b3d Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Thu, 11 Jun 2015 11:55:39 +0200 Subject: [PATCH 6/6] cleaned code --- composer.json | 10 +- .../Test/Fixture/DBUnitFixtureXML.php | 190 +++++++----------- 2 files changed, 79 insertions(+), 121 deletions(-) diff --git a/composer.json b/composer.json index 376e6408..0af86216 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "doctrine/dbal": ">=2.4.5,<3.0.x-dev", "phpcr/phpcr": "~2.1.2", "phpcr/phpcr-utils": "~1.2,>=1.2.6", - "jackalope/jackalope": "dev-version-history as 1.3.0" + "jackalope/jackalope": "dev-versioning as 1.3.0" }, "provide": { "jackalope/jackalope-transport": "1.1.0" @@ -39,11 +39,5 @@ "branch-alias": { "dev-master": "1.2-dev" } - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/danrot/jackalope.git" - } - ] + } } diff --git a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php index 201accd3..c8330d9b 100644 --- a/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php +++ b/tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php @@ -47,16 +47,16 @@ class DBUnitFixtureXML extends XMLDocument private $rootNodes; /** - * @param string $file - file path - * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php + * @param string $file - file path + * @param int $options - libxml option constants: http://www.php.net/manual/en/libxml.constants.php */ public function __construct($file, $options = null) { parent::__construct($file, $options); - $this->tables = array(); - $this->ids = array(); - $this->references = array(); + $this->tables = array(); + $this->ids = array(); + $this->references = array(); $this->expectedNodes = array(); } @@ -65,16 +65,13 @@ public function addDataset() $this->appendChild($this->createElement('dataset')); // purge binary in case no binary properties are in fixture - $this->ensureTableExists( - 'phpcr_binarydata', - array( - 'node_id', - 'property_name', - 'workspace_name', - 'idx', - 'data', - ) - ); + $this->ensureTableExists('phpcr_binarydata', array( + 'node_id', + 'property_name', + 'workspace_name', + 'idx', + 'data', + )); return $this; } @@ -102,7 +99,7 @@ public function addNamespaces(array $namespaces) * * If the root node is not called jcr:root, autogenerate a root node. * - * @param string $workspaceName + * @param string $workspaceName * @param \DOMNodeList $nodes * * @return DBUnitFixtureXML @@ -117,9 +114,7 @@ public function addNodes($workspaceName, \DOMNodeList $nodes) $this->rootNodes[$workspaceName] = true; } - $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML( - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml' - ); + $srcDom = new \Jackalope\Test\Fixture\JCRSystemXML(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'system.xml'); foreach ($srcDom->load()->getNodes() as $node) { $this->addNode($workspaceName, $node); } @@ -136,43 +131,40 @@ public function addRootNode($workspaceName = 'default') $uuid = UUIDHelper::generateUUID(); $this->ids[$uuid] = self::$idCounter++; - return $this->addRow( - 'phpcr_nodes', - array( - 'id' => $this->ids[$uuid], - 'path' => '/', - 'parent' => '', - 'local_name' => '', - 'namespace' => '', - 'workspace_name' => $workspaceName, - 'identifier' => $uuid, - 'type' => 'nt:unstructured', - 'props' => '' - . '', - 'depth' => 0, - 'sort_order' => 0, - ) - ); + return $this->addRow('phpcr_nodes', array( + 'id' => $this->ids[$uuid], + 'path' => '/', + 'parent' => '', + 'local_name' => '', + 'namespace' => '', + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => 'nt:unstructured', + 'props' => '' + . '', + 'depth' => 0, + 'sort_order' => 0, + )); } public function addNode($workspaceName, \DOMElement $node) { $properties = $this->getAttributes($node); $uuid = isset($properties['jcr:uuid']['value'][0]) - ? (string)$properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); + ? (string) $properties['jcr:uuid']['value'][0] : UUIDHelper::generateUUID(); $this->ids[$uuid] = $id = isset($this->expectedNodes[$uuid]) ? $this->expectedNodes[$uuid] : self::$idCounter++; @@ -192,25 +184,23 @@ public function addNode($workspaceName, \DOMElement $node) throw new \InvalidArgumentException('"' . $propertyData['type'] . '" is not a valid JCR type.'); } - $phpcrNode->appendChild( - $this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode) - ); + $phpcrNode->appendChild($this->createPropertyNode($workspaceName, $propertyName, $propertyData, $id, $dom, $phpcrNode)); } list ($parentPath, $childPath) = $this->getPath($node); $namespace = ''; - $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); + $name = $node->getAttributeNS($this->namespaces['sv'], 'name'); if (count($parts = explode(':', $name, 2)) == 2) { list($namespace, $name) = $parts; } if ($namespace == 'jcr' && $name == 'root') { - $id = 1; - $childPath = '/'; + $id = 1; + $childPath = '/'; $parentPath = ''; - $name = ''; - $namespace = ''; + $name = ''; + $namespace = ''; } if (isset($properties['jcr:mixinTypes']) @@ -219,22 +209,19 @@ public function addNode($workspaceName, \DOMElement $node) $this->addVersioningProperties($dom, $phpcrNode, $workspaceName, $id, $uuid); } - $this->addRow( - 'phpcr_nodes', - array( - 'id' => $id, - 'path' => $childPath, - 'parent' => $parentPath, - 'local_name' => $name, - 'namespace' => $namespace, - 'workspace_name' => $workspaceName, - 'identifier' => $uuid, - 'type' => $properties['jcr:primaryType']['value'][0], - 'props' => $dom->saveXML(), - 'depth' => PathHelper::getPathDepth($childPath), - 'sort_order' => $id - 2, - ) - ); + $this->addRow('phpcr_nodes', array( + 'id' => $id, + 'path' => $childPath, + 'parent' => $parentPath, + 'local_name' => $name, + 'namespace' => $namespace, + 'workspace_name' => $workspaceName, + 'identifier' => $uuid, + 'type' => $properties['jcr:primaryType']['value'][0], + 'props' => $dom->saveXML(), + 'depth' => PathHelper::getPathDepth($childPath), + 'sort_order' => $id - 2, + )); return $this; } @@ -242,7 +229,7 @@ public function addNode($workspaceName, \DOMElement $node) public function addReferences() { foreach ($this->references as $type => $references) { - $table = 'phpcr_nodes_' . $type . 's'; + $table = 'phpcr_nodes_'.$type.'s'; // make sure we have the references even if there is not a single entry in it to have it truncated $this->ensureTableExists($table, array('source_id', 'source_property_name', 'target_id')); @@ -290,10 +277,7 @@ public function getChildAttribute(\DOMElement $node) $isMultiValue = false; if ($name == 'jcr:mixinTypes' || count($values) > 1 - || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS( - $this->namespaces['sv'], - 'multiple' - ) == 'true') + || ($node->hasAttributeNS($this->namespaces['sv'], 'multiple') && $node->getAttributeNS($this->namespaces['sv'], 'multiple') == 'true') ) { $isMultiValue = true; } @@ -310,31 +294,14 @@ public function createPropertyNode($workspaceName, $propertyName, $propertyData, $binaryDataIdx = 0; foreach ($propertyData['value'] as $value) { - $propertyNode->appendChild( - $this->createValueNodeByType( - $workspaceName, - $propertyData['type'], - $value, - $id, - $propertyName, - $binaryDataIdx++, - $dom - ) - ); + $propertyNode->appendChild($this->createValueNodeByType($workspaceName, $propertyData['type'], $value, $id, $propertyName, $binaryDataIdx++, $dom)); } return $propertyNode; } - public function createValueNodeByType( - $workspaceName, - $type, - $value, - $id, - $propertyName, - $binaryDataIdx, - \DOMDocument $dom - ) { + public function createValueNodeByType($workspaceName, $type, $value, $id, $propertyName, $binaryDataIdx, \DOMDocument $dom) + { $length = is_scalar($value) ? strlen($value) : null; switch ($type) { case 'binary': @@ -362,9 +329,9 @@ public function createValueNodeByType( } // do not repeat references $this->references[$type][$value][$id . $propertyName . $targetId] = array( - 'source_id' => $id, + 'source_id' => $id, 'source_property_name' => $propertyName, - 'target_id' => $targetId, + 'target_id' => $targetId, ); break; } @@ -412,10 +379,10 @@ public function getPath(\DOMElement $node) } /** - * @param int $id + * @param int $id * @param string $propertyName * @param string $workspaceName - * @param int $idx + * @param int $idx * @param string $data * * @return int - length of base64 decoded string @@ -424,16 +391,13 @@ public function addBinaryNode($id, $propertyName, $workspaceName, $idx, $data) { $data = base64_decode($data); - $this->addRow( - 'phpcr_binarydata', - array( - 'node_id' => $id, - 'property_name' => $propertyName, - 'workspace_name' => $workspaceName, - 'idx' => $idx, - 'data' => $data, - ) - ); + $this->addRow('phpcr_binarydata', array( + 'node_id' => $id, + 'property_name' => $propertyName, + 'workspace_name' => $workspaceName, + 'idx' => $idx, + 'data' => $data, + )); return strlen($data); }