From 7f4f7593d2daf18a6d9cb01b87a2f921c9567024 Mon Sep 17 00:00:00 2001 From: dantleech <dan.t.leech@gmail.com> Date: Thu, 31 Mar 2016 08:21:10 +0100 Subject: [PATCH] Added test for removing node in other session and refreshing --- fixtures/10_Writing/combinedmanipulations.xml | 18 +++++++ tests/Writing/CombinedManipulationsTest.php | 50 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/fixtures/10_Writing/combinedmanipulations.xml b/fixtures/10_Writing/combinedmanipulations.xml index ee4b8f16..87921ab6 100644 --- a/fixtures/10_Writing/combinedmanipulations.xml +++ b/fixtures/10_Writing/combinedmanipulations.xml @@ -263,6 +263,24 @@ </sv:node> </sv:node> + <sv:node sv:name="testRemoveNewNodeInOtherSessionDiscardChanges"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>nt:unstructured</sv:value> + </sv:property> + </sv:node> + + <sv:node sv:name="testRemoveNewNodeInOtherSessionKeepChanges"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>nt:unstructured</sv:value> + </sv:property> + </sv:node> + + <sv:node sv:name="testRemoveNodeInOtherSessionKeepChangeg"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>nt:unstructured</sv:value> + </sv:property> + </sv:node> + <sv:node sv:name="testMoveSessionRefresh"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>nt:unstructured</sv:value> diff --git a/tests/Writing/CombinedManipulationsTest.php b/tests/Writing/CombinedManipulationsTest.php index 9d482b40..9b3e22e4 100644 --- a/tests/Writing/CombinedManipulationsTest.php +++ b/tests/Writing/CombinedManipulationsTest.php @@ -618,6 +618,56 @@ public function testRemoveOtherSessionRefreshKeepChanges() $this->assertEquals('Value', $node->getPropertyValue('newprop')); } + /** + * It should throw an exception when accessing a property of a node created + * and persisted earlier in the session, but which has since been deleted + * by a different session. (refresh should not throw an exception). + */ + public function testRemoveNewNodeInOtherSessionDiscardChanges() + { + $this->setExpectedException( + 'PHPCR\PathNotFoundException', + 'Property bar' + ); + + $node = $this->node; + $fooNode = $node->addNode('foo'); + $fooNode->setProperty('bar', 'boo'); + $this->session->save(); + + $othersession = self::$loader->getSession(); + $othersession->getNode($node->getPath())->remove(); + $othersession->save(); + + $this->session->refresh(false); + + $fooNode->getProperty('bar'); + } + + /** + * Same as above but keep changes when refreshing -- what should happen here? + * + * Currently jackalope-doctrine-dbal throws: + * + * PHPCR\RepositoryException: + * Setting item /tests_write_combined_manipulation/testRemoveNewNodeInOtherSessionDiscardChanges/foo dirty in state 4 is not expected + */ + public function testRemoveNewNodeInOtherSessionKeepChanges() + { + $node = $this->node; + $fooNode = $node->addNode('foo'); + $fooNode->setProperty('bar', 'boo'); + $this->session->save(); + + $othersession = self::$loader->getSession(); + $othersession->getNode($node->getPath())->remove(); + $othersession->save(); + + $this->session->refresh(true); + + $fooNode->getProperty('bar'); + } + public function testMoveSessionRefresh() { $node = $this->node;