Skip to content

Commit 0cb8087

Browse files
committed
Merge remote-tracking branch 'fazy/node-cloning'
2 parents 81a75b8 + ff396f9 commit 0cb8087

File tree

5 files changed

+773
-7
lines changed

5 files changed

+773
-7
lines changed

fixtures/10_Writing/clone.xml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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_write_manipulation_clone">
3+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
4+
<sv:value>nt:unstructured</sv:value>
5+
</sv:property>
6+
<sv:node sv:name="testWorkspaceClone">
7+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
8+
<sv:value>nt:unstructured</sv:value>
9+
</sv:property>
10+
<sv:node sv:name="referenceable">
11+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
12+
<sv:value>nt:unstructured</sv:value>
13+
</sv:property>
14+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
15+
<sv:value>mix:referenceable</sv:value>
16+
</sv:property>
17+
<sv:property sv:name="jcr:uuid" sv:type="String">
18+
<sv:value>842e61c0-09ab-42a9-87c0-308ccc90e6f6</sv:value>
19+
</sv:property>
20+
<sv:property sv:name="foo" sv:type="Name">
21+
<sv:value>bar_1</sv:value>
22+
</sv:property>
23+
<sv:node sv:name="cloneChild">
24+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
25+
<sv:value>nt:unstructured</sv:value>
26+
</sv:property>
27+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
28+
<sv:value>mix:referenceable</sv:value>
29+
</sv:property>
30+
<sv:property sv:name="jcr:uuid" sv:type="String">
31+
<sv:value>9da62173-d674-4413-87a4-8f538e033021</sv:value>
32+
</sv:property>
33+
<sv:property sv:name="fooChild" sv:type="Name">
34+
<sv:value>barChild</sv:value>
35+
</sv:property>
36+
</sv:node>
37+
</sv:node>
38+
<sv:node sv:name="referenceableRemoveExisting">
39+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
40+
<sv:value>nt:unstructured</sv:value>
41+
</sv:property>
42+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
43+
<sv:value>mix:referenceable</sv:value>
44+
</sv:property>
45+
<sv:property sv:name="jcr:uuid" sv:type="String">
46+
<sv:value>091d157f-dfaf-42eb-aedd-88183ff8fa3d</sv:value>
47+
</sv:property>
48+
<sv:property sv:name="foo" sv:type="Name">
49+
<sv:value>bar_2</sv:value>
50+
</sv:property>
51+
</sv:node>
52+
<sv:node sv:name="referenceableNoRemoveExisting_1">
53+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
54+
<sv:value>nt:unstructured</sv:value>
55+
</sv:property>
56+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
57+
<sv:value>mix:referenceable</sv:value>
58+
</sv:property>
59+
<sv:property sv:name="jcr:uuid" sv:type="String">
60+
<sv:value>99cce0f7-91fd-4dab-a9ed-ea939981d40b</sv:value>
61+
</sv:property>
62+
</sv:node>
63+
<sv:node sv:name="referenceableNoRemoveExisting_2">
64+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
65+
<sv:value>nt:unstructured</sv:value>
66+
</sv:property>
67+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
68+
<sv:value>mix:referenceable</sv:value>
69+
</sv:property>
70+
<sv:property sv:name="jcr:uuid" sv:type="String">
71+
<sv:value>471711ef-043b-4692-874b-f634932e79ba</sv:value>
72+
</sv:property>
73+
</sv:node>
74+
<sv:node sv:name="nonReferenceable">
75+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
76+
<sv:value>nt:unstructured</sv:value>
77+
</sv:property>
78+
<sv:property sv:name="foo" sv:type="Name">
79+
<sv:value>bar_3</sv:value>
80+
</sv:property>
81+
</sv:node>
82+
<sv:node sv:name="nonReferenceableRemoveExisting">
83+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
84+
<sv:value>nt:unstructured</sv:value>
85+
</sv:property>
86+
<sv:property sv:name="foo" sv:type="Name">
87+
<sv:value>bar_4</sv:value>
88+
</sv:property>
89+
</sv:node>
90+
<sv:node sv:name="nonReferenceableNoRemoveExisting">
91+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
92+
<sv:value>nt:unstructured</sv:value>
93+
</sv:property>
94+
</sv:node>
95+
</sv:node>
96+
<sv:node sv:name="testWorkspaceCorrespondingNode">
97+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
98+
<sv:value>nt:unstructured</sv:value>
99+
</sv:property>
100+
<sv:node sv:name="sourceNode">
101+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
102+
<sv:value>mix:referenceable</sv:value>
103+
</sv:property>
104+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
105+
<sv:value>nt:unstructured</sv:value>
106+
</sv:property>
107+
<sv:property sv:name="jcr:uuid" sv:type="String">
108+
<sv:value>a64bfa45-d5e1-4bf0-a739-1890da40579d</sv:value>
109+
</sv:property>
110+
</sv:node>
111+
<sv:node sv:name="nodeThatWillNotBeCloned">
112+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
113+
<sv:value>mix:referenceable</sv:value>
114+
</sv:property>
115+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
116+
<sv:value>nt:unstructured</sv:value>
117+
</sv:property>
118+
<sv:property sv:name="jcr:uuid" sv:type="String">
119+
<sv:value>e7c14901-aec8-4e9b-8e76-704197d24794</sv:value>
120+
</sv:property>
121+
</sv:node>
122+
</sv:node>
123+
<sv:node sv:name="testWorkspaceUpdateNode">
124+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
125+
<sv:value>nt:unstructured</sv:value>
126+
</sv:property>
127+
<sv:node sv:name="sourceNode">
128+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
129+
<sv:value>mix:referenceable</sv:value>
130+
</sv:property>
131+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
132+
<sv:value>nt:unstructured</sv:value>
133+
</sv:property>
134+
<sv:property sv:name="jcr:uuid" sv:type="String">
135+
<sv:value>c8996418-3fd9-407c-bfe6-faea6dcfbb40</sv:value>
136+
</sv:property>
137+
<sv:property sv:name="foo" sv:type="Name">
138+
<sv:value>bar_5</sv:value>
139+
</sv:property>
140+
<sv:node sv:name="cloneChild">
141+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
142+
<sv:value>nt:unstructured</sv:value>
143+
</sv:property>
144+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
145+
<sv:value>mix:referenceable</sv:value>
146+
</sv:property>
147+
<sv:property sv:name="jcr:uuid" sv:type="String">
148+
<sv:value>e7683690-0465-4aa8-87c6-f37a67d08469</sv:value>
149+
</sv:property>
150+
<sv:property sv:name="fooChild" sv:type="Name">
151+
<sv:value>barChild</sv:value>
152+
</sv:property>
153+
<sv:node sv:name="childOfChild">
154+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
155+
<sv:value>nt:unstructured</sv:value>
156+
</sv:property>
157+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
158+
<sv:value>mix:referenceable</sv:value>
159+
</sv:property>
160+
<sv:property sv:name="jcr:uuid" sv:type="String">
161+
<sv:value>7547cb47-3c13-4e23-b6d1-29685a434c88</sv:value>
162+
</sv:property>
163+
<sv:property sv:name="fooChildOfChild" sv:type="Name">
164+
<sv:value>barChildOfChild</sv:value>
165+
</sv:property>
166+
</sv:node>
167+
</sv:node>
168+
</sv:node>
169+
<sv:node sv:name="updateNoSuchWorkspace">
170+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
171+
<sv:value>mix:referenceable</sv:value>
172+
</sv:property>
173+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
174+
<sv:value>nt:unstructured</sv:value>
175+
</sv:property>
176+
<sv:property sv:name="jcr:uuid" sv:type="String">
177+
<sv:value>8cd0ab49-1e3d-4b92-bfe4-48bf3e5efdb3</sv:value>
178+
</sv:property>
179+
<sv:property sv:name="foo" sv:type="Name">
180+
<sv:value>bar_5</sv:value>
181+
</sv:property>
182+
</sv:node>
183+
<sv:node sv:name="updateSrcNotFound">
184+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
185+
<sv:value>mix:referenceable</sv:value>
186+
</sv:property>
187+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
188+
<sv:value>nt:unstructured</sv:value>
189+
</sv:property>
190+
<sv:property sv:name="jcr:uuid" sv:type="String">
191+
<sv:value>1d392bcb-3e49-4f0e-b0af-7c30ab838122</sv:value>
192+
</sv:property>
193+
<sv:property sv:name="foo" sv:type="Name">
194+
<sv:value>bar_6</sv:value>
195+
</sv:property>
196+
</sv:node>
197+
</sv:node>
198+
</sv:node>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node xmlns:crx="http://www.day.com/crx/1.0"
3+
xmlns:lx="http://flux-cms.org/2.0"
4+
xmlns:test="http://liip.to/jackalope"
5+
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
6+
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
7+
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
8+
xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"
9+
xmlns:fn="http://www.w3.org/2005/xpath-functions"
10+
xmlns:vlt="http://www.day.com/jcr/vault/1.0"
11+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
12+
xmlns:new_prefix="http://a_new_namespace"
13+
xmlns:jcr="http://www.jcp.org/jcr/1.0"
14+
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
15+
xmlns:rep="internal"
16+
17+
sv:name="tests_general_additional_workspace">
18+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
19+
<sv:value>nt:unstructured</sv:value>
20+
</sv:property>
21+
</sv:node>

inc/AbstractLoader.php

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ abstract class AbstractLoader
1414
{
1515
protected $factoryclass;
1616
protected $workspacename;
17+
protected $otherWorkspacename;
1718

1819
/**
1920
* array with chapter names to skip all test cases in (without the numbers)
@@ -35,11 +36,14 @@ abstract class AbstractLoader
3536
* RepositoryFactory. You can pass null but then you must overwrite
3637
* the getRepository method.
3738
* @param string $workspacename the workspace to use for the tests, defaults to 'tests'
39+
* @param string $otherWorkspacename name of second workspace, defaults to 'testsAdditional'
40+
* Needed to test certain operations, such as clone, that span workspaces.
3841
*/
39-
protected function __construct($factoryclass, $workspacename = 'tests')
42+
protected function __construct($factoryclass, $workspacename = 'tests', $otherWorkspacename = 'testsAdditional')
4043
{
4144
$this->factoryclass = $factoryclass;
4245
$this->workspacename = $workspacename;
46+
$this->otherWorkspacename = $otherWorkspacename;
4347
}
4448

4549
/**
@@ -133,6 +137,14 @@ public function getWorkspaceName()
133137
return $this->workspacename;
134138
}
135139

140+
/**
141+
* @return string the additional workspace name used for tests that need it
142+
*/
143+
public function getOtherWorkspaceName()
144+
{
145+
return $this->otherWorkspacename;
146+
}
147+
136148
/**
137149
* Get a session for this implementation.
138150
*
@@ -141,12 +153,18 @@ public function getWorkspaceName()
141153
*/
142154
public function getSession($credentials = false)
143155
{
144-
$repository = $this->getRepository();
145-
if (false === $credentials) {
146-
$credentials = $this->getCredentials();
147-
}
156+
return $this->getSessionForWorkspace($credentials, $this->getWorkspaceName());
157+
}
148158

149-
return $repository->login($credentials, $this->getWorkspaceName());
159+
/**
160+
* Get a session corresponding to the additional workspace for this implementation.
161+
*
162+
* @param \PHPCR\CredentialsInterface $credentials The credentials to log into the repository. If omitted, self::getCredentials should be used
163+
* @return \PHPCR\SessionInterface the session resulting from logging into the repository with the provided credentials
164+
*/
165+
public function getAdditionalSession($credentials = false)
166+
{
167+
return $this->getSessionForWorkspace($credentials, $this->getOtherWorkspaceName());
150168
}
151169

152170
/**
@@ -174,4 +192,18 @@ public function getTestSupported($chapter, $case, $name)
174192
*/
175193
public abstract function getFixtureLoader();
176194

195+
/**
196+
* @param $credentials
197+
* @param $workspaceName
198+
* @return mixed
199+
*/
200+
private function getSessionForWorkspace($credentials, $workspaceName)
201+
{
202+
$repository = $this->getRepository();
203+
if (false === $credentials) {
204+
$credentials = $this->getCredentials();
205+
}
206+
207+
return $repository->login($credentials, $workspaceName);
208+
}
177209
}

inc/BaseCase.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace PHPCR\Test;
33

4+
use PHPCR\NodeInterface;
5+
46
// PHPUnit 3.4 compat
57
if (method_exists('PHPUnit_Util_Filter', 'addDirectoryToFilter')) {
68
require_once 'PHPUnit/Framework.php';
@@ -90,8 +92,9 @@ public static function setupBeforeClass($fixtures = 'general/base')
9092
self::$staticSharedFixture['ie']->import($fixtures);
9193
}
9294

93-
// only load session once fixtures have been imported (relevant i.e. for jackalope-doctrine-dbal)
95+
// only load sessions once fixtures have been imported (relevant i.e. for jackalope-doctrine-dbal)
9496
self::$staticSharedFixture['session'] = self::$loader->getSession();
97+
self::$staticSharedFixture['additionalSession'] = self::$loader->getAdditionalSession();
9598
}
9699

97100
protected function setUp()
@@ -212,4 +215,17 @@ protected function assertTraversableImplemented($obj)
212215
{
213216
$this->assertTrue($obj instanceof \Iterator || $obj instanceof \IteratorAggregate, 'To provide Traversable, you have to either implement Iterator or IteratorAggregate');
214217
}
218+
219+
/**
220+
* Check specified property exists, then compare property value to the supplied one using assertEquals.
221+
*
222+
* @param NodeInterface $node
223+
* @param string $property
224+
* @param mixed $value
225+
*/
226+
protected function checkNodeProperty(NodeInterface $node, $property, $value)
227+
{
228+
$this->assertTrue($node->hasProperty($property));
229+
$this->assertEquals($value, $node->getPropertyValue($property));
230+
}
215231
}

0 commit comments

Comments
 (0)