Skip to content

Commit 7eeb2eb

Browse files
committed
Merge pull request #122 from wjzijderveld/test-for-dbal-pr-158
Added test for reusing a path with a different Identifier
2 parents 7726fec + 1a3308c commit 7eeb2eb

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

fixtures/10_Writing/delete.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@
230230
</sv:node>
231231
</sv:node>
232232

233+
<sv:node sv:name="testDeleteNodeAndReusePathWithReference">
234+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
235+
<sv:value>nt:unstructured</sv:value>
236+
</sv:property>
237+
238+
<sv:node sv:name="idExample">
239+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
240+
<sv:value>nt:unstructured</sv:value>
241+
</sv:property>
242+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
243+
<sv:value>mix:referenceable</sv:value>
244+
</sv:property>
245+
<sv:property sv:name="jcr:uuid" sv:type="String">
246+
<sv:value>cbc172b2-c317-44ac-a73b-1df61c35fb1a</sv:value>
247+
</sv:property>
248+
</sv:node>
249+
</sv:node>
250+
233251
<sv:node sv:name="testWorkspaceDelete">
234252
<sv:property sv:name="jcr:primaryType" sv:type="Name">
235253
<sv:value>nt:unstructured</sv:value>

tests/10_Writing/DeleteMethodsTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,43 @@ public function testDeleteWeakReferencedNode()
450450
$this->assertFalse($this->node->hasNode('idExample'));
451451
}
452452

453+
/**
454+
* test if deleting a node and creating a node at the same path with a new UUID
455+
* won't cause trouble with internally cached UUID's
456+
*/
457+
public function testDeleteNodeAndReusePathWithReference()
458+
{
459+
//relies on the base class setup trick to have the node populated from the fixtures
460+
$this->assertInstanceOf('PHPCR\NodeInterface', $this->node);
461+
462+
// 1. remove the idExample node with UUID cbc172b2-c317-44ac-a73b-1df61c35fb1a
463+
$referencedNode = $this->node->getNode('idExample');
464+
$referencedNode->remove();
465+
466+
// 2. Save the session (without reloading)
467+
$this->session->save();
468+
469+
// 3. Recreate the node with a specific UUID
470+
$referencedNode = $this->node->addNode('idExample');
471+
// Add mixin to make it referenceable
472+
$referencedNode->addMixin('mix:referenceable');
473+
// Change Identifier from the one in the fixtures
474+
$referencedNode->setProperty('jcr:uuid', '54378257-ca4d-4b9f-9383-f30dfb280977');
475+
476+
// Node should be persisted before using it as a reference
477+
$this->session->save();
478+
479+
// 4. Give the testNode a reference to the new idExample node
480+
$this->node->setProperty('reference', '54378257-ca4d-4b9f-9383-f30dfb280977', \PHPCR\PropertyType::REFERENCE);
481+
482+
// 5. Throws an PHPCR\ReferentialIntegrityException when above UUID is not a valid reference
483+
$this->saveAndRenewSession();
484+
485+
$this->assertInstanceOf('PHPCR\NodeInterface', $this->node);
486+
$this->assertEquals('54378257-ca4d-4b9f-9383-f30dfb280977', $this->node->getProperty('reference')->getString(), 'Reference property should contain "54378257-ca4d-4b9f-9383-f30dfb280977" as string value');
487+
$this->assertEquals('54378257-ca4d-4b9f-9383-f30dfb280977', $this->node->getNode('idExample')->getIdentifier(), 'idExample node should have "54378257-ca4d-4b9f-9383-f30dfb280977" as UUID');
488+
}
489+
453490
public function testWorkspaceDelete()
454491
{
455492
//relies on the base class setup trick to have the node populated from the fixtures

0 commit comments

Comments
 (0)