-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathImportRepositoryContentTest.php
394 lines (324 loc) · 19.1 KB
/
ImportRepositoryContentTest.php
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
namespace PHPCR\Tests\Import;
use PHPCR\ImportUUIDBehaviorInterface;
require_once(__DIR__ . '/../../inc/BaseCase.php');
//6.5 Import Repository Content
class ImportRepositoryContentTest extends \PHPCR\Test\BaseCase
{
public static function setupBeforeClass($fixtures = null)
{
parent::setupBeforeClass($fixtures);
}
/**
* Import to empty repository with various data
*/
public function testImportXMLSystemSession()
{
self::$staticSharedFixture['ie']->import('11_Import/empty');
$session = $this->renewSession();
$this->doTestImportXMLSystem($session, $session);
}
/**
* Import to empty repository with various data
*/
public function testImportXMLSystemWorkspace()
{
self::$staticSharedFixture['ie']->import('11_Import/empty');
$session = $this->renewSession();
$this->doTestImportXMLSystem($session->getWorkspace(), $session);
}
private function doTestImportXMLSystem($connect, $session)
{
$connect->importXML('/', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
$this->assertTrue($session->nodeExists('/tests_general_base'));
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid'));
$uuid = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid');
$this->assertInstanceOf('PHPCR\PropertyInterface', $uuid);
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $uuid->getString());
$ref = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
$session = $this->saveAndRenewSession();
$this->assertTrue($session->nodeExists('/tests_general_base'));
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid'));
$uuid = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid');
$this->assertInstanceOf('PHPCR\PropertyInterface', $uuid);
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $uuid->getString());
$ref = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
}
/**
* @expectedException \PHPCR\PathNotFoundException
*/
public function testImportXMLSystemPathNotFoundSession()
{
$session = $this->sharedFixture['session'];
$session->importXML('/inexistent-path', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
}
/**
* @expectedException \PHPCR\PathNotFoundException
*/
public function testImportXMLSystemPathNotFoundWorkspace()
{
$session = $this->sharedFixture['session'];
$session->getWorkspace()->importXML('/inexistent-path', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
}
/**
* @expectedException \PHPCR\ItemExistsException
*/
public function testImportXMLSystemIdCollisionSession()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$session->importXML('/', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
}
/**
* @expectedException \PHPCR\ItemExistsException
*/
public function testImportXMLSystemIdCollisionWorkspace()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$session->getWorkspace()->importXML('/', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
}
/**
* try to replace the path to which we are importing atm
* @expectedException \PHPCR\NodeType\ConstraintViolationException
*/
public function testImportXMLUuidRemoveParentSession()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$session->importXML('/test/container/idExample', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REMOVE_EXISTING);
}
/**
* try to replace the path to which we are importing atm
* @expectedException \PHPCR\NodeType\ConstraintViolationException
*/
public function testImportXMLUuidRemoveParentWorkspace()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$session->getWorkspace()->importXML('/test/container/idExample', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REMOVE_EXISTING);
}
public function testImportXMLUuidNewSession()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$this->doTestImportXMLUuidNew($session, $session);
}
public function testImportXMLUuidNewWorkspace()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$this->doTestImportXMLUuidNew($session->getWorkspace(), $session);
}
private function doTestImportXMLUuidNew($connect, $session)
{
$connect->importXML('/', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW);
// existing node did not change its uuid
$this->assertTrue($session->nodeExists('/test/container/idExample'));
$idExample = $session->getNode('/test/container/idExample');
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->nodeExists('/tests_general_base'));
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1'));
$ref = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
$session = $this->saveAndRenewSession();
// existing node did not change its uuid
$this->assertTrue($session->nodeExists('/test/container/idExample'));
$idExample = $session->getNode('/test/container/idExample');
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->nodeExists('/tests_general_base'));
// imported node got a new uuid
$this->assertTrue($session->nodeExists('/tests_general_base/idExample'));
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:uuid'));
$newId = $session->getNode('/tests_general_base/idExample');
$this->assertNotEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $newId->getIdentifier());
// reference from input points to existing node
$this->assertTrue($session->propertyExists('/tests_general_base/numberPropertyNode/jcr:content/ref'));
$ref = $session->getProperty('/tests_general_base/numberPropertyNode/jcr:content/ref');
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $ref->getString());
// get the uuid of an imported node that had no collision
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid'));
$uuid = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid');
$this->assertInstanceOf('PHPCR\PropertyInterface', $uuid);
$target = $uuid->getString();
// the reference must still point to that node. the uuid might has changed (implementation detail if non-collision uuid change or not)
$ref = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals($target, $ref->getString());
}
public function testImportXMLUuidRemoveExistingSession()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$this->doTestImportXMLUuidRemoveExisting($session, $session);
}
public function testImportXMLUuidRemoveExistingWorkspace()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$this->doTestImportXMLUuidRemoveExisting($session->getWorkspace(), $session);
}
private function doTestImportXMLUuidRemoveExisting($connect, $session)
{
$connect->importXML('/', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REMOVE_EXISTING);
// existing node removed
$this->assertFalse($session->nodeExists('/test/container/idExample'));
// the rest is the same as with empty repo
$this->assertTrue($session->nodeExists('/tests_general_base'));
$idExample = $session->getNode('/tests_general_base/idExample');
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid'));
$uuid = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid');
$this->assertInstanceOf('PHPCR\PropertyInterface', $uuid);
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $uuid->getString());
$ref = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
$session = $this->saveAndRenewSession();
// existing node removed
$this->assertFalse($session->nodeExists('/test/container/idExample'));
// the rest is the same as with empty repo
$this->assertTrue($session->nodeExists('/tests_general_base'));
$this->assertTrue($session->propertyExists('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid'));
$uuid = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_target/jcr:uuid');
$this->assertInstanceOf('PHPCR\PropertyInterface', $uuid);
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $uuid->getString());
$ref = $session->getProperty('/tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
}
public function testImportXMLUuidReplaceExistingSession()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$this->doTestImportXMLUuidReplaceExisting($session, $session);
}
public function testImportXMLUuidReplaceExistingWorkspace()
{
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$this->doTestImportXMLUuidReplaceExisting($session->getWorkspace(), $session);
}
private function doTestImportXMLUuidReplaceExisting($connect, $session)
{
$session->importXML('/', __DIR__.'/../../fixtures/general/base.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REPLACE_EXISTING);
// existing node replaced
$this->assertTrue($session->nodeExists('/test/container/idExample'));
$idExample = $session->getNode('/test/container/idExample');
$this->assertEquals('nt:file', $idExample->getPrimaryNodeType()->getName());
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->nodeExists('/test/container/idExample/jcr:content'));
$this->assertFalse($session->nodeExists('/tests_general_base/idExample'));
// the rest is the same as with empty repo
$this->assertTrue($session->nodeExists('/tests_general_base'));
$this->assertTrue($session->nodeExists('/tests_general_base/test:namespacedNode'));
$ref = $session->getProperty('/test/container/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
$session = $this->saveAndRenewSession();
// existing node replaced
$this->assertTrue($session->nodeExists('/test/container/idExample'));
$idExample = $session->getNode('/test/container/idExample');
$this->assertEquals('nt:file', $idExample->getPrimaryNodeType()->getName());
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->nodeExists('/test/container/idExample/jcr:content'));
$this->assertFalse($session->nodeExists('/tests_general_base/idExample'));
// the rest is the same as with empty repo
$this->assertTrue($session->nodeExists('/tests_general_base'));
$this->assertTrue($session->nodeExists('/tests_general_base/test:namespacedNode'));
$ref = $session->getProperty('/test/container/idExample/jcr:content/weakreference_source1/ref1');
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $ref->getType());
$this->assertEquals('13543fc6-1abf-4708-bfcc-e49511754b40', $ref->getString());
}
public function testImportXMLUuidReplaceRoot()
{
self::$staticSharedFixture['ie']->import('general/base');
$session = $this->renewSession();
$session->getRootNode()->addMixin('mix:referenceable');
$session = $this->saveAndRenewSession();
$id = $session->getRootNode()->getIdentifier();
$this->assertTrue(\PHPCR\Util\UUIDHelper::isUUID($id));
$filename = tempnam('/tmp', '');
$file = fopen($filename, 'w+');
fwrite($file, str_replace('XXX_ROOT_ID_XXX', $id, file_get_contents(__DIR__.'/../../fixtures/11_Import/rootnode.xml')));
fclose($file);
$session->importXML('/', $filename, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_REPLACE_EXISTING);
$this->assertFalse($session->nodeExists('/jcr:root'));
$this->assertTrue($session->propertyExists('/test'));
$prop = $session->getRootNode()->getProperty('test');
$this->assertEquals('A test string', $prop->getString());
$this->assertTrue($session->nodeExists('/testChild'));
$session = $this->saveAndRenewSession();
$this->assertFalse($session->nodeExists('/jcr:root'));
$this->assertTrue($session->propertyExists('/test'));
$prop = $session->getRootNode()->getProperty('test');
$this->assertEquals('A test string', $prop->getString());
$this->assertTrue($session->nodeExists('/testChild'));
}
/**
* Provoke an io error
*
* @expectedException \RuntimeException
*/
public function testImportXMLNoFile()
{
$session = $this->sharedFixture['session'];
$session->importXML('/', 'nonexisting.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
}
/*
TODO: can we make XMLReader throw exception instead of whatever it does now?
public function testImportXMLNoXml()
{
$session = $this->sharedFixture['session'];
$session->importXML('/', __FILE__, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
}
*/
public function testImportXMLDocument()
{
// TODO: have a node that tests unescaping in the documentview.xml and check
self::$staticSharedFixture['ie']->import('11_Import/idnode');
$session = $this->renewSession();
$session->importXML('/', __DIR__.'/../../fixtures/11_Import/documentview.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW);
// existing node did not change its uuid
$this->assertTrue($session->nodeExists('/test/container/idExample'));
$idExample = $session->getNode('/test/container/idExample');
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->nodeExists('/tests_import'));
$this->assertTrue($session->nodeExists('/tests_import/idExample'));
$id = $session->getNode('/tests_import/idExample');
$this->assertTrue($id->isNodeType('mix:referenceable'));
$this->assertTrue($session->propertyExists('/tests_import/idExample/jcr:content/weakreference_source1/ref1'));
$ref = $session->getProperty('/tests_import/idExample/jcr:content/weakreference_source1/ref1');
$this->assertTrue(\PHPCR\Util\UUIDHelper::isUUID($ref->getString()));
$session = $this->saveAndRenewSession();
// existing node did not change its uuid
$this->assertTrue($session->nodeExists('/test/container/idExample'));
$idExample = $session->getNode('/test/container/idExample');
$this->assertEquals('842e61c0-09ab-42a9-87c0-308ccc90e6f4', $idExample->getIdentifier());
$this->assertTrue($session->nodeExists('/tests_import'));
$this->assertTrue($session->nodeExists('/tests_import/idExample'));
$id = $session->getNode('/tests_import/idExample');
$this->assertTrue($id->isNodeType('mix:referenceable'));
$this->assertTrue($session->propertyExists('/tests_import/idExample/jcr:content/weakreference_source1/ref1'));
$ref = $session->getProperty('/tests_import/idExample/jcr:content/weakreference_source1/ref1');
$this->assertTrue(\PHPCR\Util\UUIDHelper::isUUID($ref->getString()));
}
public function testImportXMLDocumentSimple()
{
self::$staticSharedFixture['ie']->import('11_Import/empty');
$session = $this->renewSession();
$session->importXML('/tests_import', __DIR__.'/../../fixtures/11_Import/simple.xml', ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
$this->assertTrue($session->nodeExists('/tests_import/data/node'));
$this->assertTrue($session->nodeExists('/tests_import/data/sibling/child1'));
$this->assertEquals('Test', $session->getProperty('/tests_import/data/sibling/title')->getValue());
$session = $this->saveAndRenewSession();
$this->assertTrue($session->nodeExists('/tests_import/data/node'));
$this->assertTrue($session->nodeExists('/tests_import/data/sibling/child1'));
$this->assertEquals('Test', $session->getProperty('/tests_import/data/sibling/title')->getValue());
}
}