@@ -27,6 +27,7 @@ class FeatureContext extends BehatContext
2727 protected $ applicationTester ;
2828 protected $ filesystem ;
2929 protected $ workingDir ;
30+ protected $ currentWorkspaceName = 'default ' ;
3031
3132 /**
3233 * Initializes context.
@@ -45,8 +46,7 @@ public function beforeScenario()
4546 chdir ($ this ->workingDir );
4647 $ this ->filesystem = new Filesystem ();
4748
48- $ session = $ this ->getSession ();
49- $ session ->save ();
49+ $ session = $ this ->getSession (null , true );
5050
5151 $ this ->applicationTester = new ApplicationTester ($ this ->application );
5252 $ this ->applicationTester ->run (array (
@@ -69,12 +69,17 @@ public static function cleanTestFolders()
6969 $ fs ->remove (sys_get_temp_dir () . DIRECTORY_SEPARATOR . 'phpcr-shell ' );
7070 }
7171
72- private function getSession ($ workspaceName = ' default ' )
72+ private function getSession ($ workspaceName = null , $ force = false )
7373 {
74- static $ session = array ();
74+ if ($ workspaceName === null ) {
75+ $ workspaceName = $ this ->currentWorkspaceName ;
76+ }
77+
78+ static $ sessions = array ();
7579
76- if (isset ($ session [$ workspaceName ])) {
77- return $ session [$ workspaceName ];
80+ if (false === $ force && isset ($ sessions [$ workspaceName ])) {
81+ $ session = $ sessions [$ workspaceName ];
82+ return $ session ;
7883 }
7984
8085 $ params = array (
@@ -85,9 +90,9 @@ private function getSession($workspaceName = 'default')
8590 $ repository = $ factory ->getRepository ($ params );
8691 $ credentials = new SimpleCredentials ('admin ' , 'admin ' );
8792
88- $ session [$ workspaceName ] = $ repository ->login ($ credentials , $ workspaceName );
93+ $ sessions [$ workspaceName ] = $ repository ->login ($ credentials , $ workspaceName );
8994
90- return $ session [$ workspaceName ];
95+ return $ sessions [$ workspaceName ];
9196 }
9297
9398 private function getOutput ()
@@ -413,7 +418,7 @@ public function theNodeAtShouldNotHaveTheMixin($arg1, $arg2)
413418 */
414419 public function thereShouldNotExistANodeAt ($ arg1 )
415420 {
416- $ session = $ this ->getSession ();
421+ $ session = $ this ->getSession (null , true );
417422
418423 try {
419424 $ session ->getNode ($ arg1 );
@@ -532,13 +537,13 @@ public function thereShouldNotExistAWorkspaceCalled($arg1)
532537 }
533538
534539 /**
535- * @Given /^the "([^"]*)" fixtures are loaded into a workspace "([^"]*)"$/
540+ * @Given /^the "([^"]*)" fixtures are loaded into workspace "([^"]*)"$/
536541 */
537- public function theFixturesAreLoadedIntoAWorkspace ($ arg1 , $ arg2 )
542+ public function theFixturesAreLoadedIntoWorkspace ($ arg1 , $ arg2 )
538543 {
539- $ this ->thereExistsAWorkspace ($ arg2 );
544+ $ this ->theCurrentWorkspaceIs ($ arg2 );
540545 $ fixtureFile = $ this ->getFixtureFilename ($ arg1 );
541- $ session = $ this ->getSession ($ arg2 );
546+ $ session = $ this ->getSession ();
542547 NodeHelper::purgeWorkspace ($ session );
543548 $ session ->save ();
544549 $ session ->importXml ('/ ' , $ fixtureFile , 0 );
@@ -556,7 +561,6 @@ public function theNodeTypeIsLoaded($arg1)
556561 $ workspace = $ session ->getWorkspace ();
557562 $ nodeTypeManager = $ workspace ->getNodeTypeManager ();
558563 $ nodeTypeManager ->registerNodeTypesCnd ($ cnd , true );
559- $ session ->save ();
560564 }
561565
562566 /**
@@ -614,6 +618,33 @@ public function theCurrentNodeIs($arg1)
614618 $ this ->executeCommand (sprintf ('cd %s ' , $ arg1 ));
615619 }
616620
621+ /**
622+ * @Given /^the current workspace is "([^"]*)"$/
623+ */
624+ public function theCurrentWorkspaceIs ($ arg1 )
625+ {
626+ $ this ->thereExistsAWorkspace ($ arg1 );
627+ $ this ->currentWorkspaceName = $ arg1 ;
628+ }
629+
630+ /**
631+ * @Given /^the current workspace is empty/
632+ */
633+ public function theCurrentWorkspaceIsEmpty ()
634+ {
635+ $ session = $ this ->getSession ();
636+ NodeHelper::purgeWorkspace ($ session );
637+ $ session ->save ();
638+ }
639+
640+ /**
641+ * @Given /^I refresh the session/
642+ */
643+ public function iRefreshTheSession ()
644+ {
645+ $ this ->executeCommand ('session:refresh ' );
646+ }
647+
617648 /**
618649 * @Given /^the primary type of "([^"]*)" should be "([^"]*)"$/
619650 */
@@ -637,6 +668,18 @@ public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
637668 PHPUnit_Framework_Assert::assertEquals ($ arg3 , $ propertyType );
638669 }
639670
671+ /**
672+ * @Given /^I set the value of property "([^"]*)" on node "([^"]*)" to "([^"]*)"$/
673+ */
674+ public function iSetTheValueOfPropertyOnNodeTo ($ arg1 , $ arg2 , $ arg3 )
675+ {
676+ $ session = $ this ->getSession ();
677+ $ node = $ session ->getNode ($ arg2 );
678+ $ property = $ node ->getProperty ($ arg1 );
679+ $ property ->setValue ($ arg3 );
680+ $ session ->save ();
681+ }
682+
640683 /**
641684 * @Given /^the node at "([^"]*)" has the mixin "([^"]*)"$/
642685 */
@@ -655,7 +698,7 @@ public function iCloneNodeFromTo($arg1, $arg2, $arg3)
655698 {
656699 $ session = $ this ->getSession ();
657700 $ workspace = $ session ->getWorkspace ();
658- $ workspace ->cloneFrom ($ arg2 , $ arg1 , $ arg3 , false );
701+ $ workspace ->cloneFrom ($ arg2 , $ arg1 , $ arg3 , true );
659702 }
660703
661704 /**
0 commit comments