@@ -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,13 +46,13 @@ 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 (
5353 '--transport ' => 'jackrabbit ' ,
5454 '--no-interaction ' => true ,
55+ '--unsupported ' => true , // test all the commands, even if they are unsupported (we test for the fail)
5556 ), array (
5657 'interactive ' => true ,
5758 ));
@@ -69,8 +70,19 @@ public static function cleanTestFolders()
6970 $ fs ->remove (sys_get_temp_dir () . DIRECTORY_SEPARATOR . 'phpcr-shell ' );
7071 }
7172
72- private function getSession ($ workspaceName = ' default ' )
73+ private function getSession ($ workspaceName = null , $ force = false )
7374 {
75+ if ($ workspaceName === null ) {
76+ $ workspaceName = $ this ->currentWorkspaceName ;
77+ }
78+
79+ static $ sessions = array ();
80+
81+ if (false === $ force && isset ($ sessions [$ workspaceName ])) {
82+ $ session = $ sessions [$ workspaceName ];
83+ return $ session ;
84+ }
85+
7486 $ params = array (
7587 'jackalope.jackrabbit_uri ' => 'http://localhost:8080/server/ ' ,
7688 );
@@ -79,9 +91,9 @@ private function getSession($workspaceName = 'default')
7991 $ repository = $ factory ->getRepository ($ params );
8092 $ credentials = new SimpleCredentials ('admin ' , 'admin ' );
8193
82- $ session = $ repository ->login ($ credentials , $ workspaceName );
94+ $ sessions [ $ workspaceName ] = $ repository ->login ($ credentials , $ workspaceName );
8395
84- return $ session ;
96+ return $ sessions [ $ workspaceName ] ;
8597 }
8698
8799 private function getOutput ()
@@ -184,7 +196,7 @@ public function iShouldSeeTheFollowing(PyStringNode $string)
184196 public function theFixturesAreLoaded ($ arg1 )
185197 {
186198 $ fixtureFile = $ this ->getFixtureFilename ($ arg1 );
187- $ session = $ this ->getSession ();
199+ $ session = $ this ->getSession (null , true );
188200 NodeHelper::purgeWorkspace ($ session );
189201 $ session ->save ();
190202 $ session ->importXml ('/ ' , $ fixtureFile , 0 );
@@ -407,7 +419,7 @@ public function theNodeAtShouldNotHaveTheMixin($arg1, $arg2)
407419 */
408420 public function thereShouldNotExistANodeAt ($ arg1 )
409421 {
410- $ session = $ this ->getSession ();
422+ $ session = $ this ->getSession (null , true );
411423
412424 try {
413425 $ session ->getNode ($ arg1 );
@@ -506,7 +518,11 @@ public function thereExistsAWorkspace($arg1)
506518 {
507519 $ session = $ this ->getSession ();
508520 $ workspace = $ session ->getWorkspace ();
509- $ workspace ->createWorkspace ($ arg1 );
521+ try {
522+ $ workspace ->createWorkspace ($ arg1 );
523+ } catch (\Exception $ e ) {
524+ // already exists..
525+ }
510526 }
511527
512528 /**
@@ -522,12 +538,13 @@ public function thereShouldNotExistAWorkspaceCalled($arg1)
522538 }
523539
524540 /**
525- * @Given /^the "([^"]*)" fixtures are loaded into a workspace "([^"]*)"$/
541+ * @Given /^the "([^"]*)" fixtures are loaded into workspace "([^"]*)"$/
526542 */
527- public function theFixturesAreLoadedIntoAWorkspace ($ arg1 , $ arg2 )
543+ public function theFixturesAreLoadedIntoWorkspace ($ arg1 , $ arg2 )
528544 {
545+ $ this ->theCurrentWorkspaceIs ($ arg2 );
529546 $ fixtureFile = $ this ->getFixtureFilename ($ arg1 );
530- $ session = $ this ->getSession ($ arg2 );
547+ $ session = $ this ->getSession ();
531548 NodeHelper::purgeWorkspace ($ session );
532549 $ session ->save ();
533550 $ session ->importXml ('/ ' , $ fixtureFile , 0 );
@@ -545,7 +562,6 @@ public function theNodeTypeIsLoaded($arg1)
545562 $ workspace = $ session ->getWorkspace ();
546563 $ nodeTypeManager = $ workspace ->getNodeTypeManager ();
547564 $ nodeTypeManager ->registerNodeTypesCnd ($ cnd , true );
548- $ session ->save ();
549565 }
550566
551567 /**
@@ -603,6 +619,33 @@ public function theCurrentNodeIs($arg1)
603619 $ this ->executeCommand (sprintf ('cd %s ' , $ arg1 ));
604620 }
605621
622+ /**
623+ * @Given /^the current workspace is "([^"]*)"$/
624+ */
625+ public function theCurrentWorkspaceIs ($ arg1 )
626+ {
627+ $ this ->thereExistsAWorkspace ($ arg1 );
628+ $ this ->currentWorkspaceName = $ arg1 ;
629+ }
630+
631+ /**
632+ * @Given /^the current workspace is empty/
633+ */
634+ public function theCurrentWorkspaceIsEmpty ()
635+ {
636+ $ session = $ this ->getSession ();
637+ NodeHelper::purgeWorkspace ($ session );
638+ $ session ->save ();
639+ }
640+
641+ /**
642+ * @Given /^I refresh the session/
643+ */
644+ public function iRefreshTheSession ()
645+ {
646+ $ this ->executeCommand ('session:refresh ' );
647+ }
648+
606649 /**
607650 * @Given /^the primary type of "([^"]*)" should be "([^"]*)"$/
608651 */
@@ -615,17 +658,29 @@ public function thePrimaryTypeOfShouldBe($arg1, $arg2)
615658 }
616659
617660 /**
618- * @Given /^the node at "([^"]*)" should have the property "([^"]*)" with type "([^"]*)"$/
661+ * @Given /^the node at "([^"]*)" should have the property "([^"]*)" with value "([^"]*)"$/
619662 */
620- public function theNodeAtShouldHaveThePropertyWithType ($ arg1 , $ arg2 , $ arg3 )
663+ public function theNodeAtShouldHaveThePropertyWithValue ($ arg1 , $ arg2 , $ arg3 )
621664 {
622665 $ session = $ this ->getSession ();
623666 $ node = $ session ->getNode ($ arg1 );
624667 $ property = $ node ->getProperty ($ arg2 );
625- $ propertyType = $ property ->getType ();
668+ $ propertyType = $ property ->getValue ();
626669 PHPUnit_Framework_Assert::assertEquals ($ arg3 , $ propertyType );
627670 }
628671
672+ /**
673+ * @Given /^I set the value of property "([^"]*)" on node "([^"]*)" to "([^"]*)"$/
674+ */
675+ public function iSetTheValueOfPropertyOnNodeTo ($ arg1 , $ arg2 , $ arg3 )
676+ {
677+ $ session = $ this ->getSession ();
678+ $ node = $ session ->getNode ($ arg2 );
679+ $ property = $ node ->getProperty ($ arg1 );
680+ $ property ->setValue ($ arg3 );
681+ $ session ->save ();
682+ }
683+
629684 /**
630685 * @Given /^the node at "([^"]*)" has the mixin "([^"]*)"$/
631686 */
@@ -644,7 +699,7 @@ public function iCloneNodeFromTo($arg1, $arg2, $arg3)
644699 {
645700 $ session = $ this ->getSession ();
646701 $ workspace = $ session ->getWorkspace ();
647- $ workspace ->cloneFrom ($ arg2 , $ arg1 , $ arg3 , false );
702+ $ workspace ->cloneFrom ($ arg2 , $ arg1 , $ arg3 , true );
648703 }
649704
650705 /**
0 commit comments