Skip to content

Commit 7f2e48e

Browse files
committed
Node set property not working ..
1 parent 2260d6f commit 7f2e48e

File tree

10 files changed

+332
-34
lines changed

10 files changed

+332
-34
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Filesystem\Filesystem;
99
use PHPCR\PathNotFoundException;
1010
use PHPCR\Shell\Test\ApplicationTester;
11+
use PHPCR\Util\PathHelper;
1112

1213
use Behat\Behat\Context\ClosuredContextInterface,
1314
Behat\Behat\Context\TranslatedContextInterface,
@@ -342,6 +343,24 @@ public function thereShouldExistANodeAt($arg1)
342343
} catch (PathNotFoundException $e) {
343344
throw new \Exception('Node does at path ' . $arg1 . ' does not exist.');
344345
}
346+
}
347+
348+
/**
349+
* @Given /^there should exist a node at "([^"]*)" before "([^"]*)"$/
350+
*/
351+
public function thereShouldExistANodeAtBefore($arg1, $arg2)
352+
{
353+
$session = $this->getSession();
354+
try {
355+
$node = $session->getNode($arg1);
356+
} catch (PathNotFoundException $e) {
357+
throw new \Exception('Node does at path ' . $arg1 . ' does not exist.');
358+
}
359+
$parent = $session->getNode(PathHelper::getParentPath($arg1));
360+
$index = $node->getIndex();
361+
$parentChildren = array_values((array) $parent->getNodes());
362+
$beforeNode = $parentChildren[$index];
363+
PHPUnit_Framework_Assert::assertEquals($arg2, $beforeNode->getName());
345364
}
346365

347366
/**
@@ -536,4 +555,35 @@ public function iHaveAnEditorWhichProducesTheFollowing(PyStringNode $string)
536555
chmod($editorFile, 0777);
537556
putenv('EDITOR=' . $editorFile);
538557
}
558+
559+
/**
560+
* @Given /^the current node is "([^"]*)"$/
561+
*/
562+
public function theCurrentNodeIs($arg1)
563+
{
564+
$this->executeCommand(sprintf('cd %s', $arg1));
565+
}
566+
567+
/**
568+
* @Given /^the primary type of "([^"]*)" should be "([^"]*)"$/
569+
*/
570+
public function thePrimaryTypeOfShouldBe($arg1, $arg2)
571+
{
572+
$session = $this->getSession();
573+
$node = $session->getNode($arg1);
574+
$primaryTypeName = $node->getPrimaryNodeType()->getName();
575+
PHPUnit_Framework_Assert::assertEquals($arg2, $primaryTypeName, 'Node type of ' . $arg1 . ' is ' . $arg2);
576+
}
577+
578+
/**
579+
* @Given /^the node at "([^"]*)" should have the property "([^"]*)" with type "([^"]*)"$/
580+
*/
581+
public function theNodeAtShouldHaveThePropertyWithType($arg1, $arg2, $arg3)
582+
{
583+
$session = $this->getSession();
584+
$node = $session->getNode($arg1);
585+
$property = $node->getProperty($arg2);
586+
$propertyType = $property->getType();
587+
PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
588+
}
539589
}

features/node_create.feature

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,38 @@ Feature: Create a node
1010
Scenario: Create a new node
1111
Given the current node is "/"
1212
And I execute the "node:create testcreate" command
13+
And I save the session
1314
Then the command should not fail
1415
And there should exist a node at "/testcreate"
1516

16-
Scenario: Create a new node at a non-root current node
17-
Given the current node is "/tests_general_base"
18-
And I execute the "node:create testcreate" command
17+
Scenario: Create a new node with primary node type
18+
Given the current node is "/"
19+
And I execute the "node:create testfile nt:folder" command
20+
And I save the session
1921
Then the command should not fail
20-
And there should exist a node at "/tests_general_base/testcreate"
22+
And there should exist a node at "/testfile"
23+
And the primary type of "/testfile" should be "nt:folder"
2124

22-
Scenario: Create a new node at an absolute path
23-
Given I execute the "node:create /testcreate" command
24-
Then the command should not fail
25-
And there should exist a node at "/testcreate"
25+
Scenario: Create a new node at a non-root current node no matching child type
26+
Given the current node is "/tests_general_base"
27+
And I execute the "node:create testcreate" command
28+
Then the command should fail
29+
And I should see the following:
30+
"""
31+
No matching child node definition found for `testcreate' in type `nt:folder' for node '/tests_general_base'. Please specify the type explicitly
32+
"""
2633

27-
Scenario: Create a new node before another node
34+
Scenario: Create a new node at a non-root current node
2835
Given the current node is "/tests_general_base"
29-
Given I execute the "node:create foobar --before unversionable" command
36+
And I execute the "node:create testcreate nt:folder" command
37+
And I save the session
3038
Then the command should not fail
31-
And there should exist a node at "/tests_general_base/foobar" before "/tests_general_base/unversionable"
39+
And there should exist a node at "/tests_general_base/testcreate"
3240

3341
Scenario: Attempt to create an empty node
34-
Given I execute the "node:create /" command
42+
Given I execute the "node:create" command
3543
Then the command should fail
36-
And I should see the following
44+
And I should see the following:
3745
"""
38-
Invalid node name "/"
46+
Name can not be empty
3947
"""

features/node_definition.feature

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@ Feature: Show CND for node
77
Given that I am logged in as "testuser"
88
And the "session_data.xml" fixtures are loaded
99

10-
Scenario: Rename a node
10+
Scenario: Show node definition
1111
Given the current node is "/tests_general_base"
1212
And I execute the "node:definition --no-ansi" command
13-
Then the command should not fail
13+
Then the command should fail
1414
And I should see the following:
1515
"""
16-
<nt='http://www.jcp.org/jcr/nt/1.0'>
17-
[nt:unstructured] > nt:base
18-
orderable query
19-
- *
20-
multiple jcr.operator.equal.to', 'jcr.operator.not.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like
21-
- *
22-
jcr.operator.equal.to', 'jcr.operator.not.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like
23-
+ * (nt:base)
24-
= nt:unstructured
25-
VERSION sns
16+
Not implemented
2617
"""

features/node_set.feature

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: Set a node property
66
Background:
77
Given that I am logged in as "testuser"
88
And the "all_property_types.xml" fixtures are loaded
9-
And the current node path is "/properties"
9+
Given the current node is "/properties"
1010

1111
Scenario Outline: Set a property
1212
Given I execute the "<command>" command
@@ -15,9 +15,7 @@ Feature: Set a node property
1515

1616
Examples:
1717
| command | name | type |
18-
| node:set uri http://foobar | uri | http://foobar | url |
19-
| node:set double 12.12 | double | 12.12 | double |
20-
| node:set long 123 | long | 123 | long |
21-
| node:set multivalue value1 --index=0 | multivalue | value1 | string |
22-
| node:set multivalue value2 --index=1 | multivalue | value2 | string |
23-
| node:set thisisnew foobar string | /properties/thisisnew | foobar | string |
18+
| node:set uri http://foobar | uri | http://foobar |
19+
| node:set double 12.12 | double | 12.12 |
20+
| node:set long 123 | long | 123 |
21+
| node:set thisisnew foobar --type=string | /properties/thisisnew | foobar |

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
use PHPCR\Shell\Console\Command\VersionRestoreCommand;
6868
use PHPCR\Shell\Console\Command\VersionRemoveCommand;
6969
use PHPCR\Shell\Console\Command\VersionCheckpointCommand;
70+
use PHPCR\Shell\Console\Command\NodeCreateCommand;
71+
use PHPCR\Shell\Console\Command\NodeDefinitionCommand;
72+
use PHPCR\Shell\Console\Command\NodeSetCommand;
73+
use PHPCR\Shell\Console\Command\NodeRenameCommand;
74+
use Jackalope\NotImplementedException;
7075

7176
class ShellApplication extends Application
7277
{
@@ -144,6 +149,10 @@ public function init()
144149
$this->add(new VersionRemoveCommand());
145150
$this->add(new VersionCheckpointCommand());
146151
$this->add(new VersionCheckinCommand());
152+
$this->add(new NodeCreateCommand());
153+
$this->add(new NodeDefinitionCommand());
154+
$this->add(new NodeSetCommand());
155+
$this->add(new NodeRenameCommand());
147156

148157
// add shell-specific commands
149158
$this->add(new ChangePathCommand());
@@ -244,11 +253,14 @@ public function doRun(InputInterface $input, OutputInterface $output)
244253
if ($e instanceof \PHPCR\UnsupportedRepositoryOperationException) {
245254
throw new \Exception('Unsupported repository operation');
246255
}
256+
}
247257

258+
if ($e instanceof NotImplementedException) {
259+
throw new \Exception('Not implemented: ' . $e->getMessage());
248260
}
249261

250262
$output->writeln('<error>' . $e->getMessage() . '</error>');
251-
return;
263+
return 1;
252264
}
253265

254266
return $exitCode;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
use PHPCR\Util\CND\Parser\CndParser;
12+
use PHPCR\NamespaceException;
13+
use Symfony\Component\Console\Input\InputOption;
14+
15+
class NodeCreateCommand extends Command
16+
{
17+
protected function configure()
18+
{
19+
$this->setName('node:create');
20+
$this->setDescription('Create a node at the current path');
21+
$this->addArgument('relPath', null, InputArgument::REQUIRED, null, 'The name of the node to create');
22+
$this->addArgument('primaryNodeTypeName', null, InputArgument::OPTIONAL, null, 'Optional name of primary node type to use');
23+
$this->setHelp(<<<HERE
24+
Creates a new node at the specified <info>relPath</info>
25+
26+
This is session-write method, meaning that the addition of the new node
27+
is dispatched upon SessionInterface::save().
28+
29+
The <info>relPath</info> provided must not have an index on its final element,
30+
otherwise a RepositoryException is thrown.
31+
32+
If ordering is supported by the node type of the parent node of the new
33+
node then the new node is appended to the end of the child node list.
34+
35+
If <info>primaryNodeTypeName</info> is specified, this type will be used (or a
36+
ConstraintViolationException thrown if this child type is not allowed).
37+
Otherwise the new node's primary node type will be determined by the
38+
child node definitions in the node types of its parent. This may occur
39+
either immediately, on dispatch (save, whether within or without
40+
transactions) or on persist (save without transactions, commit within
41+
a transaction), depending on the implementation.
42+
HERE
43+
);
44+
}
45+
46+
public function execute(InputInterface $input, OutputInterface $output)
47+
{
48+
$session = $this->getHelper('phpcr')->getSession();
49+
$relPath = $input->getArgument('relPath');
50+
$primaryNodeTypeName = $input->getArgument('primaryNodeTypeName');
51+
$currentNode = $session->getCurrentNode();
52+
$currentNode->addNode($relPath, $primaryNodeTypeName);
53+
}
54+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
use PHPCR\Util\CND\Parser\CndParser;
12+
use PHPCR\NamespaceException;
13+
14+
class NodeDefinitionCommand extends Command
15+
{
16+
protected function configure()
17+
{
18+
$this->setName('node:definition');
19+
$this->setDescription('Show the CND Definition of current node NOT IMPLEMENTED');
20+
$this->setHelp(<<<HERE
21+
Show the CND definition of the primary type of the current node.
22+
HERE
23+
);
24+
}
25+
26+
public function execute(InputInterface $input, OutputInterface $output)
27+
{
28+
$session = $this->getHelper('phpcr')->getSession();
29+
$currentNode = $session->getCurrentNode();
30+
$workspace = $session->getWorkspace();
31+
$namespaceRegistry = $workspace->getNamespaceRegistry();
32+
33+
$nodeType = $currentNode->getDefinition();
34+
$cndWriter = new CndWriter($namespaceRegistry);
35+
$out = $cndWriter->writeString(array($nodeType));
36+
$output->writeln(sprintf('<comment>%s</comment>', $out));
37+
}
38+
}
39+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
use PHPCR\Util\CND\Parser\CndParser;
12+
use PHPCR\NamespaceException;
13+
14+
class NodeRenameCommand extends Command
15+
{
16+
protected function configure()
17+
{
18+
$this->setName('node:rename');
19+
$this->setDescription('Rename the node at the current path');
20+
$this->addArgument('newName', null, InputArgument::REQUIRED, 'The name of the node to create');
21+
$this->setHelp(<<<HERE
22+
Renames this node to the specified <info>newName</info>. The ordering (if any) of
23+
this node among it siblings remains unchanged.
24+
25+
This is a session-write method, meaning that the name change is
26+
dispatched upon <comment>session:save</comment>.
27+
28+
The <info>newName</info> provided must not have an index, otherwise a
29+
RepositoryException is thrown.
30+
31+
An ItemExistsException will be thrown either immediately, on dispatch
32+
(save, whether within or without transactions) or on persist (save
33+
without transactions, commit within a transaction), if there already
34+
exists a sibling item of this node with the specified name and
35+
same-name-siblings are not allowed. Implementations may differ on when
36+
this validation is performed.
37+
38+
A ConstraintViolationException will be thrown either immediately, on
39+
dispatch (save, whether within or without transactions) or on persist
40+
(save without transactions, commit within a transaction), if changing
41+
the name would violate a node type or implementation-specific
42+
constraint. Implementations may differ on when this validation is
43+
performed.
44+
45+
A VersionException will be thrown either immediately, on dispatch (save,
46+
whether within or without transactions) or on persist (save without
47+
transactions, commit within a transaction), if this node is read-only
48+
due to a checked-in node. Implementations may differ on when this
49+
validation is performed.
50+
51+
A LockException will be thrown either immediately, on dispatch (save,
52+
whether within or without transactions) or on persist (save without
53+
transactions, commit within a transaction), if a lock prevents the name
54+
change of the node. Implementations may differ on when this validation
55+
is performed.
56+
HERE
57+
);
58+
}
59+
60+
public function execute(InputInterface $input, OutputInterface $output)
61+
{
62+
$session = $this->getHelper('phpcr')->getSession();
63+
$newName = $input->getArgument('newName');
64+
$currentNode = $session->getCurrentNode();
65+
$currentNode->rename($newName);
66+
}
67+
}

0 commit comments

Comments
 (0)