Skip to content

Added test for reusing a path with a different Identifier #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions fixtures/10_Writing/delete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@
</sv:node>
</sv:node>

<sv:node sv:name="testDeleteNodeAndReusePathWithReference">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>

<sv:node sv:name="idExample">
<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>cbc172b2-c317-44ac-a73b-1df61c35fb1a</sv:value>
</sv:property>
</sv:node>
</sv:node>

<sv:node sv:name="testWorkspaceDelete">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
Expand Down
37 changes: 37 additions & 0 deletions tests/10_Writing/DeleteMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,43 @@ public function testDeleteWeakReferencedNode()
$this->assertFalse($this->node->hasNode('idExample'));
}

/**
* test if deleting a node and creating a node at the same path with a new UUID
* won't cause trouble with internally cached UUID's
*/
public function testDeleteNodeAndReusePathWithReference()
{
//relies on the base class setup trick to have the node populated from the fixtures
$this->assertInstanceOf('PHPCR\NodeInterface', $this->node);

// 1. remove the idExample node with UUID cbc172b2-c317-44ac-a73b-1df61c35fb1a
$referencedNode = $this->node->getNode('idExample');
$referencedNode->remove();

// 2. Save the session (without reloading)
$this->session->save();

// 3. Recreate the node with a specific UUID
$referencedNode = $this->node->addNode('idExample');
// Add mixin to make it referenceable
$referencedNode->addMixin('mix:referenceable');
// Change Identifier from the one in the fixtures
$referencedNode->setProperty('jcr:uuid', '54378257-ca4d-4b9f-9383-f30dfb280977');

// Node should be persisted before using it as a reference
$this->session->save();

// 4. Give the testNode a reference to the new idExample node
$this->node->setProperty('reference', '54378257-ca4d-4b9f-9383-f30dfb280977', \PHPCR\PropertyType::REFERENCE);

// 5. Throws an PHPCR\ReferentialIntegrityException when above UUID is not a valid reference
$this->saveAndRenewSession();

$this->assertInstanceOf('PHPCR\NodeInterface', $this->node);
$this->assertEquals('54378257-ca4d-4b9f-9383-f30dfb280977', $this->node->getProperty('reference')->getString(), 'Reference property should contain "54378257-ca4d-4b9f-9383-f30dfb280977" as string value');
$this->assertEquals('54378257-ca4d-4b9f-9383-f30dfb280977', $this->node->getNode('idExample')->getIdentifier(), 'idExample node should have "54378257-ca4d-4b9f-9383-f30dfb280977" as UUID');
}

public function testWorkspaceDelete()
{
//relies on the base class setup trick to have the node populated from the fixtures
Expand Down