Пример #1
0
 public function testResolve()
 {
     $this->contentTypeManager->get('content_type')->willReturn($this->contentType);
     $this->contentType->getViewData(Argument::any())->willReturn('view');
     $this->contentType->getContentData(Argument::any())->willReturn('content');
     $excerptExtension = $this->prophesize('Sulu\\Component\\Content\\Extension\\ExtensionInterface');
     $excerptExtension->getContentData(['test1' => 'test1'])->willReturn(['test1' => 'test1']);
     $this->structureManager->getExtension('test', 'excerpt')->willReturn($excerptExtension);
     $property = $this->prophesize('Sulu\\Component\\Content\\Compat\\PropertyInterface');
     $property->getName()->willReturn('property');
     $property->getContentTypeName()->willReturn('content_type');
     $structure = $this->prophesize('Sulu\\Component\\Content\\Compat\\Structure\\PageBridge');
     $structure->getKey()->willReturn('test');
     $structure->getExt()->willReturn(new ExtensionContainer(['excerpt' => ['test1' => 'test1']]));
     $structure->getUuid()->willReturn('some-uuid');
     $structure->getProperties(true)->willReturn([$property->reveal()]);
     $structure->getCreator()->willReturn(1);
     $structure->getChanger()->willReturn(1);
     $structure->getCreated()->willReturn('date');
     $structure->getChanged()->willReturn('date');
     $structure->getPublished()->willReturn('date');
     $structure->getPath()->willReturn('test-path');
     $structure->getUrls()->willReturn(['en' => '/description', 'de' => '/beschreibung', 'es' => null]);
     $structure->getShadowBaseLanguage()->willReturn('en');
     $expected = ['extension' => ['excerpt' => ['test1' => 'test1']], 'uuid' => 'some-uuid', 'view' => ['property' => 'view'], 'content' => ['property' => 'content'], 'creator' => 1, 'changer' => 1, 'created' => 'date', 'changed' => 'date', 'published' => 'date', 'template' => 'test', 'urls' => ['en' => '/description', 'de' => '/beschreibung', 'es' => null], 'path' => 'test-path', 'shadowBaseLocale' => 'en'];
     $this->assertEquals($expected, $this->structureResolver->resolve($structure->reveal()));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function export($contentTypeName, $propertyValue)
 {
     $contentType = $this->contentTypeManager->get($contentTypeName);
     if ($contentType instanceof ContentTypeExportInterface) {
         return $contentType->exportData($propertyValue);
     }
     return '';
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function hasImport($contentTypeName, $format)
 {
     $contentType = $this->contentTypeManager->get($contentTypeName);
     if ($contentType instanceof ContentTypeExportInterface) {
         return true;
     }
     return false;
 }
Пример #4
0
 protected function setUp()
 {
     parent::setUp();
     $this->contentTypeManager = $this->getMock('Sulu\\Component\\Content\\ContentTypeManager', ['get'], [], '', false);
     $this->blockContentType = new BlockContentType($this->contentTypeManager, 'not in use', 'i18n:');
     $this->contentTypeValueMap = [['text_line', new TextLine('not in use')], ['text_area', new TextArea('not in use')], ['block', $this->blockContentType]];
     $this->contentTypeManager->expects($this->any())->method('get')->will($this->returnValueMap($this->contentTypeValueMap));
 }
Пример #5
0
 protected function setUp()
 {
     parent::setUp();
     $this->contentMapper = $this->prophesize('Sulu\\Component\\Content\\Mapper\\ContentMapperInterface');
     $this->requestAnalyzer = $this->prophesize('Sulu\\Component\\Webspace\\Analyzer\\RequestAnalyzerInterface');
     $this->contentTypeManager = $this->prophesize('Sulu\\Component\\Content\\ContentTypeManagerInterface');
     $this->structureManager = $this->prophesize('Sulu\\Component\\Content\\Compat\\StructureManagerInterface');
     $this->sessionManager = $this->prophesize('Sulu\\Component\\PHPCR\\SessionManager\\SessionManagerInterface');
     $this->session = $this->prophesize('PHPCR\\SessionInterface');
     $this->node = $this->prophesize('PHPCR\\NodeInterface');
     $this->parentNode = $this->prophesize('PHPCR\\NodeInterface');
     $this->startPageNode = $this->prophesize('PHPCR\\NodeInterface');
     $webspace = new Webspace();
     $webspace->setKey('sulu_test');
     $locale = new Localization();
     $locale->setCountry('us');
     $locale->setLanguage('en');
     $this->requestAnalyzer->getWebspace()->willReturn($webspace);
     $this->requestAnalyzer->getCurrentLocalization()->willReturn($locale);
     $this->contentTypeManager->get('text_line')->willReturn(new TextLine(''));
     $this->sessionManager->getSession()->willReturn($this->session->reveal());
     $this->sessionManager->getContentNode('sulu_test')->willReturn($this->startPageNode->reveal());
     $this->session->getNodeByIdentifier('123-123-123')->willReturn($this->node->reveal());
     $this->session->getNodeByIdentifier('321-321-321')->willReturn($this->parentNode->reveal());
     $this->node->getIdentifier()->willReturn('123-123-123');
     $this->node->getParent()->willReturn($this->parentNode->reveal());
     $this->node->getDepth()->willReturn(4);
     $this->parentNode->getIdentifier()->willReturn('321-321-321');
     $this->parentNode->getDepth()->willReturn(3);
     $this->startPageNode->getDepth()->willReturn(3);
     $this->structureResolver = new StructureResolver($this->contentTypeManager->reveal(), $this->structureManager->reveal());
 }
Пример #6
0
 /**
  * {@inheritDoc}
  */
 public function resolve(StructureInterface $structure)
 {
     $data = ['view' => [], 'content' => [], 'uuid' => $structure->getUuid(), 'creator' => $structure->getCreator(), 'changer' => $structure->getChanger(), 'created' => $structure->getCreated(), 'changed' => $structure->getChanged(), 'template' => $structure->getKey(), 'path' => $structure->getPath()];
     if ($structure instanceof PageBridge) {
         $data['extension'] = $structure->getExt()->toArray();
         $data['urls'] = $structure->getUrls();
         $data['published'] = $structure->getPublished();
         $data['shadowBaseLocale'] = $structure->getShadowBaseLanguage();
         foreach ($data['extension'] as $name => $value) {
             $extension = $this->structureManager->getExtension($structure->getKey(), $name);
             $data['extension'][$name] = $extension->getContentData($value);
         }
     }
     foreach ($structure->getProperties(true) as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $data['view'][$property->getName()] = $contentType->getViewData($property);
         $data['content'][$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function import(NodeInterface $node, $data, $webspaceKey, $languageCode, $format)
 {
     $this->setLanguageCode($languageCode, 'i18n', null);
     foreach ($this->getExcerptStructure()->getProperties() as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         if (isset($data[$property->getName()]) && $this->contentImportManager->hasImport($property->getContentTypeName(), $format)) {
             /** @var ContentTypeExportInterface $contentType */
             $contentType->importData($node, new TranslatedProperty($property, $languageCode, $this->languageNamespace, $this->additionalPrefix), $data[$property->getName()], null, $webspaceKey, $languageCode, null);
         }
     }
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function getContentData($container)
 {
     $container = new ExcerptValueContainer($container);
     $data = [];
     foreach ($this->getExcerptStructure()->getProperties() as $property) {
         if ($container->__isset($property->getName())) {
             $property->setValue($container->__get($property->getName()));
             $contentType = $this->contentTypeManager->get($property->getContentTypeName());
             $data[$property->getName()] = $contentType->getContentData($property);
         }
     }
     return $data;
 }
Пример #9
0
 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());
 }
Пример #10
0
 /**
  * {@inheritDoc}
  */
 public function getContentViewProperty($name)
 {
     if (isset($this->propertyValues[$name])) {
         return $this->propertyValues[$name];
     }
     // initialize the legacy property
     $this->getProperty($name);
     $legacyProperty = $this->legacyProperties[$name];
     $structureProperty = $this->structureMetadata->getProperty($name);
     $contentTypeName = $structureProperty->getType();
     $contentType = $this->contentTypeManager->get($contentTypeName);
     $propertyValue = new PropertyValue($name, $contentType->getContentData($legacyProperty));
     $this->propertyValues[$name] = $propertyValue;
     return $propertyValue;
 }
Пример #11
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);
     }
 }
Пример #12
0
 /**
  * Sets the given data in the given content (including webspace and language) and returns sequence information.
  */
 private function setValue(StructureInterface $content, $property, $data, $webspaceKey, $languageCode)
 {
     if (false !== ($sequence = $this->crawler->getSequence($content, $property))) {
         $tmp = $data;
         $data = $sequence['property']->getValue();
         $value =& $data;
         $len = count($sequence['index']);
         for ($i = 0; $i < $len; ++$i) {
             $value =& $value[$sequence['index'][$i]];
         }
         $value = $tmp;
         $instance = $sequence['property'];
     } else {
         if (!$content->hasProperty($property)) {
             return $sequence;
         }
         $instance = $content->getProperty($property);
     }
     $contentType = $this->contentTypeManager->get($instance->getContentTypeName());
     $contentType->readForPreview($data, $instance, $webspaceKey, $languageCode, null);
     return $sequence;
 }
Пример #13
0
 /**
  * adopts resource locator of children by iteration.
  *
  * @param NodeInterface $contentNode
  * @param int           $userId
  * @param string        $webspaceKey
  * @param string        $languageCode
  * @param bool          $iterate
  * @param string        $segmentKey
  */
 private function adaptResourceLocators(NodeInterface $contentNode, $userId, $webspaceKey, $languageCode, $segmentKey = null, $iterate = true)
 {
     foreach ($contentNode->getNodes() as $node) {
         // determine structure
         $templatePropertyName = $this->nodeHelper->getTranslatedPropertyName('template', $languageCode);
         if (!$node->hasProperty($templatePropertyName)) {
             continue;
         }
         $template = $node->getPropertyValue($templatePropertyName);
         $structure = $this->structureManager->getStructure($template);
         // only if rlp exists
         if ($structure->hasTag('sulu.rlp')) {
             // get rlp
             try {
                 $rlp = $this->loadByContent($node, $webspaceKey, $languageCode);
             } catch (ResourceLocatorNotFoundException $ex) {
                 $contentNode->getSession()->save();
                 $rlpPart = $node->getPropertyValue($this->nodeHelper->getTranslatedPropertyName('title', $languageCode));
                 $prentRlp = $this->mapper->getParentPath($node->getIdentifier(), $webspaceKey, $languageCode, $segmentKey);
                 // generate new resourcelocator
                 $rlp = $this->generate($rlpPart, $prentRlp, $webspaceKey, $languageCode);
             }
             // determine rlp property
             $property = $structure->getPropertyByTagName('sulu.rlp');
             $contentType = $this->contentTypeManager->get($property->getContentTypeName());
             $property->setValue($rlp);
             // write value to node
             $translatedProperty = $this->nodeHelper->getTranslatedProperty($property, $languageCode);
             $contentType->write($node, $translatedProperty, $userId, $webspaceKey, $languageCode, $segmentKey);
         }
         // for node move the tree will be copied to then there is the iteration over this function
         // for node copy the iteration is done by the content-type which calls over the move function
         //     recursively this function
         if ($iterate) {
             $this->adaptResourceLocators($node, $userId, $webspaceKey, $languageCode, $segmentKey);
         }
     }
 }
Пример #14
0
 /**
  * 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());
 }
Пример #15
0
 /**
  * Returns prepared data from property
  * use callback to prepare data foreach property function($contentType, $property).
  *
  * @param PropertyInterface $property
  * @param callable          $dataCallback
  * @param bool              $returnType
  *
  * @return array
  */
 private function prepareData(PropertyInterface $property, callable $dataCallback, $returnType = true)
 {
     /** @var BlockPropertyInterface $blockProperty */
     $blockProperty = $property;
     while (!$blockProperty instanceof BlockPropertyInterface) {
         $blockProperty = $blockProperty->getProperty();
     }
     $data = [];
     for ($i = 0; $i < $blockProperty->getLength(); ++$i) {
         $blockPropertyType = $blockProperty->getProperties($i);
         if ($returnType) {
             $type = $blockPropertyType->getName();
             $data[$i] = ['type' => $type];
         }
         foreach ($blockPropertyType->getChildProperties() as $childProperty) {
             $contentType = $this->contentTypeManager->get($childProperty->getContentTypeName());
             $data[$i][$childProperty->getName()] = $dataCallback($contentType, $childProperty);
         }
     }
     if (!$property->getIsMultiple() && count($data) > 0) {
         $data = $data[0];
     }
     return $data;
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function load(NodeInterface $node, $webspaceKey, $languageCode)
 {
     $data = [];
     foreach ($this->excerptStructure->getProperties() as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $contentType->read($node, new TranslatedProperty($property, $languageCode . '-' . $this->additionalPrefix, $this->languageNamespace), $webspaceKey, $languageCode, null);
         $data[$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
Пример #17
0
 /**
  * Returns content type with given name.
  *
  * @param $name string
  *
  * @return ContentTypeInterface
  */
 public function getTypeFunction($name)
 {
     return $this->contentTypeManager->get($name);
 }