Skip to content

Commit a8071d7

Browse files
committed
Merge pull request #153 from phpcr/reinstated-multivalue-tests
Reinstated multivalue tests
2 parents 7c90f87 + 35e6af9 commit a8071d7

File tree

2 files changed

+220
-31
lines changed

2 files changed

+220
-31
lines changed
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node xmlns:crx="http://www.day.com/crx/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" sv:name="tests_mixinreferencable">
3+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
4+
<sv:value>nt:unstructured</sv:value>
5+
</sv:property>
6+
<sv:property sv:name="jcr:created" sv:type="Date">
7+
<sv:value>2009-04-27T13:00:54.082+02:00</sv:value>
8+
</sv:property>
9+
10+
<sv:node sv:name="testReferenceOnNonReferenceableNode">
11+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
12+
<sv:value>nt:unstructured</sv:value>
13+
</sv:property>
14+
<sv:node sv:name="non-referenceable">
15+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
16+
<sv:value>nt:unstructured</sv:value>
17+
</sv:property>
18+
</sv:node>
19+
<sv:node sv:name="node">
20+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
21+
<sv:value>nt:unstructured</sv:value>
22+
</sv:property>
23+
</sv:node>
24+
</sv:node>
25+
26+
<sv:node sv:name="testReferenceOnNewlyReferenceableNode">
27+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
28+
<sv:value>nt:unstructured</sv:value>
29+
</sv:property>
30+
31+
<sv:node sv:name="other-node">
32+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
33+
<sv:value>nt:unstructured</sv:value>
34+
</sv:property>
35+
</sv:node>
36+
<sv:node sv:name="node">
37+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
38+
<sv:value>nt:unstructured</sv:value>
39+
</sv:property>
40+
</sv:node>
41+
</sv:node>
42+
43+
<sv:node sv:name="testReferenceOnReferenceableNode">
44+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
45+
<sv:value>nt:unstructured</sv:value>
46+
</sv:property>
47+
48+
<sv:node sv:name="referenceable">
49+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
50+
<sv:value>nt:unstructured</sv:value>
51+
</sv:property>
52+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
53+
<sv:value>mix:referenceable</sv:value>
54+
</sv:property>
55+
<sv:property sv:name="jcr:uuid" sv:type="String">
56+
<sv:value>842e61c0-09ab-42a9-87c0-308ccc90e6f4</sv:value>
57+
</sv:property>
58+
</sv:node>
59+
<sv:node sv:name="node">
60+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
61+
<sv:value>nt:unstructured</sv:value>
62+
</sv:property>
63+
</sv:node>
64+
</sv:node>
65+
66+
<sv:node sv:name="testUpdateReference">
67+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
68+
<sv:value>nt:unstructured</sv:value>
69+
</sv:property>
70+
71+
<sv:node sv:name="referenceable">
72+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
73+
<sv:value>nt:unstructured</sv:value>
74+
</sv:property>
75+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
76+
<sv:value>mix:referenceable</sv:value>
77+
</sv:property>
78+
<sv:property sv:name="jcr:uuid" sv:type="String">
79+
<sv:value>242e61c0-09ab-42a9-82c0-398cc690e6f4</sv:value>
80+
</sv:property>
81+
</sv:node>
82+
<sv:node sv:name="node">
83+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
84+
<sv:value>nt:unstructured</sv:value>
85+
</sv:property>
86+
</sv:node>
87+
<sv:node sv:name="other-node">
88+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
89+
<sv:value>nt:unstructured</sv:value>
90+
</sv:property>
91+
</sv:node>
92+
</sv:node>
93+
94+
<sv:node sv:name="testMultiValueReference">
95+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
96+
<sv:value>nt:unstructured</sv:value>
97+
</sv:property>
98+
</sv:node>
99+
100+
<sv:node sv:name="testMultiValueWeakReference">
101+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
102+
<sv:value>nt:unstructured</sv:value>
103+
</sv:property>
104+
</sv:node>
105+
106+
<sv:node sv:name="testSetUuidNewReferenceable">
107+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
108+
<sv:value>nt:unstructured</sv:value>
109+
</sv:property>
110+
</sv:node>
111+
112+
<sv:node sv:name="testSetUuidNewButNonreferenceable">
113+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
114+
<sv:value>nt:unstructured</sv:value>
115+
</sv:property>
116+
</sv:node>
117+
118+
<sv:node sv:name="testSetUuidButNotReferenceableExisting">
119+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
120+
<sv:value>nt:unstructured</sv:value>
121+
</sv:property>
122+
</sv:node>
123+
124+
<sv:node sv:name="testSetUuidReferenceableButExisting">
125+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
126+
<sv:value>nt:unstructured</sv:value>
127+
</sv:property>
128+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
129+
<sv:value>mix:referenceable</sv:value>
130+
</sv:property>
131+
</sv:node>
132+
</sv:node>
133+
+87-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace PHPCR\Tests\Writing;
33

4+
use PHPCR\PropertyType;
5+
46
require_once(__DIR__ . '/../../inc/BaseCase.php');
57

68
/**
@@ -10,6 +12,11 @@
1012
*/
1113
class MixinReferenceableTest extends \PHPCR\Test\BaseCase
1214
{
15+
public static function setupBeforeClass($fixtures = '10_Writing/mixinreferenceable')
16+
{
17+
parent::setupBeforeClass($fixtures);
18+
}
19+
1320
public function setUp()
1421
{
1522
$this->renewSession(); // discard changes
@@ -22,11 +29,11 @@ public function setUp()
2229
public function testReferenceOnNonReferenceableNode()
2330
{
2431
// Load a non-referenceable node
25-
$referenced_node = $this->session->getNode('/tests_general_base/emptyExample');
32+
$nonReferenceableNode = $this->node->getNode('non-referenceable');
2633

2734
// Try to reference it
28-
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
29-
$source_node->setProperty('reference', $referenced_node, \PHPCR\PropertyType::WEAKREFERENCE);
35+
$sourceNode = $this->node->getNode('node');
36+
$sourceNode->setProperty('reference', $nonReferenceableNode, \PHPCR\PropertyType::WEAKREFERENCE);
3037
$this->session->save();
3138
}
3239

@@ -36,24 +43,24 @@ public function testReferenceOnNonReferenceableNode()
3643
public function testReferenceOnNewlyReferenceableNode()
3744
{
3845
// Load a non-referenceable node and make it referenceable
39-
$referenced_node = $this->session->getNode('/tests_general_base/emptyExample');
40-
$referenced_node->addMixin('mix:referenceable');
46+
$referencedNode = $this->node->getNode('node');
47+
$referencedNode->addMixin('mix:referenceable');
4148

4249
// Re-read the node to be sure it has a UUID
4350
$this->saveAndRenewSession();
44-
$referenced_node = $this->session->getNode('/tests_general_base/emptyExample');
51+
$referencedNode = $this->node->getNode('node');
4552

4653
// Reference it from another node
47-
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
48-
$source_node->setProperty('reference', $referenced_node, \PHPCR\PropertyType::WEAKREFERENCE);
54+
$sourceNode = $this->node->getNode('other-node');
55+
$sourceNode->setProperty('reference', $referencedNode, \PHPCR\PropertyType::WEAKREFERENCE);
4956

5057
$this->session->save();
5158

52-
$this->assertInstanceOf('PHPCR\NodeInterface', $source_node->getPropertyValue('reference'));
59+
$this->assertInstanceOf('PHPCR\NodeInterface', $sourceNode->getPropertyValue('reference'));
5360

5461
// referrers only required to work once save happened
55-
$this->assertCount(0, $referenced_node->getReferences());
56-
$this->assertCount(1, $referenced_node->getWeakReferences());
62+
$this->assertCount(0, $referencedNode->getReferences());
63+
$this->assertCount(1, $referencedNode->getWeakReferences());
5764
}
5865

5966
/**
@@ -62,54 +69,105 @@ public function testReferenceOnNewlyReferenceableNode()
6269
public function testReferenceOnReferenceableNode()
6370
{
6471
// Load a referenceable node
65-
$referenced_node = $this->session->getNode('/tests_general_base/idExample');
72+
$referencedNode = $this->node->getNode('referenceable');
6673

6774
// Reference it from another node
68-
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
69-
$source_node->setProperty('oreference', $referenced_node, \PHPCR\PropertyType::WEAKREFERENCE);
75+
$sourceNode = $this->node->getNode('node');
76+
$sourceNode->setProperty('oreference', $referencedNode, \PHPCR\PropertyType::WEAKREFERENCE);
7077
$this->session->save();
7178

72-
$this->assertInstanceOf('PHPCR\NodeInterface', $source_node->getPropertyValue('oreference'));
79+
$this->assertInstanceOf('PHPCR\NodeInterface', $sourceNode->getPropertyValue('oreference'));
7380
}
7481

7582
/**
7683
* Test that we can update a reference
7784
*/
7885
public function testUpdateReference()
7986
{
80-
$referenced1 = $this->session->getNode('/tests_general_base/emptyExample');
87+
$referenced1 = $this->node->getNode('node');
8188
$referenced1->addMixin('mix:referenceable');
8289
$this->session->save();
8390

8491
// Load a referenceable node
85-
$referenced2 = $this->session->getNode('/tests_general_base/idExample');
92+
$referenced2 = $this->node->getNode('referenceable');
8693

8794
// Reference it from another node
88-
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
95+
$sourceNode = $this->node->getNode('other-node');
8996

90-
$source_node->setProperty('reference', $referenced1, \PHPCR\PropertyType::WEAKREFERENCE);
97+
$sourceNode->setProperty('reference', $referenced1, \PHPCR\PropertyType::WEAKREFERENCE);
9198
$this->session->save();
92-
$source_node->setProperty('reference', $referenced2, \PHPCR\PropertyType::WEAKREFERENCE);
99+
$sourceNode->setProperty('reference', $referenced2, \PHPCR\PropertyType::WEAKREFERENCE);
93100
$this->session->save();
94-
$this->assertSame($referenced2, $source_node->getPropertyValue('reference'));
101+
$this->assertSame($referenced2, $sourceNode->getPropertyValue('reference'));
95102

96-
$session = $this->renewSession();
97-
$referenced2 = $session->getNode('/tests_general_base/idExample');
98-
$this->assertSame($referenced2, $session->getProperty('/tests_general_base/index.txt/jcr:content/reference')->getValue());
103+
$this->renewSession();
104+
$referenced2 = $this->node->getNode('referenceable');
105+
$this->assertSame($referenced2, $this->node->getNode('other-node')->getProperty('reference')->getValue());
106+
}
107+
108+
public function testMultiValueReference()
109+
{
110+
$this->doTestMultiValueReference(
111+
array('one', 'two', 'three'),
112+
array('one', 'two', 'one', 'one', 'two', 'three'),
113+
PropertyType::REFERENCE
114+
);
115+
}
116+
117+
public function testMultiValueWeakReference()
118+
{
119+
$this->doTestMultiValueReference(
120+
array('one', 'two', 'three'),
121+
array('one', 'two', 'one', 'one', 'two', 'three'),
122+
PropertyType::WEAKREFERENCE
123+
);
124+
}
125+
126+
private function doTestMultiValueReference($nodeNames, $nodeCollectionNames, $referenceType)
127+
{
128+
$baseNode = $this->node;
129+
$nodes = array();
130+
foreach ($nodeNames as $nodeName) {
131+
$node = $baseNode->addNode($nodeName);
132+
$node->addMixin('mix:referenceable');
133+
$nodes[$nodeName] = $node;
134+
}
135+
136+
$this->session->save();
137+
138+
$referrer = $baseNode->addNode('referrer');
139+
140+
$nodeCollection = array();
141+
142+
foreach ($nodeCollectionNames as $nodeCollectionName) {
143+
$nodeCollection[] = $nodes[$nodeCollectionName];
144+
}
145+
$referrer->setProperty('references', $nodeCollection, $referenceType);
146+
147+
$this->session->save();
148+
149+
$this->renewSession();
150+
$referrer = $this->node->getNode('referrer');
151+
$values = $referrer->getProperty('references');
152+
153+
foreach ($values as $referencedNode) {
154+
$name = array_shift($nodeCollectionNames);
155+
$this->assertSame($name, $referencedNode->getName());
156+
}
99157
}
100158

101159
public function testSetUuidNewReferenceable()
102160
{
103161
$uuid = 'aaaa61c0-09ab-42a9-87c0-308ccc93aaaa';
104-
$node = $this->session->getNode('/tests_general_base/index.txt/jcr:content')->addNode('newId', 'nt:unstructured');
162+
$node = $this->node->addNode('newId', 'nt:unstructured');
105163
$node->addMixin('mix:referenceable');
106164
$node->setProperty('jcr:uuid', $uuid);
107165
$this->session->save();
108166
$this->assertSame($uuid, $node->getIdentifier());
109167

110168
$session = $this->renewSession();
111169

112-
$node = $session->getNode('/tests_general_base/index.txt/jcr:content/newId');
170+
$node = $this->node->getNode('newId');
113171
$this->assertSame($uuid, $node->getIdentifier());
114172
}
115173

@@ -118,7 +176,7 @@ public function testSetUuidNewReferenceable()
118176
*/
119177
public function testSetUuidNewButNonreferenceable()
120178
{
121-
$node = $this->session->getNode('/tests_general_base/index.txt/jcr:content')->addNode('newNonref', 'nt:unstructured');
179+
$node = $this->node->addNode('newNonref', 'nt:unstructured');
122180
$node->setProperty('jcr:uuid', 'bbbb61c0-09ab-42a9-87c0-308ccc93aaaa');
123181
}
124182

@@ -127,16 +185,14 @@ public function testSetUuidNewButNonreferenceable()
127185
*/
128186
public function testSetUuidReferenceableButExisting()
129187
{
130-
$node = $this->session->getNode('/tests_general_base/idExample');
131-
$node->setProperty('jcr:uuid', 'cccc61c0-09ab-42a9-87c0-308ccc93aaaa');
188+
$this->node->setProperty('jcr:uuid', 'cccc61c0-09ab-42a9-87c0-308ccc93aaaa');
132189
}
133190

134191
/**
135192
* @expectedException \PHPCR\NodeType\ConstraintViolationException
136193
*/
137194
public function testSetUuidButNotReferenceableExisting()
138195
{
139-
$node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
140-
$node->setProperty('jcr:uuid', 'dddd61c0-09ab-42a9-87c0-308ccc93aaaa');
196+
$this->node->setProperty('jcr:uuid', 'dddd61c0-09ab-42a9-87c0-308ccc93aaaa');
141197
}
142198
}

0 commit comments

Comments
 (0)