Skip to content

Commit

Permalink
Merge pull request #282 from danrot/version-history
Browse files Browse the repository at this point in the history
Enabling tests and adapting fixtures for version history
  • Loading branch information
dbu committed Jun 11, 2015
2 parents f3f2042 + 1e8ba0b commit 09e50cd
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 62 deletions.
14 changes: 9 additions & 5 deletions tests/ImplementationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +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\\VersionHistoryTest',
'Versioning\\VersionManagerTest',
'Versioning\\VersionTest',
);

$this->unsupportedTests = array(
Expand Down Expand Up @@ -87,6 +82,15 @@ 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',
'Versioning\\VersionManagerTest::testRestoreByPathAndName',
'Versioning\\VersionManagerTest::testRestoreByVersionObject',
'Versioning\\VersionManagerTest::testRestoreRootVersion',
'Versioning\\VersionManagerTest::testWriteNotCheckedOutVersion',
);

if ($connection->getDatabasePlatform() instanceof Doctrine\DBAL\Platforms\SqlitePlatform) {
Expand Down
173 changes: 116 additions & 57 deletions tests/Jackalope/Test/Fixture/DBUnitFixtureXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ 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()
Expand Down Expand Up @@ -132,31 +132,31 @@ public function addRootNode($workspaceName = 'default')
$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' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:crx="http://www.day.com/crx/1.0"'
. 'xmlns:lx="http://flux-cms.org/2.0"'
. 'xmlns:test="http://liip.to/jackalope"'
. 'xmlns:mix="http://www.jcp.org/jcr/mix/1.0"'
. 'xmlns:sling="http://sling.apache.org/jcr/sling/1.0"'
. 'xmlns:nt="http://www.jcp.org/jcr/nt/1.0"'
. 'xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"'
. 'xmlns:fn="http://www.w3.org/2005/xpath-functions"'
. 'xmlns:vlt="http://www.day.com/jcr/vault/1.0"'
. 'xmlns:xs="http://www.w3.org/2001/XMLSchema"'
. 'xmlns:new_prefix="http://a_new_namespace"'
. 'xmlns:jcr="http://www.jcp.org/jcr/1.0"'
. 'xmlns:sv="http://www.jcp.org/jcr/sv/1.0"'
. 'xmlns:rep="internal" />',
'depth' => 0,
'sort_order' => 0,
'id' => $this->ids[$uuid],
'path' => '/',
'parent' => '',
'local_name' => '',
'namespace' => '',
'workspace_name' => $workspaceName,
'identifier' => $uuid,
'type' => 'nt:unstructured',
'props' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:crx="http://www.day.com/crx/1.0"'
. 'xmlns:lx="http://flux-cms.org/2.0"'
. 'xmlns:test="http://liip.to/jackalope"'
. 'xmlns:mix="http://www.jcp.org/jcr/mix/1.0"'
. 'xmlns:sling="http://sling.apache.org/jcr/sling/1.0"'
. 'xmlns:nt="http://www.jcp.org/jcr/nt/1.0"'
. 'xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"'
. 'xmlns:fn="http://www.w3.org/2005/xpath-functions"'
. 'xmlns:vlt="http://www.day.com/jcr/vault/1.0"'
. 'xmlns:xs="http://www.w3.org/2001/XMLSchema"'
. 'xmlns:new_prefix="http://a_new_namespace"'
. 'xmlns:jcr="http://www.jcp.org/jcr/1.0"'
. 'xmlns:sv="http://www.jcp.org/jcr/sv/1.0"'
. 'xmlns:rep="internal" />',
'depth' => 0,
'sort_order' => 0,
));
}

Expand Down Expand Up @@ -189,8 +189,8 @@ public function addNode($workspaceName, \DOMElement $node)

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;
}
Expand All @@ -206,21 +206,21 @@ 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('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,
'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;
Expand Down Expand Up @@ -329,9 +329,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;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ public function createValueNode($value, \DOMDocument $dom, $length)

public function getPath(\DOMElement $node)
{
$childPath = '';
$childPath = '';

$parent = $node;
do {
Expand Down Expand Up @@ -392,11 +392,11 @@ 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,
'node_id' => $id,
'property_name' => $propertyName,
'workspace_name' => $workspaceName,
'idx' => $idx,
'data' => $data,
));

return strlen($data);
Expand Down Expand Up @@ -435,7 +435,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(
Expand All @@ -447,6 +447,7 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $
)
);

// version node in version storage
$versionNodeUuid = UUIDHelper::generateUUID();
$versionParentPath = '/jcr:system/jcr:versionStorage';
$versionPath = $versionParentPath . '/' . $versionNodeUuid;
Expand All @@ -462,12 +463,39 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $
'identifier' => $versionNodeUuid,
'type' => 'nt:unstructured',
'props' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0"/>',
. '<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0">'
. '<sv:property sv:name="jcr:uuid" sv:type="String" sv:multi-valued="0">'
. '<sv:value length="36">' . $versionNodeUuid . '</sv:value>'
. '</sv:property>'
. '<sv:property sv:name="jcr:versionableUuid" sv:type="String" sv:multi-valued="0">'
. '<sv:value length="36">' . $uuid . '</sv:value>'
. '</sv:property>'
. '</sv:node>',
'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(
Expand All @@ -482,7 +510,13 @@ private function addVersioningProperties(\DOMDocument $dom, \DOMElement $node, $
'identifier' => $rootVersionUuid,
'type' => 'nt:version',
'props' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0"/>',
. '<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0">'
. '<sv:property sv:name="jcr:uuid" sv:type="String" sv:multi-valued="0">'
. '<sv:value length="36">' . $rootVersionUuid . '</sv:value>'
. '</sv:property>'
. '<sv:property sv:name="jcr:predecessors" sv:type="String" sv:multi-valued="1"/>'
. '<sv:property sv:name="jcr:successors" sv:type="String" sv:multi-valued="1"/>'
. '</sv:node>',
'depth' => PathHelper::getPathDepth($rootVersionPath),
'sort_order' => $id - 2,
)
Expand All @@ -491,8 +525,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
)
Expand All @@ -507,5 +541,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' => '<?xml version="1.0" encoding="UTF-8"?>'
. '<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0">'
. '<sv:property sv:name="jcr:uuid" sv:type="String" sv:multi-valued="0">'
. '<sv:value length="36">' . $rootVersionFrozenNodeUuid . '</sv:value>'
. '</sv:property>'
. '</sv:node>',
'depth' => PathHelper::getPathDepth($rootVersionFrozenNodePath),
'sort_order' => $id - 2,
)
);
}
}

0 comments on commit 09e50cd

Please sign in to comment.