Skip to content

Added test for maintaining references after copying #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions fixtures/10_Writing/copy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,69 @@
</sv:property>
</sv:node>
</sv:node>

<sv:node sv:name="testCopyUpdateReferrersSingleValue">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:node sv:name="referencedNode">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>00000000-0000-0000-0000-000000000010</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="srcNode">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="reference" sv:type="Reference">
<sv:value>00000000-0000-0000-0000-000000000010</sv:value>
</sv:property>
</sv:node>
</sv:node>

<sv:node sv:name="testCopyUpdateReferrersMultiValue">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:node sv:name="referencedNode1">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>00000000-0000-0000-0000-000000000012</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="referencedNode2">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>00000000-0000-0000-0000-000000000013</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="srcNode">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="reference" sv:type="Reference" sv:multiple="true">
<sv:value>00000000-0000-0000-0000-000000000012</sv:value>
<sv:value>00000000-0000-0000-0000-000000000013</sv:value>
</sv:property>
</sv:node>
</sv:node>

<sv:node sv:name="testCopyNoUpdateOnCopy">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
Expand Down
47 changes: 40 additions & 7 deletions tests/10_Writing/CopyMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,49 @@ public function testCopyNoUpdateOnCopy()
$this->ws->copy($src, $dst);
}

public function testCopyUpdateOnCopy()
/**
* When a node is copied, any nodes to which it refers should show the copied node in its list of references.
*/
public function testCopyUpdateReferencesSingleValue()
{
$src = '/tests_write_manipulation_copy/testCopyUpdateOnCopy/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyUpdateOnCopy/dstNode/srcNode';
$src = '/tests_write_manipulation_copy/testCopyUpdateReferrersSingleValue/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyUpdateReferrersSingleValue/dstNode';
$ref = '/tests_write_manipulation_copy/testCopyUpdateReferrersSingleValue/referencedNode';

$node = $this->session->getNode($ref);
$references = $node->getReferences();
$this->assertCount(1, $references);

$this->ws->copy($src, $dst);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have the assertions before and after refreshing, to make sure both the object state and the storage state are correctly updated.


// make sure child node was copied
$this->assertTrue($this->session->nodeExists($dst.'/srcFile'));
// make sure things were updated
$this->assertEquals('123', $this->session->getProperty($dst.'/updateFile/jcr:data')->getValue());
$references = $node->getReferences();
$this->assertCount(2, $references);

$this->session->refresh(true );

$node = $this->session->getNode($ref);
$references = $node->getReferences();

$this->assertCount(2, $references);
}

/**
* Copied nodes which reference other nodes should be shown in the referrers list of references
* Multi-value
*/
public function testCopyUpdateReferencesMultiValue()
{
$src = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/dstNode';
$ref1 = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/referencedNode1';
$ref2 = '/tests_write_manipulation_copy/testCopyUpdateReferrersMultiValue/referencedNode2';

$this->ws->copy($src, $dst);
$this->session->refresh(true);

$node = $this->session->getNode($ref1);
$references = $node->getReferences();

$this->assertCount(2, $references);
}
}