File tree 4 files changed +56
-8
lines changed
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)
652
652
$ this ->executeCommand (sprintf ('cd %s ' , $ arg1 ));
653
653
}
654
654
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
+
655
665
/**
656
666
* @Given /^the current workspace is "([^"]*)"$/
657
667
*/
Original file line number Diff line number Diff line change @@ -7,9 +7,28 @@ Feature: Remove a node
7
7
Given that I am logged in as "testuser"
8
8
And the "session_data.xml" fixtures are loaded
9
9
10
- Scenario : Remove a node
10
+ Scenario : Remove the current node
11
11
Given the current node is "/tests_general_base"
12
12
And I execute the "node:remove ." command
13
13
Then the command should not fail
14
14
And I save the session
15
15
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()
23
23
public function execute (InputInterface $ input , OutputInterface $ output )
24
24
{
25
25
$ 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 ();
29
28
30
- if ($ currentPath == '/ ' ) {
29
+ // verify that node exists by trying to get it..
30
+ $ targetNode = $ session ->getNode ($ targetPath );
31
+
32
+ if ($ targetPath == '/ ' ) {
31
33
throw new \InvalidArgumentException (
32
- 'Cannot delete root node! '
34
+ 'You cannot delete the root node! '
33
35
);
34
36
}
35
37
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
+ }
38
45
}
39
46
}
Original file line number Diff line number Diff line change @@ -90,6 +90,18 @@ public function getDisplay($normalize = false)
90
90
return $ display ;
91
91
}
92
92
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
+
93
105
/**
94
106
* Gets the input instance used by the last execution of the application.
95
107
*
You can’t perform that action at this time.
0 commit comments