From ed3444cce3a50da9e9dd8e730f6356fef77a5eea Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 6 Jan 2015 09:05:31 +0100 Subject: [PATCH] test behaviour with jcr:uuid property --- tests/05_Reading/NodeReadMethodsTest.php | 14 ++++++- tests/10_Writing/MixinReferenceableTest.php | 42 +++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/05_Reading/NodeReadMethodsTest.php b/tests/05_Reading/NodeReadMethodsTest.php index 5342ae6f..cdb788d2 100644 --- a/tests/05_Reading/NodeReadMethodsTest.php +++ b/tests/05_Reading/NodeReadMethodsTest.php @@ -444,9 +444,21 @@ public function testGetIdentifier() $this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $id); } + /** + * The JCR specification is not saying what the properties of this id + * should be. But it must be a string. + */ + public function testGetIdentifierNonReferenceable() + { + $id = $this->node->getNode('index.txt')->getIdentifier(); + $this->assertInternalType('string', $id); + } + + /** + * getIndex has to work even when same-name siblings are not allowed. + */ public function testGetIndex() { - //TODO: Improve this test to test actual multiple nodes $index = $this->node->getIndex(); $this->assertTrue(is_numeric($index)); $this->assertEquals(1, $index); diff --git a/tests/10_Writing/MixinReferenceableTest.php b/tests/10_Writing/MixinReferenceableTest.php index c72afa6e..d7824823 100644 --- a/tests/10_Writing/MixinReferenceableTest.php +++ b/tests/10_Writing/MixinReferenceableTest.php @@ -97,4 +97,46 @@ public function testUpdateReference() $referenced2 = $session->getNode('/tests_general_base/idExample'); $this->assertSame($referenced2, $session->getProperty('/tests_general_base/index.txt/jcr:content/reference')->getValue()); } + + public function testSetUuidNewReferenceable() + { + $uuid = 'aaaa61c0-09ab-42a9-87c0-308ccc93aaaa'; + $node = $this->session->getNode('/tests_general_base/index.txt/jcr:content')->addNode('newId', 'nt:unstructured'); + $node->addMixin('mix:referenceable'); + $node->setProperty('jcr:uuid', $uuid); + $this->session->save(); + $this->assertSame($uuid, $node->getIdentifier()); + + $session = $this->renewSession(); + + $node = $session->getNode('/tests_general_base/index.txt/jcr:content/newId'); + $this->assertSame($uuid, $node->getIdentifier()); + } + + /** + * @expectedException \PHPCR\NodeType\ConstraintViolationException + */ + public function testSetUuidNewButNonreferenceable() + { + $node = $this->session->getNode('/tests_general_base/index.txt/jcr:content')->addNode('newNonref', 'nt:unstructured'); + $node->setProperty('jcr:uuid', 'bbbb61c0-09ab-42a9-87c0-308ccc93aaaa'); + } + + /** + * @expectedException \PHPCR\NodeType\ConstraintViolationException + */ + public function testSetUuidReferenceableButExisting() + { + $node = $this->session->getNode('/tests_general_base/idExample'); + $node->setProperty('jcr:uuid', 'cccc61c0-09ab-42a9-87c0-308ccc93aaaa'); + } + + /** + * @expectedException \PHPCR\NodeType\ConstraintViolationException + */ + public function testSetUuidButNotReferenceableExisting() + { + $node = $this->session->getNode('/tests_general_base/index.txt/jcr:content'); + $node->setProperty('jcr:uuid', 'dddd61c0-09ab-42a9-87c0-308ccc93aaaa'); + } }