11<?php
22namespace PHPCR \Tests \Writing ;
33
4+ use PHPCR \ItemNotFoundException ;
5+
46require_once (__DIR__ . '/../../inc/BaseCase.php ' );
57
68/**
@@ -26,19 +28,18 @@ public function testRemoveItemNode()
2628 {
2729 //relies on the base class setup trick to have the node populated from the fixtures
2830 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
29- $ session = $ this ->sharedFixture ['session ' ];
3031
3132 $ parent = $ this ->node ->getParent ();
3233 $ this ->assertTrue ($ parent ->hasNode ('testRemoveItemNode ' ));
3334
34- $ session ->removeItem ($ this ->node ->getPath ());
35+ $ this -> session ->removeItem ($ this ->node ->getPath ());
3536
3637 $ 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 ' ));
3839
3940 $ this ->saveAndRenewSession ();
4041
41- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ parent ->getPath ().'/testRemoveItemNode ' ));
42+ $ this ->assertFalse ($ this ->session ->nodeExists ($ parent ->getPath ().'/testRemoveItemNode ' ));
4243 }
4344
4445 /**
@@ -51,7 +52,7 @@ public function testRemoveItemProperty()
5152
5253 $ property = $ this ->node ->getProperty ('longNumber ' );
5354 $ 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 ' );
5556 $ this ->assertFalse ($ this ->node ->hasProperty ('longNumber ' ));
5657 }
5758
@@ -63,8 +64,8 @@ public function testRemoveNodeConstraintViolation()
6364 {
6465 //relies on the base class setup trick to have the node populated from the fixtures
6566 $ 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 ();
6869 }
6970
7071 /**
@@ -73,7 +74,7 @@ public function testRemoveNodeConstraintViolation()
7374 */
7475 public function testRemoveItemNotExisting ()
7576 {
76- $ this ->sharedFixture [ ' session ' ] ->removeItem ('/not/existing ' );
77+ $ this ->session ->removeItem ('/not/existing ' );
7778 }
7879
7980 /**
@@ -93,11 +94,11 @@ public function testRemoveNode()
9394 $ this ->node ->remove ();
9495
9596 $ this ->assertFalse ($ parent ->hasNode ('testRemoveNode ' ));
96- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ path ));
97+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
9798
9899 $ this ->saveAndRenewSession ();
99100
100- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ path ));
101+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
101102 }
102103
103104 public function testRemoveNodeWhitespace ()
@@ -112,7 +113,7 @@ public function testRemoveNodeWhitespace()
112113 $ node ->remove ();
113114 $ this ->saveAndRenewSession ();
114115
115- $ this ->assertFalse ($ this ->sharedFixture [ ' session ' ] ->nodeExists ($ path ));
116+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
116117 }
117118
118119 /**
@@ -125,14 +126,13 @@ public function testRemoveNodeParentState()
125126 //relies on the base class setup trick to have the node populated from the fixtures
126127 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
127128 $ path = $ this ->node ->getPath ().'/parent/child ' ;
128- $ session = $ this ->sharedFixture ['session ' ];
129129
130- $ child = $ session ->getNode ($ path );
130+ $ child = $ this -> session ->getNode ($ path );
131131 $ child ->remove ();
132132
133- $ parent = $ session ->getNode ($ this ->node ->getPath ().'/parent ' );
133+ $ parent = $ this -> session ->getNode ($ this ->node ->getPath ().'/parent ' );
134134 $ this ->assertFalse ($ parent ->hasNode ('child ' ));
135- $ this ->assertFalse ($ session ->nodeExists ($ path ));
135+ $ this ->assertFalse ($ this -> session ->nodeExists ($ path ));
136136
137137 $ session = $ this ->saveAndRenewSession ();
138138
@@ -149,19 +149,19 @@ public function testRemoveNodeFromBackend()
149149 $ nodename = 'toBeDeleted ' ;
150150 if (! $ this ->rootNode ->hasNode ($ nodename )) {
151151 $ this ->rootNode ->addNode ($ nodename , 'nt:unstructured ' );
152- $ this ->sharedFixture [ ' session ' ] ->save ();
152+ $ this ->session ->save ();
153153 $ this ->renewSession ();
154154 }
155155
156- $ node = $ this ->sharedFixture [ ' session ' ] ->getNode ('/toBeDeleted ' );
156+ $ node = $ this ->session ->getNode ('/toBeDeleted ' );
157157
158158 $ node ->remove ();
159- $ this ->sharedFixture [ ' session ' ] ->save ();
159+ $ this ->session ->save ();
160160
161161 $ this ->renewSession ();
162162
163163 $ this ->setExpectedException ('\PHPCR\PathNotFoundException ' );
164- $ this ->sharedFixture [ ' session ' ] ->getNode ('/toBeDeleted ' );
164+ $ this ->session ->getNode ('/toBeDeleted ' );
165165 }
166166
167167 /**
@@ -172,15 +172,15 @@ public function testRemovePropertyFromBackend()
172172 $ this ->rootNode ->setProperty ('toBeDeletedProperty ' , 'TEMP ' );
173173 $ this ->saveAndRenewSession ();
174174
175- $ node = $ this ->sharedFixture [ ' session ' ] ->getNode ('/ ' );
175+ $ node = $ this ->session ->getNode ('/ ' );
176176 $ this ->assertTrue ($ node ->hasProperty ('toBeDeletedProperty ' ), 'Property was not created ' );
177177 $ this ->assertEquals ('TEMP ' , $ node ->getPropertyValue ('toBeDeletedProperty ' ), 'wrong value ' );
178178
179179 $ node ->getProperty ('toBeDeletedProperty ' )->remove ();
180180 $ this ->saveAndRenewSession ();
181181
182182 $ this ->setExpectedException ('\PHPCR\PathNotFoundException ' );
183- $ this ->sharedFixture [ ' session ' ] ->getNode ('/ ' )->getProperty ('toBeDeletedProperty ' );
183+ $ this ->session ->getNode ('/ ' )->getProperty ('toBeDeletedProperty ' );
184184
185185 }
186186
@@ -219,7 +219,7 @@ public function testNodeRemoveProperty()
219219 $ this ->assertTrue ($ this ->node ->hasProperty ('longNumber ' ));
220220 $ this ->node ->setProperty ('longNumber ' , null );
221221 $ 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 ' ));
223223 }
224224
225225 /**
@@ -243,7 +243,7 @@ public function testNodeRemovePropertyConstraintViolation()
243243 //relies on the base class setup trick to have the node populated from the fixtures
244244 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
245245 $ this ->node ->setProperty ('jcr:created ' , null ); //removes the property
246- $ this ->sharedFixture [ ' session ' ] ->save ();
246+ $ this ->session ->save ();
247247 }
248248
249249 /**
@@ -255,7 +255,7 @@ public function testRemovePropertyConstraintViolation()
255255 //relies on the base class setup trick to have the node populated from the fixtures
256256 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
257257 $ this ->node ->setProperty ('jcr:primaryType ' , null ); //removes the property
258- $ this ->sharedFixture [ ' session ' ] ->save ();
258+ $ this ->session ->save ();
259259 }
260260
261261 /**
@@ -270,7 +270,7 @@ public function testGetRemovedNodeSession()
270270
271271 $ path = $ this ->node ->getPath ();
272272 $ this ->node ->remove ();
273- $ this ->sharedFixture [ ' session ' ] ->getNode ($ path );
273+ $ this ->session ->getNode ($ path );
274274 }
275275
276276 /**
@@ -302,7 +302,7 @@ public function testGetRemovedPropertySession()
302302 $ property = $ this ->node ->getProperty ('prop ' );
303303 $ path = $ property ->getPath ();
304304 $ property ->remove ();
305- $ this ->sharedFixture [ ' session ' ] ->getProperty ($ path );
305+ $ this ->session ->getProperty ($ path );
306306 }
307307
308308 /**
@@ -332,7 +332,7 @@ public function testRemoveRemovedNode()
332332
333333 $ path = $ this ->node ->getPath ();
334334 $ this ->node ->remove ();
335- $ this ->sharedFixture [ ' session ' ] ->removeItem ($ path );
335+ $ this ->session ->removeItem ($ path );
336336 }
337337
338338 /**
@@ -357,7 +357,6 @@ public function testDeleteCascade()
357357 //relies on the base class setup trick to have the node populated from the fixtures
358358 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
359359
360- $ session = $ this ->sharedFixture ['session ' ];
361360 $ path = $ this ->node ->getPath ();
362361
363362 $ ptest = $ this ->node ->setProperty ('test ' , 'value ' );
@@ -379,15 +378,15 @@ public function testDeleteCascade()
379378 }
380379 }
381380
382- $ session ->save ();
381+ $ this -> session ->save ();
383382
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 " ));
391390
392391 foreach ($ items as $ item ) {
393392 try {
@@ -410,7 +409,7 @@ public function testDeleteReferencedNodeException()
410409
411410 $ destnode = $ this ->node ->getNode ('idExample ' );
412411 $ destnode ->remove ();
413- $ this ->sharedFixture [ ' session ' ] ->save ();
412+ $ this ->session ->save ();
414413 }
415414
416415 /**
@@ -461,29 +460,54 @@ public function testDeleteNodeAndReusePathWithReference()
461460
462461 // 1. remove the idExample node with UUID cbc172b2-c317-44ac-a73b-1df61c35fb1a
463462 $ referencedNode = $ this ->node ->getNode ('idExample ' );
463+ $ path = $ referencedNode ->getPath ();
464+ $ uuid = $ referencedNode ->getIdentifier ();
465+
466+ $ child = $ referencedNode ->getNode ('idChild ' );
467+ $ childUuid = $ child ->getIdentifier ();
468+
464469 $ 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 ));
465484
466485 // 2. Save the session (without reloading)
467486 $ this ->session ->save ();
487+ $ this ->assertFalse ($ this ->session ->nodeExists ($ path ));
468488
469489 // 3. Recreate the node with a specific UUID
470490 $ referencedNode = $ this ->node ->addNode ('idExample ' );
471- // Add mixin to make it referenceable
472491 $ referencedNode ->addMixin ('mix:referenceable ' );
473- // Change Identifier from the one in the fixtures
474492 $ referencedNode ->setProperty ('jcr:uuid ' , '54378257-ca4d-4b9f-9383-f30dfb280977 ' );
475493
494+ $ child = $ referencedNode ->addNode ('idChild ' );
495+ $ child ->addMixin ('mix:referenceable ' );
496+ $ child ->setProperty ('jcr:uuid ' , 'eee78257-ca4d-4b9f-9383-f30dfb280977 ' );
497+
476498 // Node should be persisted before using it as a reference
477499 $ this ->session ->save ();
478500
479501 // 4. Give the testNode a reference to the new idExample node
480502 $ 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 );
481504
482505 // 5. Throws an PHPCR\ReferentialIntegrityException when above UUID is not a valid reference
483506 $ this ->saveAndRenewSession ();
484507
485508 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
486509 $ 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 ' );
487511 $ this ->assertEquals ('54378257-ca4d-4b9f-9383-f30dfb280977 ' , $ this ->node ->getNode ('idExample ' )->getIdentifier (), 'idExample node should have "54378257-ca4d-4b9f-9383-f30dfb280977" as UUID ' );
488512 }
489513
@@ -492,19 +516,16 @@ public function testWorkspaceDelete()
492516 //relies on the base class setup trick to have the node populated from the fixtures
493517 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
494518
495- /** @var $session \PHPCR\SessionInterface */
496- $ session = $ this ->sharedFixture ['session ' ];
497-
498- $ workspace = $ session ->getWorkspace ();
519+ $ workspace = $ this ->session ->getWorkspace ();
499520 $ path = $ this ->node ->getPath ();
500521
501522 $ property = $ this ->node ->getProperty ('prop ' );
502523 $ workspace ->removeItem ($ path );
503524
504525 // 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 ' ));
508529 try {
509530 $ this ->node ->getPath ();
510531 $ this ->fail ('Node was not notified that it is deleted ' );
@@ -519,25 +540,22 @@ public function testWorkspaceDelete()
519540 }
520541
521542 // 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 ' ));
525546 }
526547
527548 public function testWorkspaceDeleteProperty ()
528549 {
529550 //relies on the base class setup trick to have the node populated from the fixtures
530551 $ this ->assertInstanceOf ('PHPCR\NodeInterface ' , $ this ->node );
531552
532- /** @var $session \PHPCR\SessionInterface */
533- $ session = $ this ->sharedFixture ['session ' ];
534-
535- $ workspace = $ session ->getWorkspace ();
553+ $ workspace = $ this ->session ->getWorkspace ();
536554 $ path = $ this ->node ->getPath ();
537555 $ workspace ->removeItem ("$ path/prop " );
538556
539557 // Session
540- $ this ->assertFalse ($ session ->propertyExists ("$ path/prop " ));
558+ $ this ->assertFalse ($ this -> session ->propertyExists ("$ path/prop " ));
541559
542560 // Backend
543561 $ session = $ this ->saveAndRenewSession ();
@@ -549,8 +567,7 @@ public function testWorkspaceDeleteProperty()
549567 */
550568 public function testWorkspaceDeleteNonExisting ()
551569 {
552- $ session = $ this ->sharedFixture ['session ' ];
553- $ workspace = $ session ->getWorkspace ();
570+ $ workspace = $ this ->session ->getWorkspace ();
554571 $ workspace ->removeItem ('/not/existing ' );
555572 }
556573}
0 commit comments