diff --git a/CHANGELOG.md b/CHANGELOG.md index b1e33410..f5728308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/features/all/phpcr_node_property_set.feature b/features/all/phpcr_node_property_set.feature index bdf93dfe..528495b1 100644 --- a/features/all/phpcr_node_property_set.feature +++ b/features/all/phpcr_node_property_set.feature @@ -12,12 +12,16 @@ Feature: Set a node property Given I execute the "" command Then the command should not fail And I save the session + Then the node at "/properties" should have the property "" with 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 diff --git a/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php b/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php index e79e15d8..293c3dcb 100644 --- a/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php +++ b/src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php @@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\InputOption; use PHPCR\PropertyType; use PHPCR\PathNotFoundException; +use PHPCR\Util\UUIDHelper; class NodePropertySetCommand extends BasePhpcrCommand { @@ -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); diff --git a/src/PHPCR/Shell/Test/ContextBase.php b/src/PHPCR/Shell/Test/ContextBase.php index a44b669f..f69cc6d6 100644 --- a/src/PHPCR/Shell/Test/ContextBase.php +++ b/src/PHPCR/Shell/Test/ContextBase.php @@ -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, @@ -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); } /**