Skip to content

Commit ed3444c

Browse files
committed
test behaviour with jcr:uuid property
1 parent a6a6d78 commit ed3444c

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

tests/05_Reading/NodeReadMethodsTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,21 @@ public function testGetIdentifier()
444444
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $id);
445445
}
446446

447+
/**
448+
* The JCR specification is not saying what the properties of this id
449+
* should be. But it must be a string.
450+
*/
451+
public function testGetIdentifierNonReferenceable()
452+
{
453+
$id = $this->node->getNode('index.txt')->getIdentifier();
454+
$this->assertInternalType('string', $id);
455+
}
456+
457+
/**
458+
* getIndex has to work even when same-name siblings are not allowed.
459+
*/
447460
public function testGetIndex()
448461
{
449-
//TODO: Improve this test to test actual multiple nodes
450462
$index = $this->node->getIndex();
451463
$this->assertTrue(is_numeric($index));
452464
$this->assertEquals(1, $index);

tests/10_Writing/MixinReferenceableTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,46 @@ public function testUpdateReference()
9797
$referenced2 = $session->getNode('/tests_general_base/idExample');
9898
$this->assertSame($referenced2, $session->getProperty('/tests_general_base/index.txt/jcr:content/reference')->getValue());
9999
}
100+
101+
public function testSetUuidNewReferenceable()
102+
{
103+
$uuid = 'aaaa61c0-09ab-42a9-87c0-308ccc93aaaa';
104+
$node = $this->session->getNode('/tests_general_base/index.txt/jcr:content')->addNode('newId', 'nt:unstructured');
105+
$node->addMixin('mix:referenceable');
106+
$node->setProperty('jcr:uuid', $uuid);
107+
$this->session->save();
108+
$this->assertSame($uuid, $node->getIdentifier());
109+
110+
$session = $this->renewSession();
111+
112+
$node = $session->getNode('/tests_general_base/index.txt/jcr:content/newId');
113+
$this->assertSame($uuid, $node->getIdentifier());
114+
}
115+
116+
/**
117+
* @expectedException \PHPCR\NodeType\ConstraintViolationException
118+
*/
119+
public function testSetUuidNewButNonreferenceable()
120+
{
121+
$node = $this->session->getNode('/tests_general_base/index.txt/jcr:content')->addNode('newNonref', 'nt:unstructured');
122+
$node->setProperty('jcr:uuid', 'bbbb61c0-09ab-42a9-87c0-308ccc93aaaa');
123+
}
124+
125+
/**
126+
* @expectedException \PHPCR\NodeType\ConstraintViolationException
127+
*/
128+
public function testSetUuidReferenceableButExisting()
129+
{
130+
$node = $this->session->getNode('/tests_general_base/idExample');
131+
$node->setProperty('jcr:uuid', 'cccc61c0-09ab-42a9-87c0-308ccc93aaaa');
132+
}
133+
134+
/**
135+
* @expectedException \PHPCR\NodeType\ConstraintViolationException
136+
*/
137+
public function testSetUuidButNotReferenceableExisting()
138+
{
139+
$node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
140+
$node->setProperty('jcr:uuid', 'dddd61c0-09ab-42a9-87c0-308ccc93aaaa');
141+
}
100142
}

0 commit comments

Comments
 (0)