public function setUp()
 {
     $this->factory = $this->prophesize(StructureMetadataFactory::class);
     $this->extensionManager = $this->prophesize(ExtensionManager::class);
     $this->inspector = $this->prophesize(DocumentInspector::class);
     $this->structure = $this->prophesize(StructureMetadata::class);
     $this->extension = $this->prophesize(ExtensionInterface::class);
     $this->propertyFactory = $this->prophesize(LegacyPropertyFactory::class);
     $typemap = ['page' => '\\Sulu\\Component\\Content\\Compat\\Structure\\PageBridge', 'home' => '\\Sulu\\Component\\Content\\Compat\\Structure\\PageBridge', 'snippet' => '\\Sulu\\Component\\Content\\Compat\\Structure\\SnippetBridge'];
     $this->structureManager = new StructureManager($this->factory->reveal(), $this->extensionManager->reveal(), $this->inspector->reveal(), $this->propertyFactory->reveal(), $typemap);
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function getProperty($name)
 {
     $this->init();
     if (isset($this->properties[$name])) {
         return $this->properties[$name];
     }
     if (!$this->node) {
         $this->node = $this->inspector->getNode($this->document);
     }
     $structureProperty = $this->structureMetadata->getProperty($name);
     $contentTypeName = $structureProperty->getType();
     $bridge = new StructureBridge($this->structureMetadata, $this->inspector, $this->legacyPropertyFactory, $this->document);
     if ($structureProperty->isLocalized()) {
         $locale = $this->inspector->getLocale($this->document);
         $property = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale, $bridge);
     } else {
         $property = $this->legacyPropertyFactory->createProperty($structureProperty);
     }
     $this->legacyProperties[$name] = $property;
     $property->setStructure($bridge);
     $contentType = $this->contentTypeManager->get($contentTypeName);
     $contentType->read($this->node, $property, null, null, null);
     $valueProperty = new PropertyValue($name, $property->getValue());
     $this->properties[$name] = $valueProperty;
     return $valueProperty;
 }
Exemple #3
0
 /**
  * Prepare document-property and import them.
  *
  * @param PropertyInterface $property
  * @param NodeInterface $node
  * @param string $value
  * @param string $webspaceKey
  * @param string $locale
  * @param string $format
  */
 protected function importProperty(PropertyInterface $property, NodeInterface $node, StructureInterface $structure, $value, $webspaceKey, $locale, $format)
 {
     $contentType = $property->getContentTypeName();
     if (!$this->contentImportManager->hasImport($contentType, $format)) {
         return;
     }
     $translateProperty = $this->legacyPropertyFactory->createTranslatedProperty($property, $locale, $structure);
     $this->contentImportManager->import($contentType, $node, $translateProperty, $value, null, $webspaceKey, $locale);
 }
Exemple #4
0
 private function createLegacyPropertyFromItem($item)
 {
     $name = $item->getName();
     if (isset($this->loadedProperties[$name])) {
         return $this->loadedProperties[$name];
     }
     $propertyBridge = $this->propertyFactory->createProperty($item, $this);
     if ($this->document) {
         $property = $this->getDocument()->getStructure()->getProperty($name);
         $propertyBridge->setPropertyValue($property);
     }
     $this->loadedProperties[$name] = $propertyBridge;
     return $propertyBridge;
 }
 private function doGetProperty($name, $contentTypeName, $locale)
 {
     $this->propertyMetadata->getType()->willReturn($contentTypeName);
     $this->structureMetadata->getProperty($name)->willReturn($this->propertyMetadata);
     $this->contentTypeManager->get($contentTypeName)->willReturn($this->contentType->reveal());
     if ($locale) {
         $this->propertyFactory->createTranslatedProperty($this->propertyMetadata->reveal(), $locale, Argument::type(StructureBridge::class))->willReturn($this->legacyProperty->reveal());
     } else {
         $this->propertyFactory->createProperty($this->propertyMetadata->reveal(), $locale)->willReturn($this->legacyProperty->reveal());
     }
     $this->contentType->read($this->node->reveal(), $this->legacyProperty->reveal(), null, null, null)->shouldBeCalledTimes(1);
     $property = $this->structure->getProperty($name);
     $this->assertInstanceOf(PropertyValue::class, $property);
     $this->assertEquals($name, $property->getName());
 }
 /**
  * It should create a block property.
  *
  * @depends testCreateProperty
  */
 public function testCreateBlock($property)
 {
     $this->setUpProperty($this->block);
     $this->component->getName()->willReturn('hai');
     $this->component->getChildren()->willReturn([$property->reveal()]);
     $this->component->title = ['de' => 'Testtitel', 'en' => 'Test title'];
     $this->block->getComponents()->willReturn([$this->component->reveal()]);
     $this->block->getDefaultComponentName()->willReturn('foobar');
     /** @var BlockProperty $blockProperty */
     $blockProperty = $this->factory->createProperty($this->block->reveal());
     $this->assertInstanceOf(BlockPropertyInterface::class, $blockProperty);
     $this->assertCount(1, $blockProperty->getTypes());
     $blockType = $blockProperty->getType('hai');
     $this->assertNotNull($blockType);
     $this->assertCount(1, $blockType->getChildProperties());
     $this->assertEquals('Testtitel', $blockType->getMetadata()->get('title', 'de'));
     $this->assertEquals('Test title', $blockType->getMetadata()->get('title', 'en'));
 }
Exemple #7
0
 /**
  * Map to the content properties to the node using the content types.
  *
  * @param mixed $document
  * @param NodeInterface $node
  * @param string $locale
  *
  * @throws MandatoryPropertyException
  */
 private function mapContentToNode($document, NodeInterface $node, $locale)
 {
     $structure = $document->getStructure();
     $webspaceName = $this->inspector->getWebspace($document);
     $metadata = $this->inspector->getStructureMetadata($document);
     foreach ($metadata->getProperties() as $propertyName => $structureProperty) {
         $realProperty = $structure->getProperty($propertyName);
         $value = $realProperty->getValue();
         if ($structureProperty->isRequired() && null === $value) {
             throw new MandatoryPropertyException(sprintf('Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"', $propertyName, $metadata->getName(), $metadata->resource));
         }
         $contentTypeName = $structureProperty->getContentTypeName();
         $contentType = $this->contentTypeManager->get($contentTypeName);
         // TODO: Only write if the property has been modified.
         $legacyProperty = $this->legacyPropertyFactory->createTranslatedProperty($structureProperty, $locale);
         $legacyProperty->setValue($value);
         $contentType->remove($node, $legacyProperty, $webspaceName, $locale, null);
         $contentType->write($node, $legacyProperty, null, $webspaceName, $locale, null);
     }
 }
 /**
  * It should set the structure type and map the content to thethe node.
  */
 public function testPersist()
 {
     $document = new TestContentDocument($this->structure->reveal());
     $document->setStructureType('foobar');
     $this->persistEvent->getDocument()->willReturn($document);
     // map the structure type
     $this->persistEvent->getLocale()->willReturn('fr');
     $this->encoder->contentName('template')->willReturn('i18n:fr-template');
     $this->node->setProperty('i18n:fr-template', 'foobar')->shouldBeCalled();
     // map the content
     $this->inspector->getStructureMetadata($document)->willReturn($this->structureMetadata->reveal());
     $this->inspector->getWebspace($document)->willReturn('webspace');
     $this->structureMetadata->getProperties()->willReturn(['prop1' => $this->structureProperty->reveal()]);
     $this->structureProperty->isRequired()->willReturn(true);
     $this->structureProperty->getContentTypeName()->willReturn('content_type');
     $this->contentTypeManager->get('content_type')->willReturn($this->contentType->reveal());
     $this->propertyFactory->createTranslatedProperty($this->structureProperty->reveal(), 'fr')->willReturn($this->legacyProperty->reveal());
     $this->structure->getProperty('prop1')->willReturn($this->propertyValue->reveal());
     $this->propertyValue->getValue()->willReturn('test');
     $this->contentType->remove($this->node->reveal(), $this->legacyProperty->reveal(), 'webspace', 'fr', null)->shouldBeCalled();
     $this->contentType->write($this->node->reveal(), $this->legacyProperty->reveal(), null, 'webspace', 'fr', null)->shouldBeCalled();
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }