Skip to content

Commit 2dd6203

Browse files
committed
Node Edit command
1 parent 895de85 commit 2dd6203

File tree

13 files changed

+450
-135
lines changed

13 files changed

+450
-135
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
dev-master
5+
----------
6+
7+
### Features
8+
9+
- [node:edit] New command `node:edit` enables editing of entire node
10+
411
alpha-4
512
-------
613

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"phpcr/phpcr": "~2.1",
1010
"phpcr/phpcr-utils": "~1.2",
1111
"symfony/finder": "~2.3",
12-
"symfony/serializer": "~2.3"
12+
"symfony/serializer": "~2.3",
13+
"symfony/yaml": "~2.3"
1314
},
1415
"minimum-stability": "dev",
1516
"require-dev": {

features/bootstrap/FeatureContext.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PHPCR\PathNotFoundException;
1010
use PHPCR\Shell\Test\ApplicationTester;
1111
use PHPCR\Util\PathHelper;
12+
use PHPCR\PropertyInterface;
13+
use PHPCR\PropertyType;
1214

1315
use Behat\Behat\Context\ClosuredContextInterface,
1416
Behat\Behat\Context\TranslatedContextInterface,
@@ -233,7 +235,7 @@ public function theCommandShouldNotFail()
233235
throw new \Exception('Command failed: (' . $exitCode . ') ' . $this->getOutput());
234236
}
235237

236-
PHPUnit_Framework_Assert::assertEquals(0, $exitCode, 'Command exited with code ' . $exitCode);
238+
PHPUnit_Framework_Assert::assertEquals(0, $exitCode, 'Command exited with code: ' . $exitCode);
237239
}
238240

239241
/**
@@ -720,6 +722,23 @@ public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
720722
PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
721723
}
722724

725+
/**
726+
* @Given /^the property "([^"]*)" should have type "([^"]*)" and value "([^"]*)"$/
727+
*/
728+
public function thePropertyShouldHaveTypeAndValue($arg1, $arg2, $arg3)
729+
{
730+
$session = $this->getSession();
731+
$property = $session->getItem($arg1);
732+
if (!$property instanceof PropertyInterface) {
733+
throw new \InvalidArgumentException(sprintf(
734+
'Item at "%s" is not a property', $arg1
735+
));
736+
}
737+
738+
PHPUnit_Framework_Assert::assertEquals($arg2, PropertyType::nameFromValue($property->getType()));
739+
PHPUnit_Framework_Assert::assertEquals($arg3, $property->getValue());
740+
}
741+
723742
/**
724743
* @Given /^I set the value of property "([^"]*)" on node "([^"]*)" to "([^"]*)"$/
725744
*/

features/fixtures/cms.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@
2525
</sv:property>
2626
</sv:node>
2727

28+
<sv:node sv:name="products">
29+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
30+
<sv:value>nt:unstructured</sv:value>
31+
</sv:property>
32+
<sv:node sv:name="product1">
33+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
34+
<sv:value>nt:unstructured</sv:value>
35+
</sv:property>
36+
<sv:property sv:name="name" sv:type="String">
37+
<sv:value>Product One</sv:value>
38+
</sv:property>
39+
<sv:property sv:name="cost" sv:type="Double">
40+
<sv:value>12.13</sv:value>
41+
</sv:property>
42+
<sv:property sv:name="size" sv:type="String">
43+
<sv:value>XL</sv:value>
44+
</sv:property>
45+
<sv:property sv:name="weight" sv:type="Double">
46+
<sv:value>10</sv:value>
47+
</sv:property>
48+
<sv:property sv:name="tags" sv:type="String">
49+
<sv:value>one</sv:value>
50+
<sv:value>two</sv:value>
51+
<sv:value>three</sv:value>
52+
</sv:property>
53+
</sv:node>
54+
</sv:node>
55+
2856
<sv:node sv:name="articles">
2957
<sv:property sv:name="jcr:primaryType" sv:type="Name">
3058
<sv:value>nt:unstructured</sv:value>

features/phpcr_node_edit.feature

Lines changed: 126 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,137 @@
11
Feature: Edit a node
2-
In order to show some useful information about the current node
2+
In order to edit a node
33
As a user that is logged into the shell
44
I should be able to run a command which does that
55

66
Background:
77
Given that I am logged in as "testuser"
8-
And the "session_data.xml" fixtures are loaded
8+
And the "cms.xml" fixtures are loaded
99

10-
Scenario: Show node information
11-
Given the current node is "/tests_general_base"
12-
And I execute the "node:info daniel --no-ansi" command
10+
Scenario: Make a nutral edit
11+
Given I have an editor which produces the following:
12+
""""
13+
weight:
14+
type: Long
15+
value: 10
16+
cost:
17+
type: Double
18+
value: 12.13
19+
size:
20+
type: String
21+
value: XL
22+
name:
23+
type: String
24+
value: 'Product One'
25+
tags:
26+
type: String
27+
value: [one, two, three]
28+
'jcr:primaryType':
29+
type: Name
30+
value: 'nt:unstructured'
31+
"""
32+
And I execute the "node:edit cms/products/product1" command
33+
Then the command should not fail
34+
And the property "/cms/products/product1/weight" should have type "Long" and value "10"
35+
And the property "/cms/products/product1/cost" should have type "Double" and value "12.13"
36+
And the property "/cms/products/product1/size" should have type "String" and value "XL"
37+
And the property "/cms/products/product1/name" should have type "String" and value "Product One"
38+
And the property "/cms/products/product1/jcr:primaryType" should have type "Name" and value "nt:unstructured"
39+
40+
Scenario: Remove some properties
41+
Given I have an editor which produces the following:
42+
""""
43+
weight:
44+
type: Long
45+
value: 10
46+
name:
47+
type: String
48+
value: 'Product One'
49+
'jcr:primaryType':
50+
type: Name
51+
value: 'nt:unstructured'
52+
"""
53+
And I execute the "node:edit cms/products/product1" command
54+
Then the command should not fail
55+
And I save the session
56+
Then the command should not fail
57+
And the property "/cms/products/product1/weight" should have type "Long" and value "10"
58+
And the property "/cms/products/product1/name" should have type "String" and value "Product One"
59+
And the property "/cms/products/product1/jcr:primaryType" should have type "Name" and value "nt:unstructured"
60+
And there should not exist a property at "/cms/products/product1/cost"
61+
And there should not exist a property at "/cms/products/product1/size"
62+
63+
Scenario: Edit some properties
64+
Given I have an editor which produces the following:
65+
""""
66+
weight:
67+
type: Long
68+
value: 10
69+
cost:
70+
type: Double
71+
value: 100
72+
size:
73+
type: String
74+
value: XXL
75+
name:
76+
type: String
77+
value: 'Product One'
78+
'jcr:primaryType':
79+
type: Name
80+
value: 'nt:unstructured'
81+
"""
82+
And I execute the "node:edit cms/products/product1" command
83+
Then the command should not fail
84+
And I save the session
1385
Then the command should not fail
14-
And I should see the following:
86+
And the property "/cms/products/product1/weight" should have type "Long" and value "10"
87+
And the property "/cms/products/product1/cost" should have type "Long" and value "100"
88+
And the property "/cms/products/product1/size" should have type "String" and value "XXL"
89+
And the property "/cms/products/product1/name" should have type "String" and value "Product One"
90+
And the property "/cms/products/product1/jcr:primaryType" should have type "Name" and value "nt:unstructured"
91+
92+
Scenario: Create a new node
93+
Given I have an editor which produces the following:
94+
""""
95+
'jcr:primaryType':
96+
type: Name
97+
value: 'nt:unstructured'
98+
foobar:
99+
type: String
100+
value: 'FOOOOOOO'
15101
"""
16-
+-------------------+--------------------------------------+
17-
| Path | /tests_general_base/daniel |
18-
| UUID | N/A |
19-
| Index | 1 |
20-
| Primary node type | nt:unstructured |
21-
| Mixin node types | |
22-
| Checked out? | N/A |
23-
| Locked? | [ERROR] Not implemented by jackalope |
24-
+-------------------+--------------------------------------+
102+
And I execute the "node:edit cms/products/product2" command
103+
Then the command should not fail
104+
And I save the session
105+
Then the command should not fail
106+
And the property "/cms/products/product2/foobar" should have type "String" and value "FOOOOOOO"
107+
108+
Scenario: Create a new node with short syntax
109+
Given I have an editor which produces the following:
110+
""""
111+
'jcr:primaryType':
112+
type: Name
113+
value: 'nt:unstructured'
114+
foobar: FOOOOOOO
25115
"""
116+
And I execute the "node:edit cms/products/product2" command
117+
Then the command should not fail
118+
And I save the session
119+
Then the command should not fail
120+
And the property "/cms/products/product2/foobar" should have type "String" and value "FOOOOOOO"
26121

122+
Scenario: Create a new node with a specified type
123+
Given I have an editor which produces the following:
124+
""""
125+
'jcr:primaryType':
126+
type: Name
127+
value: 'nt:resource'
128+
'jcr:data':
129+
type: Binary
130+
value: foo
131+
"""
132+
And I execute the "node:edit cms/products/product2 --type=nt:resource" command
133+
Then the command should not fail
134+
And I save the session
135+
Then the command should not fail
136+
And there should exist a node at "/cms/products/product2"
137+
And the primary type of "/cms/products/product2" should be "nt:resource"

features/phpcr_node_property_edit.feature

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Serializer;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
8+
class YamlEncoderSpec extends ObjectBehavior
9+
{
10+
function it_is_initializable()
11+
{
12+
$this->shouldHaveType('PHPCR\Shell\Serializer\YamlEncoder');
13+
}
14+
15+
function it_should_encode_to_yaml()
16+
{
17+
$data = array('foobar' => 'barfoo', 'barfoo' => 'foobar');
18+
$this->encode($data, 'yaml')->shouldReturn(<<<EOT
19+
foobar: barfoo
20+
barfoo: foobar
21+
22+
EOT
23+
);
24+
}
25+
26+
function is_should_decode_yaml()
27+
{
28+
$yaml = <<<EOT
29+
foobar: barfoo
30+
barfoo: foobar
31+
EOT
32+
;
33+
34+
$this->decode($yaml, 'yaml')->shouldReturn(array(
35+
'foobar' => 'barfoo',
36+
'barfoo' => 'foobar'
37+
));
38+
39+
}
40+
}

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ private function registerCommands()
156156
$this->add(new CommandPhpcr\SessionLogoutCommand());
157157
$this->add(new CommandPhpcr\SessionNamespaceListCommand());
158158
$this->add(new CommandPhpcr\SessionNamespaceSetCommand());
159-
$this->add(new CommandPhpcr\NodePropertyEditCommand());
160159
$this->add(new CommandPhpcr\NodePropertyRemoveCommand());
161160
$this->add(new CommandPhpcr\NodePropertyShowCommand());
162161
$this->add(new CommandPhpcr\SessionRefreshCommand());
@@ -175,6 +174,7 @@ private function registerCommands()
175174
$this->add(new CommandPhpcr\WorkspaceListCommand());
176175
$this->add(new CommandPhpcr\NodeCloneCommand());
177176
$this->add(new CommandPhpcr\NodeCopyCommand());
177+
$this->add(new CommandPhpcr\NodeEditCommand());
178178
$this->add(new CommandPhpcr\WorkspaceNamespaceListCommand());
179179
$this->add(new CommandPhpcr\WorkspaceNamespaceRegisterCommand());
180180
$this->add(new CommandPhpcr\WorkspaceNamespaceUnregisterCommand());

0 commit comments

Comments
 (0)