Skip to content

Allow referencing by path #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dev-master

- [cli] Specify workspace with first argument
- [global] Refactored to use DI container and various general improvements
- [node:property:set] Allow setting reference property type by path
- [references] Show UUIDs when listing reference properties
- [import/export] Renamed session import and export to `session:import` &
`session:export`
Expand Down
14 changes: 9 additions & 5 deletions features/all/phpcr_node_property_set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ Feature: Set a node property
Given I execute the "<command>" command
Then the command should not fail
And I save the session
Then the node at "/properties" should have the property "<name>" with value "<value>"
Examples:
| command | name | type |
| node:property:set uri http://foobar | uri | http://foobar |
| node:property:set double 12.12 --type=double | double | 12.12 |
| node:property:set long 123 | long | 123 |
| node:property:set thisisnew foobar --type=string | /properties/thisisnew | foobar |
| command | name | type | value |
| node:property:set uri http://foobar | uri | uri | http://foobar |
| node:property:set double 12.12 --type=double | double | double | 12.12 |
| node:property:set long 123 | long | long | 123 |
| node:property:set thisisnew foobar --type=string | thisisnew | string | foobar |
| node:property:set fooref /properties/reference_target --type=reference | fooref | string | 13543fc6-1abf-4708-bfcc-e49511754b40 |
| node:property:set fooref /properties/reference_target --type=weakreference | fooref | string | 13543fc6-1abf-4708-bfcc-e49511754b40 |
| node:property:set fooref 13543fc6-1abf-4708-bfcc-e49511754b40 --type=weakreference | fooref | string | 13543fc6-1abf-4708-bfcc-e49511754b40 |

Scenario: Update a property but do not specify the type
Given I execute the "node:property:set /properties/decimal 1234" command
Expand Down
21 changes: 21 additions & 0 deletions src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Console\Input\InputOption;
use PHPCR\PropertyType;
use PHPCR\PathNotFoundException;
use PHPCR\Util\UUIDHelper;

class NodePropertySetCommand extends BasePhpcrCommand
{
Expand Down Expand Up @@ -77,6 +78,26 @@ public function execute(InputInterface $input, OutputInterface $output)

if ($type) {
$intType = PropertyType::valueFromName($type);

if ($intType === PropertyType::REFERENCE || $intType === PropertyType::WEAKREFERENCE) {

// convert path to UUID
if (false === UUIDHelper::isUuid($value)) {
$path = $value;
try {
$targetNode = $session->getNode($path);
$value = $targetNode->getIdentifier();
} catch (PathNotFoundException $e) {
}

if (null === $value) {
throw new \InvalidArgumentException(sprintf(
'Node at path "%s" specified for reference is not referenceable',
$path
));
}
}
}
} else {
try {
$property = $node->getProperty($propName);
Expand Down
10 changes: 8 additions & 2 deletions src/PHPCR/Shell/Test/ContextBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPCR\PropertyType;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Context\Context;
use PHPCR\NodeInterface;

use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Expand Down Expand Up @@ -718,8 +719,13 @@ public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
$session = $this->getSession();
$node = $session->getNode($arg1);
$property = $node->getProperty($arg2);
$propertyType = $property->getValue();
\PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
$propertyValue = $property->getValue();

if ($propertyValue instanceof NodeInterface) {
$propertyValue = $propertyValue->getIdentifier();
}

\PHPUnit_Framework_Assert::assertEquals($arg3, $propertyValue);
}

/**
Expand Down