-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCopyMethodsTest.php
More file actions
303 lines (237 loc) · 10.9 KB
/
Copy pathCopyMethodsTest.php
File metadata and controls
303 lines (237 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
/*
* This file is part of the PHPCR API Tests package
*
* Copyright (c) 2015 Liip and others
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPCR\Tests\Writing;
use PHPCR\WorkspaceInterface;
/**
* Covering jcr-283 spec $10.7.
*/
class CopyMethodsTest extends \PHPCR\Test\BaseCase
{
/** @var WorkspaceInterface */
protected $ws;
public static function setupBeforeClass($fixtures = '10_Writing/copy')
{
parent::setupBeforeClass($fixtures);
}
protected function setUp()
{
$this->renewSession(); // get rid of cache from previous tests
parent::setUp();
$this->ws = $this->session->getWorkspace();
}
public function testWorkspaceCopy()
{
$src = '/tests_write_manipulation_copy/testWorkspaceCopy/srcNode';
$dst = '/tests_write_manipulation_copy/testWorkspaceCopy/dstNode/srcNode';
$this->ws->copy($src, $dst);
$snode = $this->session->getNode($src);
$dnode = $this->session->getNode($dst);
$this->assertNotEquals($snode->getIdentifier(), $dnode->getIdentifier());
$schild = $this->session->getNode("$src/srcFile");
$dchild = $this->session->getNode("$dst/srcFile");
$this->assertNotEquals($schild->getIdentifier(), $dchild->getIdentifier());
// do not save, workspace should do directly
$this->renewSession();
$this->assertTrue($this->session->nodeExists($dst));
$snode = $this->session->getNode($src);
$dnode = $this->session->getNode($dst);
$this->assertNotEquals($snode->getIdentifier(), $dnode->getIdentifier(), 'UUID was not changed');
$schild = $this->session->getNode("$src/srcFile");
$dchild = $this->session->getNode("$dst/srcFile");
$this->assertNotEquals($schild->getIdentifier(), $dchild->getIdentifier());
$this->assertTrue($this->session->nodeExists($dst.'/srcFile/jcr:content'), 'Did not copy the whole subgraph');
$sfile = $this->session->getNode("$src/srcFile/jcr:content");
$dfile = $this->session->getNode("$dst/srcFile/jcr:content");
$this->assertEquals($sfile->getPropertyValue('jcr:data'), $dfile->getPropertyValue('jcr:data'));
$dfile->setProperty('jcr:data', 'changed content');
$this->assertNotEquals($sfile->getPropertyValue('jcr:data'), $dfile->getPropertyValue('jcr:data'));
$this->session->save();
$this->saveAndRenewSession();
$sfile = $this->session->getNode("$src/srcFile/jcr:content");
$dfile = $this->session->getNode("$dst/srcFile/jcr:content");
$this->assertNotEquals($sfile->getPropertyValue('jcr:data'), $dfile->getPropertyValue('jcr:data'));
}
public function testWorkspaceCopyReference()
{
$src = '/tests_write_manipulation_copy/testWorkspaceCopy/referencedNodeSet';
$dst = '/tests_write_manipulation_copy/testWorkspaceCopy/dstNode/copiedReferencedSet';
$this->ws->copy($src, $dst);
$snode = $this->session->getNode($src);
$dnode = $this->session->getNode($dst);
$this->assertNotEquals($snode->getIdentifier(), $dnode->getIdentifier());
$homeNode = $dnode->getNode('home');
$block1Ref = $homeNode->getProperty('block_1_ref')->getValue()->getIdentifier();
$block2Ref = $homeNode->getProperty('block_2_ref')->getValue()->getIdentifier();
$block3Ref = $homeNode->getProperty('block_2_ref')->getValue()->getIdentifier();
$externalRef = $homeNode->getProperty('external_reference')->getValue()->getIdentifier();
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f6', $externalRef);
$block1 = $homeNode->getNode('block_1');
$this->assertEquals($block1->getIdentifier(), $block1Ref);
$block2 = $block1->getNode('block_2');
$this->assertEquals($block2->getIdentifier(), $block2Ref);
// weak reference
$block3 = $block1->getNode('block_3');
$this->assertEquals($block2->getIdentifier(), $block2Ref);
}
public function testWorkspaceCopyOther()
{
self::$staticSharedFixture['ie']->import('general/additionalWorkspace', 'additionalWorkspace');
$src = '/tests_additional_workspace/testWorkspaceCopyOther/node';
$dst = '/tests_write_manipulation_copy/testWorkspaceCopyOther/foobar';
$this->ws->copy($src, $dst, self::$loader->getOtherWorkspaceName());
$node = $this->session->getNode($dst);
$this->assertTrue($node->hasProperty('x'));
$this->assertEquals('y', $node->getPropertyValue('x'));
}
/**
* @expectedException \PHPCR\NoSuchWorkspaceException
*/
public function testCopyNoSuchWorkspace()
{
$src = '/somewhere/foo';
$dst = '/here/foo';
$this->ws->copy($src, $dst, 'inexistentworkspace');
}
/**
* @expectedException \PHPCR\RepositoryException
*/
public function testCopyRelativePaths()
{
$this->ws->copy('foo/moo', 'bar/mar');
}
/**
* @expectedException \PHPCR\RepositoryException
*/
public function testCopyInvalidDstPath()
{
$src = '/tests_write_manipulation_copy/testCopyInvalidDstPath/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyInvalidDstPath/dstNode/srcNode[3]';
$this->ws->copy($src, $dst);
}
/**
* @expectedException \PHPCR\RepositoryException
*/
public function testCopyProperty()
{
$src = '/tests_write_manipulation_copy/testCopyProperty/srcFile/jcr:content/someProperty';
$dst = '/tests_write_manipulation_copy/testCopyProperty/dstFile/jcr:content/someProperty';
$this->ws->copy($src, $dst);
}
/**
* @expectedException \PHPCR\PathNotFoundException
*/
public function testCopySrcNotFound()
{
$src = '/tests_write_manipulation_copy/testCopySrcNotFound/notFound';
$dst = '/tests_write_manipulation_copy/testCopySrcNotFound/dstNode/notFound';
$this->ws->copy($src, $dst);
}
/**
* @expectedException \PHPCR\PathNotFoundException
*/
public function testCopyDstParentNotFound()
{
$src = '/tests_write_manipulation_copy/testCopyDstParentNotFound/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyDstParentNotFound/dstNode/notFound/srcNode';
$this->ws->copy($src, $dst);
}
/**
* Verifies that there is no update-on-copy if the target node already exists.
*
* @expectedException \PHPCR\ItemExistsException
*/
public function testCopyNoUpdateOnCopy()
{
$src = '/tests_write_manipulation_copy/testCopyNoUpdateOnCopy/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyNoUpdateOnCopy/dstNode/srcNode';
$this->ws->copy($src, $dst);
}
/**
* 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/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);
$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);
}
/**
* Verifies that transport::copy actually copies binary data of children nodes
*/
public function testCopyChildrenBinaryData()
{
$src = '/tests_write_manipulation_copy/testCopyChildrenBinaryData/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyChildrenBinaryData/dstNode';
$this->ws->copy($src, $dst);
$this->session->refresh(true);
//Single value
$srcProp = $this->session->getNode($src . '/single')->getProperty('jcr:data');
$dstProp = $this->session->getNode($dst . '/single')->getProperty('jcr:data');
$this->assertEquals(\PHPCR\PropertyType::BINARY, $srcProp->getType());
$this->assertEquals(\PHPCR\PropertyType::BINARY, $dstProp->getType());
$srcVal = $srcProp->getBinary();
$dstVal = $dstProp->getBinary();
$this->assertTrue(is_resource($srcVal), 'Failed to get src binary stream');
$this->assertTrue(is_resource($dstVal), 'Failed to get dst binary stream');
$this->assertEquals(stream_get_contents($srcVal), stream_get_contents($dstVal));
}
/**
* Verifies that transport::copy actually copies binary data of children nodes
* Multivalue test
*/
public function testCopyChildrenBinaryDataMultivalue()
{
$src = '/tests_write_manipulation_copy/testCopyChildrenBinaryDataMultivalue/srcNode';
$dst = '/tests_write_manipulation_copy/testCopyChildrenBinaryDataMultivalue/dstNode';
$this->ws->copy($src, $dst);
$this->session->refresh(true);
//Multivalue
$srcProp = $this->session->getNode($src.'/multiple')->getProperty('jcr:data');
$dstProp = $this->session->getNode($dst.'/multiple')->getProperty('jcr:data');
$this->assertEquals(\PHPCR\PropertyType::BINARY, $srcProp->getType());
$this->assertEquals(\PHPCR\PropertyType::BINARY, $dstProp->getType());
$srcVal = $srcProp->getValue();
$dstVal = $dstProp->getValue();
$this->assertTrue(is_array($srcVal), 'Failed to get src value');
$this->assertTrue(is_array($dstVal), 'Failed to get dst value');
$this->assertTrue(is_resource($srcVal[0]));
$this->assertTrue(is_resource($srcVal[1]));
$this->assertTrue(is_resource($dstVal[0]));
$this->assertTrue(is_resource($dstVal[1]));
$this->assertEquals(stream_get_contents($srcVal[0]), stream_get_contents($dstVal[0]));
$this->assertEquals(stream_get_contents($srcVal[1]), stream_get_contents($dstVal[1]));
}
}