1
1
<?php
2
2
namespace PHPCR \Tests \Writing ;
3
3
4
+ use PHPCR \ItemNotFoundException ;
5
+
4
6
require_once (__DIR__ . '/../../inc/BaseCase.php ' );
5
7
6
8
/**
@@ -26,19 +28,18 @@ public function testRemoveItemNode()
26
28
{
27
29
//relies on the base class setup trick to have the node populated from the fixtures
28
30
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
29
- $ session = $ this ->sharedFixture ['session ' ];
30
31
31
32
$ parent = $ this ->node ->getParent ();
32
33
$ this ->assertTrue ($ parent ->hasNode ('testRemoveItemNode ' ));
33
34
34
- $ session ->removeItem ($ this ->node ->getPath ());
35
+ $ this -> session ->removeItem ($ this ->node ->getPath ());
35
36
36
37
$ this ->assertFalse ($ parent ->hasNode ('testRemoveItemNode ' ), 'Node was not removed ' );
37
- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ parent ->getPath ().'/testRemoveItemNode ' ));
38
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ parent ->getPath ().'/testRemoveItemNode ' ));
38
39
39
40
$ this ->saveAndRenewSession ();
40
41
41
- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ parent ->getPath ().'/testRemoveItemNode ' ));
42
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ parent ->getPath ().'/testRemoveItemNode ' ));
42
43
}
43
44
44
45
/**
@@ -51,7 +52,7 @@ public function testRemoveItemProperty()
51
52
52
53
$ property = $ this ->node ->getProperty ('longNumber ' );
53
54
$ this ->assertTrue ($ this ->node ->hasProperty ('longNumber ' ));
54
- $ this ->sharedFixture [ ' session ' ] ->removeItem ('/tests_write_manipulation_delete/testRemoveItemProperty/longNumber ' );
55
+ $ this ->session ->removeItem ('/tests_write_manipulation_delete/testRemoveItemProperty/longNumber ' );
55
56
$ this ->assertFalse ($ this ->node ->hasProperty ('longNumber ' ));
56
57
}
57
58
@@ -63,8 +64,8 @@ public function testRemoveNodeConstraintViolation()
63
64
{
64
65
//relies on the base class setup trick to have the node populated from the fixtures
65
66
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
66
- $ this ->sharedFixture [ ' session ' ] ->removeItem ('/tests_write_manipulation_delete/testRemoveNodeConstraintViolation/jcr:content ' );
67
- $ this ->sharedFixture [ ' session ' ] ->save ();
67
+ $ this ->session ->removeItem ('/tests_write_manipulation_delete/testRemoveNodeConstraintViolation/jcr:content ' );
68
+ $ this ->session ->save ();
68
69
}
69
70
70
71
/**
@@ -73,7 +74,7 @@ public function testRemoveNodeConstraintViolation()
73
74
*/
74
75
public function testRemoveItemNotExisting ()
75
76
{
76
- $ this ->sharedFixture [ ' session ' ] ->removeItem ('/not/existing ' );
77
+ $ this ->session ->removeItem ('/not/existing ' );
77
78
}
78
79
79
80
/**
@@ -93,11 +94,11 @@ public function testRemoveNode()
93
94
$ this ->node ->remove ();
94
95
95
96
$ this ->assertFalse ($ parent ->hasNode ('testRemoveNode ' ));
96
- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ path ));
97
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
97
98
98
99
$ this ->saveAndRenewSession ();
99
100
100
- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ path ));
101
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
101
102
}
102
103
103
104
public function testRemoveNodeWhitespace ()
@@ -112,7 +113,7 @@ public function testRemoveNodeWhitespace()
112
113
$ node ->remove ();
113
114
$ this ->saveAndRenewSession ();
114
115
115
- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ path ));
116
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
116
117
}
117
118
118
119
/**
@@ -125,14 +126,13 @@ public function testRemoveNodeParentState()
125
126
//relies on the base class setup trick to have the node populated from the fixtures
126
127
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
127
128
$ path = $ this ->node ->getPath ().'/parent/child ' ;
128
- $ session = $ this ->sharedFixture ['session ' ];
129
129
130
- $ child = $ session ->getNode ($ path );
130
+ $ child = $ this -> session ->getNode ($ path );
131
131
$ child ->remove ();
132
132
133
- $ parent = $ session ->getNode ($ this ->node ->getPath ().'/parent ' );
133
+ $ parent = $ this -> session ->getNode ($ this ->node ->getPath ().'/parent ' );
134
134
$ this ->assertFalse ($ parent ->hasNode ('child ' ));
135
- $ this ->assertFalse ($ session ->nodeExists ($ path ));
135
+ $ this ->assertFalse ($ this -> session ->nodeExists ($ path ));
136
136
137
137
$ session = $ this ->saveAndRenewSession ();
138
138
@@ -149,19 +149,19 @@ public function testRemoveNodeFromBackend()
149
149
$ nodename = 'toBeDeleted ' ;
150
150
if (! $ this ->rootNode ->hasNode ($ nodename )) {
151
151
$ this ->rootNode ->addNode ($ nodename , 'nt:unstructured ' );
152
- $ this ->sharedFixture [ ' session ' ] ->save ();
152
+ $ this ->session ->save ();
153
153
$ this ->renewSession ();
154
154
}
155
155
156
- $ node = $ this ->sharedFixture [ ' session ' ] ->getNode ('/toBeDeleted ' );
156
+ $ node = $ this ->session ->getNode ('/toBeDeleted ' );
157
157
158
158
$ node ->remove ();
159
- $ this ->sharedFixture [ ' session ' ] ->save ();
159
+ $ this ->session ->save ();
160
160
161
161
$ this ->renewSession ();
162
162
163
163
$ this ->setExpectedException ('\PHPCR\PathNotFoundException ' );
164
- $ this ->sharedFixture [ ' session ' ] ->getNode ('/toBeDeleted ' );
164
+ $ this ->session ->getNode ('/toBeDeleted ' );
165
165
}
166
166
167
167
/**
@@ -172,15 +172,15 @@ public function testRemovePropertyFromBackend()
172
172
$ this ->rootNode ->setProperty ('toBeDeletedProperty ' , 'TEMP ' );
173
173
$ this ->saveAndRenewSession ();
174
174
175
- $ node = $ this ->sharedFixture [ ' session ' ] ->getNode ('/ ' );
175
+ $ node = $ this ->session ->getNode ('/ ' );
176
176
$ this ->assertTrue ($ node ->hasProperty ('toBeDeletedProperty ' ), 'Property was not created ' );
177
177
$ this ->assertEquals ('TEMP ' , $ node ->getPropertyValue ('toBeDeletedProperty ' ), 'wrong value ' );
178
178
179
179
$ node ->getProperty ('toBeDeletedProperty ' )->remove ();
180
180
$ this ->saveAndRenewSession ();
181
181
182
182
$ this ->setExpectedException ('\PHPCR\PathNotFoundException ' );
183
- $ this ->sharedFixture [ ' session ' ] ->getNode ('/ ' )->getProperty ('toBeDeletedProperty ' );
183
+ $ this ->session ->getNode ('/ ' )->getProperty ('toBeDeletedProperty ' );
184
184
185
185
}
186
186
@@ -219,7 +219,7 @@ public function testNodeRemoveProperty()
219
219
$ this ->assertTrue ($ this ->node ->hasProperty ('longNumber ' ));
220
220
$ this ->node ->setProperty ('longNumber ' , null );
221
221
$ this ->assertFalse ($ this ->node ->hasProperty ('longNumber ' ));
222
- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->itemExists ('/tests_write_manipulation_delete/testNodeRemobeProperty/longNumber ' ));
222
+ $ this ->assertFalse ($ this ->session ->itemExists ('/tests_write_manipulation_delete/testNodeRemobeProperty/longNumber ' ));
223
223
}
224
224
225
225
/**
@@ -243,7 +243,7 @@ public function testNodeRemovePropertyConstraintViolation()
243
243
//relies on the base class setup trick to have the node populated from the fixtures
244
244
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
245
245
$ this ->node ->setProperty ('jcr:created ' , null ); //removes the property
246
- $ this ->sharedFixture [ ' session ' ] ->save ();
246
+ $ this ->session ->save ();
247
247
}
248
248
249
249
/**
@@ -255,7 +255,7 @@ public function testRemovePropertyConstraintViolation()
255
255
//relies on the base class setup trick to have the node populated from the fixtures
256
256
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
257
257
$ this ->node ->setProperty ('jcr:primaryType ' , null ); //removes the property
258
- $ this ->sharedFixture [ ' session ' ] ->save ();
258
+ $ this ->session ->save ();
259
259
}
260
260
261
261
/**
@@ -270,7 +270,7 @@ public function testGetRemovedNodeSession()
270
270
271
271
$ path = $ this ->node ->getPath ();
272
272
$ this ->node ->remove ();
273
- $ this ->sharedFixture [ ' session ' ] ->getNode ($ path );
273
+ $ this ->session ->getNode ($ path );
274
274
}
275
275
276
276
/**
@@ -302,7 +302,7 @@ public function testGetRemovedPropertySession()
302
302
$ property = $ this ->node ->getProperty ('prop ' );
303
303
$ path = $ property ->getPath ();
304
304
$ property ->remove ();
305
- $ this ->sharedFixture [ ' session ' ] ->getProperty ($ path );
305
+ $ this ->session ->getProperty ($ path );
306
306
}
307
307
308
308
/**
@@ -332,7 +332,7 @@ public function testRemoveRemovedNode()
332
332
333
333
$ path = $ this ->node ->getPath ();
334
334
$ this ->node ->remove ();
335
- $ this ->sharedFixture [ ' session ' ] ->removeItem ($ path );
335
+ $ this ->session ->removeItem ($ path );
336
336
}
337
337
338
338
/**
@@ -357,7 +357,6 @@ public function testDeleteCascade()
357
357
//relies on the base class setup trick to have the node populated from the fixtures
358
358
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
359
359
360
- $ session = $ this ->sharedFixture ['session ' ];
361
360
$ path = $ this ->node ->getPath ();
362
361
363
362
$ ptest = $ this ->node ->setProperty ('test ' , 'value ' );
@@ -379,15 +378,15 @@ public function testDeleteCascade()
379
378
}
380
379
}
381
380
382
- $ session ->save ();
381
+ $ this -> session ->save ();
383
382
384
- $ this ->assertFalse ($ session ->nodeExists ("$ path/prop " ));
385
- $ this ->assertFalse ($ session ->nodeExists ("$ path/test " ));
386
- $ this ->assertFalse ($ session ->nodeExists ("$ path/child " ));
387
- $ this ->assertFalse ($ session ->nodeExists ("$ path/child/child " ));
388
- $ this ->assertFalse ($ session ->propertyExists ("$ path/prop " ));
389
- $ this ->assertFalse ($ session ->propertyExists ("$ path/child/prop " ));
390
- $ this ->assertFalse ($ session ->propertyExists ("$ path/child/child/prop " ));
383
+ $ this ->assertFalse ($ this -> session ->nodeExists ("$ path/prop " ));
384
+ $ this ->assertFalse ($ this -> session ->nodeExists ("$ path/test " ));
385
+ $ this ->assertFalse ($ this -> session ->nodeExists ("$ path/child " ));
386
+ $ this ->assertFalse ($ this -> session ->nodeExists ("$ path/child/child " ));
387
+ $ this ->assertFalse ($ this -> session ->propertyExists ("$ path/prop " ));
388
+ $ this ->assertFalse ($ this -> session ->propertyExists ("$ path/child/prop " ));
389
+ $ this ->assertFalse ($ this -> session ->propertyExists ("$ path/child/child/prop " ));
391
390
392
391
foreach ($ items as $ item ) {
393
392
try {
@@ -410,7 +409,7 @@ public function testDeleteReferencedNodeException()
410
409
411
410
$ destnode = $ this ->node ->getNode ('idExample ' );
412
411
$ destnode ->remove ();
413
- $ this ->sharedFixture [ ' session ' ] ->save ();
412
+ $ this ->session ->save ();
414
413
}
415
414
416
415
/**
@@ -461,29 +460,54 @@ public function testDeleteNodeAndReusePathWithReference()
461
460
462
461
// 1. remove the idExample node with UUID cbc172b2-c317-44ac-a73b-1df61c35fb1a
463
462
$ referencedNode = $ this ->node ->getNode ('idExample ' );
463
+ $ path = $ referencedNode ->getPath ();
464
+ $ uuid = $ referencedNode ->getIdentifier ();
465
+
466
+ $ child = $ referencedNode ->getNode ('idChild ' );
467
+ $ childUuid = $ child ->getIdentifier ();
468
+
464
469
$ referencedNode ->remove ();
470
+ try {
471
+ $ this ->session ->getNodeByIdentifier ($ uuid );
472
+ $ this ->fail ('Removed node was still found ' );
473
+ } catch (ItemNotFoundException $ e ) {
474
+ // expected
475
+ }
476
+ try {
477
+ $ this ->session ->getNodeByIdentifier ($ childUuid );
478
+ $ this ->fail ('Removed child node was still found ' );
479
+ } catch (ItemNotFoundException $ e ) {
480
+ // expected
481
+ }
482
+
483
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
465
484
466
485
// 2. Save the session (without reloading)
467
486
$ this ->session ->save ();
487
+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
468
488
469
489
// 3. Recreate the node with a specific UUID
470
490
$ referencedNode = $ this ->node ->addNode ('idExample ' );
471
- // Add mixin to make it referenceable
472
491
$ referencedNode ->addMixin ('mix:referenceable ' );
473
- // Change Identifier from the one in the fixtures
474
492
$ referencedNode ->setProperty ('jcr:uuid ' , '54378257-ca4d-4b9f-9383-f30dfb280977 ' );
475
493
494
+ $ child = $ referencedNode ->addNode ('idChild ' );
495
+ $ child ->addMixin ('mix:referenceable ' );
496
+ $ child ->setProperty ('jcr:uuid ' , 'eee78257-ca4d-4b9f-9383-f30dfb280977 ' );
497
+
476
498
// Node should be persisted before using it as a reference
477
499
$ this ->session ->save ();
478
500
479
501
// 4. Give the testNode a reference to the new idExample node
480
502
$ this ->node ->setProperty ('reference ' , '54378257-ca4d-4b9f-9383-f30dfb280977 ' , \PHPCR \PropertyType::REFERENCE );
503
+ $ this ->node ->setProperty ('referenceChild ' , 'eee78257-ca4d-4b9f-9383-f30dfb280977 ' , \PHPCR \PropertyType::REFERENCE );
481
504
482
505
// 5. Throws an PHPCR\ReferentialIntegrityException when above UUID is not a valid reference
483
506
$ this ->saveAndRenewSession ();
484
507
485
508
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
486
509
$ this ->assertEquals ('54378257-ca4d-4b9f-9383-f30dfb280977 ' , $ this ->node ->getProperty ('reference ' )->getString (), 'Reference property should contain "54378257-ca4d-4b9f-9383-f30dfb280977" as string value ' );
510
+ $ this ->assertEquals ('eee78257-ca4d-4b9f-9383-f30dfb280977 ' , $ this ->node ->getProperty ('referenceChild ' )->getString (), 'Reference property should contain "eee78257-ca4d-4b9f-9383-f30dfb280977" as string value ' );
487
511
$ this ->assertEquals ('54378257-ca4d-4b9f-9383-f30dfb280977 ' , $ this ->node ->getNode ('idExample ' )->getIdentifier (), 'idExample node should have "54378257-ca4d-4b9f-9383-f30dfb280977" as UUID ' );
488
512
}
489
513
@@ -492,19 +516,16 @@ public function testWorkspaceDelete()
492
516
//relies on the base class setup trick to have the node populated from the fixtures
493
517
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
494
518
495
- /** @var $session \PHPCR\SessionInterface */
496
- $ session = $ this ->sharedFixture ['session ' ];
497
-
498
- $ workspace = $ session ->getWorkspace ();
519
+ $ workspace = $ this ->session ->getWorkspace ();
499
520
$ path = $ this ->node ->getPath ();
500
521
501
522
$ property = $ this ->node ->getProperty ('prop ' );
502
523
$ workspace ->removeItem ($ path );
503
524
504
525
// Session
505
- $ this ->assertFalse ($ session ->nodeExists ($ path ));
506
- $ this ->assertFalse ($ session ->nodeExists ($ path .'/child ' ));
507
- $ this ->assertFalse ($ session ->propertyExists ($ path .'/child/prop ' ));
526
+ $ this ->assertFalse ($ this -> session ->nodeExists ($ path ));
527
+ $ this ->assertFalse ($ this -> session ->nodeExists ($ path .'/child ' ));
528
+ $ this ->assertFalse ($ this -> session ->propertyExists ($ path .'/child/prop ' ));
508
529
try {
509
530
$ this ->node ->getPath ();
510
531
$ this ->fail ('Node was not notified that it is deleted ' );
@@ -519,25 +540,22 @@ public function testWorkspaceDelete()
519
540
}
520
541
521
542
// Backend
522
- $ session = $ this ->saveAndRenewSession ();
523
- $ this ->assertFalse ($ session ->nodeExists ($ path ));
524
- $ this ->assertFalse ($ session ->nodeExists ($ path .'/child ' ));
543
+ $ this -> session = $ this ->saveAndRenewSession ();
544
+ $ this ->assertFalse ($ this -> session ->nodeExists ($ path ));
545
+ $ this ->assertFalse ($ this -> session ->nodeExists ($ path .'/child ' ));
525
546
}
526
547
527
548
public function testWorkspaceDeleteProperty ()
528
549
{
529
550
//relies on the base class setup trick to have the node populated from the fixtures
530
551
$ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
531
552
532
- /** @var $session \PHPCR\SessionInterface */
533
- $ session = $ this ->sharedFixture ['session ' ];
534
-
535
- $ workspace = $ session ->getWorkspace ();
553
+ $ workspace = $ this ->session ->getWorkspace ();
536
554
$ path = $ this ->node ->getPath ();
537
555
$ workspace ->removeItem ("$ path/prop " );
538
556
539
557
// Session
540
- $ this ->assertFalse ($ session ->propertyExists ("$ path/prop " ));
558
+ $ this ->assertFalse ($ this -> session ->propertyExists ("$ path/prop " ));
541
559
542
560
// Backend
543
561
$ session = $ this ->saveAndRenewSession ();
@@ -549,8 +567,7 @@ public function testWorkspaceDeleteProperty()
549
567
*/
550
568
public function testWorkspaceDeleteNonExisting ()
551
569
{
552
- $ session = $ this ->sharedFixture ['session ' ];
553
- $ workspace = $ session ->getWorkspace ();
570
+ $ workspace = $ this ->session ->getWorkspace ();
554
571
$ workspace ->removeItem ('/not/existing ' );
555
572
}
556
573
}
0 commit comments