File tree Expand file tree Collapse file tree 4 files changed +56
-8
lines changed Expand file tree Collapse file tree 4 files changed +56
-8
lines changed Original file line number Diff line number Diff line change @@ -652,6 +652,16 @@ public function theCurrentNodeIs($arg1)
652652 $ this ->executeCommand (sprintf ('cd %s ' , $ arg1 ));
653653 }
654654
655+ /**
656+ * @Given /^the current node should be "([^"]*)"$/
657+ */
658+ public function theCurrentNodeShouldBe ($ arg1 )
659+ {
660+ $ this ->executeCommand ('shell:path:show ' );
661+ $ cnp = $ this ->applicationTester ->getLastLine ();
662+ PHPUnit_Framework_Assert::assertEquals ($ arg1 , $ cnp , 'Current path is ' . $ arg1 );
663+ }
664+
655665 /**
656666 * @Given /^the current workspace is "([^"]*)"$/
657667 */
Original file line number Diff line number Diff line change @@ -7,9 +7,28 @@ Feature: Remove a node
77 Given that I am logged in as "testuser"
88 And the "session_data.xml" fixtures are loaded
99
10- Scenario : Remove a node
10+ Scenario : Remove the current node
1111 Given the current node is "/tests_general_base"
1212 And I execute the "node:remove ." command
1313 Then the command should not fail
1414 And I save the session
1515 And there should not exist a node at "/tests_general_base"
16+ And the current node should be "/"
17+
18+ Scenario : Remove a non-current node
19+ Given the current node is "/tests_general_base"
20+ And I execute the "node:remove daniel" command
21+ Then the command should not fail
22+ And I save the session
23+ And there should not exist a node at "/tests_general_base/daniel"
24+ And the current node should be "/tests_general_base"
25+
26+ Scenario : Delete root node
27+ Given the current node is "/"
28+ And I execute the "node:remove ." command
29+ Then the command should fail
30+ And I should see the following:
31+ """
32+ You cannot delete the root node
33+ """
34+
Original file line number Diff line number Diff line change @@ -23,17 +23,24 @@ protected function configure()
2323 public function execute (InputInterface $ input , OutputInterface $ output )
2424 {
2525 $ session = $ this ->getHelper ('phpcr ' )->getSession ();
26- $ path = $ session ->getAbsPath ($ input ->getArgument ('path ' ));
27- $ currentNode = $ session ->getNode ($ path );
28- $ currentPath = $ currentNode ->getPath ();
26+ $ targetPath = $ session ->getAbsPath ($ input ->getArgument ('path ' ));
27+ $ currentPath = $ session ->getCwd ();
2928
30- if ($ currentPath == '/ ' ) {
29+ // verify that node exists by trying to get it..
30+ $ targetNode = $ session ->getNode ($ targetPath );
31+
32+ if ($ targetPath == '/ ' ) {
3133 throw new \InvalidArgumentException (
32- 'Cannot delete root node! '
34+ 'You cannot delete the root node! '
3335 );
3436 }
3537
36- $ session ->removeItem ($ currentPath );
37- $ session ->chdir ('.. ' );
38+ $ session ->removeItem ($ targetPath );
39+
40+ // if we deleted the current path, switch back to the parent node
41+ if ($ currentPath == $ targetPath ) {
42+ echo $ currentPath . ' vs. ' . $ targetPath ;
43+ $ session ->chdir ('.. ' );
44+ }
3845 }
3946}
Original file line number Diff line number Diff line change @@ -90,6 +90,18 @@ public function getDisplay($normalize = false)
9090 return $ display ;
9191 }
9292
93+ public function getLastLine ()
94+ {
95+ $ display = trim ($ this ->getDisplay ());
96+ $ lines = explode ("\n" , $ display );
97+
98+ if ($ lines ) {
99+ return end ($ lines );
100+ }
101+
102+ return $ display ;
103+ }
104+
93105 /**
94106 * Gets the input instance used by the last execution of the application.
95107 *
You can’t perform that action at this time.
0 commit comments