Skip to content

Commit

Permalink
Added clone test cases for existing, non-corresponding nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Janssen committed Apr 12, 2013
1 parent 5edee44 commit a76c97c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
27 changes: 27 additions & 0 deletions fixtures/10_Writing/clone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@
</sv:property>
</sv:node>
</sv:node>
<sv:node sv:name="testWorkspaceCloneNonCorresponding">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:node sv:name="sourceRemoveExisting">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>b33fbe21-d3d8-4f52-8188-ad18a62dea9b</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="sourceNoRemoveExisting">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>1ef2d543-a889-48a3-ae46-a97cf4767e95</sv:value>
</sv:property>
</sv:node>
</sv:node>
<sv:node sv:name="testWorkspaceCorrespondingNode">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
Expand Down
31 changes: 29 additions & 2 deletions fixtures/general/additionalWorkspace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,35 @@
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:rep="internal"

sv:name="tests_general_additional_workspace">
sv:name="tests_additional_workspace">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:node sv:name="testWorkspaceCloneNonCorresponding">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:node sv:name="destRemoveExisting">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>f8019868-3533-4519-a077-9c8601950627</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="destNoRemoveExisting">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>9aee563c-b5b7-44f7-a16d-f94116f4dfba</sv:value>
</sv:property>
</sv:node>
</sv:node>
</sv:node>
42 changes: 40 additions & 2 deletions tests/10_Writing/CloneMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function testCloneReferenceableWithChild()
}

/**
* Clone a referenceable node, then clone again with 'remove existing' feature.
* Clone a referenceable node, then clone again with removeExisting = true
* This should overwrite the existing, corresponding node (same UUID)
*/
public function testCloneReferenceableRemoveExisting()
{
Expand Down Expand Up @@ -127,6 +128,9 @@ public function testCloneReferenceableRemoveExisting()
}

/**
* Clone a referenceable node, then clone again with removeExisting = false
* This should cause an exception, even with a corresponding node (same UUID)
*
* @expectedException \PHPCR\ItemExistsException
*/
public function testCloneReferenceableNoRemoveExisting()
Expand All @@ -149,6 +153,10 @@ public function testCloneReferenceableNoRemoveExisting()
}

/**
* Clone a referenceable node, then clone again with removeExisting = false.
* Even though the second clone is to a new location, because a corresponding node (same UUID)
* already exists in the destination workspace, an exception should still be thrown.
*
* @expectedException \PHPCR\ItemExistsException
*/
public function testCloneNoRemoveExistingNewLocation()
Expand All @@ -171,6 +179,36 @@ public function testCloneNoRemoveExistingNewLocation()
self::$destWs->cloneFrom($this->srcWsName, $srcNode, $secondDstNode, false);
}

/**
* Check that we don't inadvertently create same name siblings (SNS) with removeExisting = true.
* This can happen when cloning from one workspace to another, when a node already exists at the
* destination but is not a corresponding node (the nodes have different UUIDs)
*
* @expectedException \PHPCR\ItemExistsException
*/
public function testExistingNonCorrespondingNodeRemoveExisting()
{
$srcNode = '/tests_write_manipulation_clone/testWorkspaceCloneNonCorresponding/sourceRemoveExisting';
$dstNode = '/tests_additional_workspace/testWorkspaceCloneNonCorresponding/destRemoveExisting';

self::$destWs->cloneFrom($this->srcWsName, $srcNode, $dstNode, true);
}

/**
* Check that we don't inadvertently create same name siblings (SNS) with removeExisting = false.
* This can happen when cloning from one workspace to another, when a node already exists at the
* destination but is not a corresponding node (the nodes have different UUIDs)
*
* @expectedException \PHPCR\ItemExistsException
*/
public function testExistingNonCorrespondingNodeNoRemoveExisting()
{
$srcNode = '/tests_write_manipulation_clone/testWorkspaceCloneNonCorresponding/sourceNoRemoveExisting';
$dstNode = '/tests_additional_workspace/testWorkspaceCloneNonCorresponding/destNoRemoveExisting';

self::$destWs->cloneFrom($this->srcWsName, $srcNode, $dstNode, false);
}

/**
* @expectedException \PHPCR\NoSuchWorkspaceException
*/
Expand Down Expand Up @@ -256,7 +294,7 @@ public function testCloneNonReferenceable()
}

/**
* Clone a non-referenceable node, then clone again with 'remove existing' feature.
* Clone a non-referenceable node, then clone again with removeExisting = true
*/
public function testCloneRemoveExistingNonReferenceable()
{
Expand Down

0 comments on commit a76c97c

Please sign in to comment.