Skip to content

Commit 51c4a38

Browse files
committed
Merge pull request #155 from phpcr/copy_update_referrers
Added test for maintaining references after copying
2 parents 376e5e0 + a1c72fc commit 51c4a38

File tree

2 files changed

+103
-7
lines changed

2 files changed

+103
-7
lines changed

fixtures/10_Writing/copy.xml

+63
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,69 @@
276276
</sv:property>
277277
</sv:node>
278278
</sv:node>
279+
280+
<sv:node sv:name="testCopyUpdateReferrersSingleValue">
281+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
282+
<sv:value>nt:unstructured</sv:value>
283+
</sv:property>
284+
<sv:node sv:name="referencedNode">
285+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
286+
<sv:value>nt:unstructured</sv:value>
287+
</sv:property>
288+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
289+
<sv:value>mix:referenceable</sv:value>
290+
</sv:property>
291+
<sv:property sv:name="jcr:uuid" sv:type="String">
292+
<sv:value>00000000-0000-0000-0000-000000000010</sv:value>
293+
</sv:property>
294+
</sv:node>
295+
<sv:node sv:name="srcNode">
296+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
297+
<sv:value>nt:unstructured</sv:value>
298+
</sv:property>
299+
<sv:property sv:name="reference" sv:type="Reference">
300+
<sv:value>00000000-0000-0000-0000-000000000010</sv:value>
301+
</sv:property>
302+
</sv:node>
303+
</sv:node>
304+
305+
<sv:node sv:name="testCopyUpdateReferrersMultiValue">
306+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
307+
<sv:value>nt:unstructured</sv:value>
308+
</sv:property>
309+
<sv:node sv:name="referencedNode1">
310+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
311+
<sv:value>nt:unstructured</sv:value>
312+
</sv:property>
313+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
314+
<sv:value>mix:referenceable</sv:value>
315+
</sv:property>
316+
<sv:property sv:name="jcr:uuid" sv:type="String">
317+
<sv:value>00000000-0000-0000-0000-000000000012</sv:value>
318+
</sv:property>
319+
</sv:node>
320+
<sv:node sv:name="referencedNode2">
321+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
322+
<sv:value>nt:unstructured</sv:value>
323+
</sv:property>
324+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
325+
<sv:value>mix:referenceable</sv:value>
326+
</sv:property>
327+
<sv:property sv:name="jcr:uuid" sv:type="String">
328+
<sv:value>00000000-0000-0000-0000-000000000013</sv:value>
329+
</sv:property>
330+
</sv:node>
331+
<sv:node sv:name="srcNode">
332+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
333+
<sv:value>nt:unstructured</sv:value>
334+
</sv:property>
335+
<sv:property sv:name="reference" sv:type="Reference" sv:multiple="true">
336+
<sv:value>00000000-0000-0000-0000-000000000012</sv:value>
337+
<sv:value>00000000-0000-0000-0000-000000000013</sv:value>
338+
</sv:property>
339+
</sv:node>
340+
</sv:node>
341+
279342
<sv:node sv:name="testCopyNoUpdateOnCopy">
280343
<sv:property sv:name="jcr:primaryType" sv:type="Name">
281344
<sv:value>nt:unstructured</sv:value>

tests/10_Writing/CopyMethodsTest.php

+40-7
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,49 @@ public function testCopyNoUpdateOnCopy()
186186
$this->ws->copy($src, $dst);
187187
}
188188

189-
public function testCopyUpdateOnCopy()
189+
/**
190+
* When a node is copied, any nodes to which it refers should show the copied node in its list of references.
191+
*/
192+
public function testCopyUpdateReferencesSingleValue()
190193
{
191-
$src = '/tests_write_manipulation_copy/testCopyUpdateOnCopy/srcNode';
192-
$dst = '/tests_write_manipulation_copy/testCopyUpdateOnCopy/dstNode/srcNode';
194+
$src = '/tests_write_manipulation_copy/testCopyUpdateReferrersSingleValue/srcNode';
195+
$dst = '/tests_write_manipulation_copy/testCopyUpdateReferrersSingleValue/dstNode';
196+
$ref = '/tests_write_manipulation_copy/testCopyUpdateReferrersSingleValue/referencedNode';
197+
198+
$node = $this->session->getNode($ref);
199+
$references = $node->getReferences();
200+
$this->assertCount(1, $references);
201+
193202
$this->ws->copy($src, $dst);
194203

195-
// make sure child node was copied
196-
$this->assertTrue($this->session->nodeExists($dst.'/srcFile'));
197-
// make sure things were updated
198-
$this->assertEquals('123', $this->session->getProperty($dst.'/updateFile/jcr:data')->getValue());
204+
$references = $node->getReferences();
205+
$this->assertCount(2, $references);
206+
207+
$this->session->refresh(true );
208+
209+
$node = $this->session->getNode($ref);
210+
$references = $node->getReferences();
211+
212+
$this->assertCount(2, $references);
199213
}
200214

215+
/**
216+
* Copied nodes which reference other nodes should be shown in the referrers list of references
217+
* Multi-value
218+
*/
219+
public function testCopyUpdateReferencesMultiValue()
220+
{
221+
$src = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/srcNode';
222+
$dst = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/dstNode';
223+
$ref1 = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/referencedNode1';
224+
$ref2 = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/referencedNode2';
225+
226+
$this->ws->copy($src, $dst);
227+
$this->session->refresh(true);
228+
229+
$node = $this->session->getNode($ref1);
230+
$references = $node->getReferences();
231+
232+
$this->assertCount(2, $references);
233+
}
201234
}

0 commit comments

Comments
 (0)