/**
  * @test
  */
 public function similarizeClearsPropertiesBeforeAddingNewOnes()
 {
     /** @var $sourceNode NodeData */
     $sourceNode = $this->getAccessibleMock(NodeData::class, array('addOrUpdate'), array('/foo/bar', $this->mockWorkspace));
     $this->inject($sourceNode, 'nodeTypeManager', $this->mockNodeTypeManager);
     $sourceNode->_set('nodeDataRepository', $this->createMock(RepositoryInterface::class));
     $this->nodeData->setProperty('someProperty', 'somePropertyValue');
     $this->nodeData->setProperty('someOtherProperty', 'someOtherPropertyValue');
     $sourceNode->setProperty('newProperty', 'newPropertyValue');
     $sourceNode->setProperty('someProperty', 'someOverriddenPropertyValue');
     $this->nodeData->similarize($sourceNode);
     $expectedProperties = array('newProperty' => 'newPropertyValue', 'someProperty' => 'someOverriddenPropertyValue');
     $this->assertEquals($expectedProperties, $this->nodeData->getProperties());
 }
Пример #2
0
 /**
  * Sets the specified property.
  *
  * If the node has a content object attached, the property will be set there
  * if it is settable.
  *
  * @param string $propertyName Name of the property
  * @param mixed $value Value of the property
  * @return mixed
  * @api
  */
 public function setProperty($propertyName, $value)
 {
     if (!$this->isNodeDataMatchingContext()) {
         $this->materializeNodeData();
     }
     // Arrays could potentially contain entities and objects could be entities. In that case even if the object is the same it needs to be persisted in NodeData.
     if (!is_object($value) && !is_array($value) && $this->getProperty($propertyName) === $value) {
         return;
     }
     $oldValue = $this->hasProperty($propertyName) ? $this->getProperty($propertyName) : null;
     $this->emitBeforeNodePropertyChange($this, $propertyName, $oldValue, $value);
     $this->nodeData->setProperty($propertyName, $value);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodePropertyChanged($this, $propertyName, $oldValue, $value);
     $this->emitNodeUpdated($this);
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return NodeData
  */
 public function execute(NodeData $node)
 {
     $reference = (string) $node->getProperty('plugin');
     $workspace = $node->getWorkspace();
     do {
         if ($this->reverse === false && preg_match(NodeInterface::MATCH_PATTERN_PATH, $reference)) {
             $pluginNode = $this->nodeDataRepository->findOneByPath($reference, $node->getWorkspace());
         } else {
             $pluginNode = $this->nodeDataRepository->findOneByIdentifier($reference, $node->getWorkspace());
         }
         if (isset($pluginNode)) {
             break;
         }
         $workspace = $workspace->getBaseWorkspace();
     } while ($workspace && $workspace->getName() !== 'live');
     if (isset($pluginNode)) {
         $node->setProperty('plugin', $this->reverse === false ? $pluginNode->getIdentifier() : $pluginNode->getPath());
     }
     return $node;
 }
 /**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $currentPropertyValue = $node->getProperty($this->propertyName);
     $newValueWithReplacedCurrentValue = str_replace($this->currentValuePlaceholder, $currentPropertyValue, $this->newValue);
     $newValueWithReplacedSearch = str_replace($this->search, $this->replace, $newValueWithReplacedCurrentValue);
     $node->setProperty($this->propertyName, $newValueWithReplacedSearch);
 }
 /**
  * Renames the configured property to the new name.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setProperty($this->newPropertyName, $node->getProperty($this->oldPropertyName));
     $node->removeProperty($this->oldPropertyName);
 }
 /**
  * Add the new property with the given value on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setProperty($this->newPropertyName, $this->value);
 }
 /**
  * Strips tags on the value of the property to work on.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $node->setProperty($this->propertyName, strip_tags($node->getProperty($this->propertyName)));
 }