Skip to content

Commit 4eb6150

Browse files
committed
Merge pull request #73 from phpcr/node-edit-command
Node edit command
2 parents 7953ad4 + ffe7120 commit 4eb6150

File tree

15 files changed

+633
-141
lines changed

15 files changed

+633
-141
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"jackalope/jackalope": "~1.1",
99
"phpcr/phpcr": "~2.1",
1010
"phpcr/phpcr-utils": "~1.2",
11-
"symfony/finder": "~2.3"
11+
"symfony/finder": "~2.3",
12+
"symfony/serializer": "~2.3",
13+
"symfony/yaml": "~2.3"
1214
},
1315
"minimum-stability": "dev",
1416
"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: 133 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,144 @@
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
85+
Then the command should not fail
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'
101+
"""
102+
And I execute the "node:edit cms/products/product2" command
103+
Then the command should not fail
104+
And I save the session
13105
Then the command should not fail
14-
And I should see the following:
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
15115
"""
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-
+-------------------+--------------------------------------+
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"
121+
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
25131
"""
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"
26138

139+
Scenario: Editor returns empty string
140+
Given I have an editor which produces the following:
141+
""""
142+
"""
143+
And I execute the "node:edit cms/products/product2 --no-interaction --type=nt:resource" command
144+
Then the command should fail

features/phpcr_node_property_edit.feature

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Serializer;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\NodeInterface;
8+
use PHPCR\PropertyInterface;
9+
use PHPCR\PropertyType;
10+
11+
class NodeNormalizerSpec extends ObjectBehavior
12+
{
13+
function it_is_initializable()
14+
{
15+
$this->shouldHaveType('PHPCR\Shell\Serializer\NodeNormalizer');
16+
}
17+
18+
function it_can_normalize_a_node_to_an_array(
19+
NodeInterface $node,
20+
PropertyInterface $p1,
21+
PropertyInterface $p2,
22+
PropertyInterface $p3
23+
)
24+
{
25+
$node->getProperties()->willReturn(array(
26+
$p1, $p2, $p3
27+
));
28+
29+
$p1->getName()->willReturn('my:property.1');
30+
$p1->getType()->willReturn(PropertyType::STRING);
31+
$p1->getValue()->willReturn('P1 Val');
32+
$p2->getName()->willReturn('my:property.2');
33+
$p2->getType()->willReturn(PropertyType::DOUBLE);
34+
$p2->getValue()->willReturn('P2 Val');
35+
$p3->getName()->willReturn('my:property.3');
36+
$p3->getType()->willReturn(PropertyType::STRING);
37+
$p3->getValue()->willReturn('P3 Val');
38+
39+
$this->normalize($node)->shouldReturn(array(
40+
'my:property.1' => array(
41+
'type' => 'String',
42+
'value' => 'P1 Val',
43+
),
44+
'my:property.2' => array(
45+
'type' => 'Double',
46+
'value' => 'P2 Val',
47+
),
48+
'my:property.3' => array(
49+
'type' => 'String',
50+
'value' => 'P3 Val',
51+
),
52+
));
53+
}
54+
}
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+
}

0 commit comments

Comments
 (0)