diff --git a/Api/Data/BlockEntryInterface.php b/Api/Data/BlockEntryInterface.php index 4cf070a..32a05a6 100644 --- a/Api/Data/BlockEntryInterface.php +++ b/Api/Data/BlockEntryInterface.php @@ -7,4 +7,5 @@ interface BlockEntryInterface extends BlockInterface, EntryInterface { + } diff --git a/Api/ExportInterface.php b/Api/ExportInterface.php new file mode 100644 index 0000000..07dc179 --- /dev/null +++ b/Api/ExportInterface.php @@ -0,0 +1,16 @@ +getAllBlockEntries = $getAllBlockEntries; + + $this->getAllBlockEntries = $getAllBlockEntries; $this->getBlocksByBlockEntry = $getBlocksByBlockEntry; } diff --git a/Console/ExportCommand.php b/Console/ExportCommand.php new file mode 100644 index 0000000..43b3c10 --- /dev/null +++ b/Console/ExportCommand.php @@ -0,0 +1,94 @@ +entryBuilder = $entryBuilder; + $this->exportToModuleFactory = $exportToModuleFactory; + $this->exportToVarFactory = $exportToVarFactory; + $this->export = $export; + } + + /** + * @inheritdoc + */ + protected function configure() + { + parent::configure(); + } + + /** + * {@inheritdoc} + * @throws NotFoundException + * @throws InputException + * @throws LocalizedException + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $moduleName = $input->getArgument('module'); + $cmsType = $input->getArgument('cms_type'); + $identifier = $input->getArgument('identifier'); + + switch ($input->getArgument('strategy')) { + case 'var': + $strategy = $this->exportToVarFactory->create(['data' => ['moduleName' => $moduleName]]); + break; + default: + $strategy = $this->exportToModuleFactory->create(['data' => ['moduleName' => $moduleName]]); + } + + $entry = $this->entryBuilder->build($cmsType, $identifier); + $this->export->execute($strategy, $entry); + } +} diff --git a/Model/Console/PageListCommand.php b/Console/PageListCommand.php similarity index 90% rename from Model/Console/PageListCommand.php rename to Console/PageListCommand.php index d4e95a9..72e5e37 100644 --- a/Model/Console/PageListCommand.php +++ b/Console/PageListCommand.php @@ -1,7 +1,7 @@ getAllContentEntries = $getAllContentEntries; - $this->getPagesByPageEntry = $getPagesByPageEntry; + $this->getPagesByPageEntry = $getPagesByPageEntry; } /** diff --git a/Model/Builder/Block.php b/Model/Builder/Block.php new file mode 100644 index 0000000..b0124ed --- /dev/null +++ b/Model/Builder/Block.php @@ -0,0 +1,55 @@ +blockRepository = $blockRepository; + $this->blockEntryInterfaceFactory = $blockEntryInterfaceFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @param string $identifier + * @return BlockEntryInterface + * @throws LocalizedException + */ + public function build(string $identifier): BlockEntryInterface + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter('identifier', $identifier, 'eq') + ->create(); + + /** @var BlockInterface|MageCmsBlock $block */ + $block = $this->blockRepository->getList($searchCriteria); + + return $this->blockEntryInterfaceFactory->create(['data' => $block->getData()]); + } +} \ No newline at end of file diff --git a/Model/Builder/Page.php b/Model/Builder/Page.php new file mode 100644 index 0000000..12730d8 --- /dev/null +++ b/Model/Builder/Page.php @@ -0,0 +1,55 @@ +pageRepository = $pageRepository; + $this->pageEntryInterfaceFactory = $pageEntryInterfaceFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @param string $identifier + * @return PageEntryInterface + * @throws LocalizedException + */ + public function build(string $identifier): PageEntryInterface + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter('identifier', $identifier, 'eq') + ->create(); + + /** @var PageInterface|MageCmsPage $page */ + $page = array_shift($this->pageRepository->getList($searchCriteria)->getItems()); + + return $this->pageEntryInterfaceFactory->create(['data' => $page->getData()]); + } +} \ No newline at end of file diff --git a/Model/Command/ExportEntry.php b/Model/Command/ExportEntry.php new file mode 100644 index 0000000..c62665b --- /dev/null +++ b/Model/Command/ExportEntry.php @@ -0,0 +1,50 @@ +generateConfig = $generateConfig; + $this->parseConfigurationFile = $parseConfigurationFile; + } + + /** + * @inheritdoc + */ + public function execute(StrategyInterface $strategy, EntryInterface $entry): void + { + if (($entry instanceof BlockEntryInterface) || ($entry instanceof PageEntryInterface)) { + $entry->setMediaDirectory($strategy->getMediaNamespacePath()); + } + + $xml = $this->parseConfigurationFile->execute($strategy); + + $this->generateConfig->execute($xml, [$entry]); + $xml->asXML($strategy->getXmlPath()); + } +} \ No newline at end of file diff --git a/Model/Command/ParseConfigurationFile.php b/Model/Command/ParseConfigurationFile.php new file mode 100644 index 0000000..91f9a79 --- /dev/null +++ b/Model/Command/ParseConfigurationFile.php @@ -0,0 +1,20 @@ +getXmlPath())) { + $xml = new SimpleXMLElement("");; + $xml->saveXML($strategy->getXmlPath()); + } + + return new SimpleXMLElement($strategy->getXmlPath(), 0, true); + } +} \ No newline at end of file diff --git a/Model/Config/Generator.php b/Model/Config/Generator.php new file mode 100644 index 0000000..250e706 --- /dev/null +++ b/Model/Config/Generator.php @@ -0,0 +1,48 @@ +blockGeneratorChain = $blockGeneratorChain; + $this->pageGeneratorChain = $pageGeneratorChain; + } + + /** + * @param SimpleXMLElement $xml + * @param EntryInterface[] $entries + * + * @return void + */ + public function execute(SimpleXMLElement $xml, array $entries): void + { + foreach ($entries as $entry) { + if ($entry instanceof PageEntryInterface) { + $this->pageGeneratorChain->execute($entry, $xml); + } + if ($entry instanceof BlockEntryInterface) { + $this->blockGeneratorChain->execute($entry, $xml); + } + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/BlockNodeGenerator.php b/Model/Config/Generator/BlockNodeGenerator.php new file mode 100644 index 0000000..534facf --- /dev/null +++ b/Model/Config/Generator/BlockNodeGenerator.php @@ -0,0 +1,55 @@ +castBooleanValue = $castBooleanValue; + $this->getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageInterface|BlockInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $node = $this->getNodeByKey->execute($xml, $entry->getKey()); + if ($node) { + $dom = dom_import_simplexml($node); + $dom->parentNode->removeChild($dom); + } + + $childNode = $xml->addChild('block'); + $childNode->addAttribute('key', $entry->getKey()); + $childNode->addAttribute('identifier', $entry->getIdentifier()); + $childNode->addAttribute('active', $this->castBooleanValue->execute($entry->isActive())); + $childNode->addAttribute('maintained', $this->castBooleanValue->execute($entry->isMaintained())); + } +} \ No newline at end of file diff --git a/Model/Config/Generator/Cast/BooleanValue.php b/Model/Config/Generator/Cast/BooleanValue.php new file mode 100644 index 0000000..d0c34c2 --- /dev/null +++ b/Model/Config/Generator/Cast/BooleanValue.php @@ -0,0 +1,20 @@ +getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageEntryInterface|BlockEntryInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $entryNode = $this->getNodeByKey->execute($xml, $entry->getKey()); + if (!$entryNode) { + return; + } + + $node = $entryNode->addChild('content', $entry->getContent()); + if ($entry instanceof PageEntryInterface) { + $node->addAttribute('heading', $entry->getContentHeading()); + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/CustomDesignGenerator.php b/Model/Config/Generator/CustomDesignGenerator.php new file mode 100644 index 0000000..3b93790 --- /dev/null +++ b/Model/Config/Generator/CustomDesignGenerator.php @@ -0,0 +1,63 @@ +getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageEntryInterface|BlockEntryInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $entryNode = $this->getNodeByKey->execute($xml, $entry->getKey()); + if (!$entryNode) { + return; + } + + $customThemeFrom = $entry->getCustomThemeFrom(); + $customThemeTo = $entry->getCustomThemeTo(); + $customTheme = $entry->getCustomTheme(); + $customNewLayout = $entry->getCustomRootTemplate(); + + if (!$customThemeFrom && !$customThemeTo && !$customTheme && !$customNewLayout) { + return; + } + + $nodeCustomDesign = $entryNode->addChild('custom_design'); + + if ($customThemeFrom) { + $nodeCustomDesign->addChild('from', $customThemeFrom); + } + if ($customThemeTo) { + $nodeCustomDesign->addChild('to', $customThemeTo); + } + if ($customNewLayout) { + $nodeCustomDesign->addChild('layout', $customNewLayout); + } + if ($customTheme) { + $nodeCustomDesign->addChild('theme_id', (string) $customTheme); + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/DesignGenerator.php b/Model/Config/Generator/DesignGenerator.php new file mode 100644 index 0000000..d9cc170 --- /dev/null +++ b/Model/Config/Generator/DesignGenerator.php @@ -0,0 +1,48 @@ +getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageEntryInterface|BlockEntryInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $entryNode = $this->getNodeByKey->execute($xml, $entry->getKey()); + if (!$entryNode) { + return; + } + + $nodeDesign = $entryNode->addChild('design'); + + if ($layout = $entry->getPageLayout()) { + $nodeDesign->addChild('layout', $layout); + } + if ($layoutUpdateXml = $entry->getLayoutUpdateXml()) { + $nodeDesign->addChild('layout_xml', $layoutUpdateXml); + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/GeneratorChain.php b/Model/Config/Generator/GeneratorChain.php new file mode 100644 index 0000000..6df3660 --- /dev/null +++ b/Model/Config/Generator/GeneratorChain.php @@ -0,0 +1,48 @@ + GeneratorInterface::class] + )); + } + } + + $this->generatorList = $generatorList; + } + + /** + * @param EntryInterface|PageInterface|BlockInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + foreach ($this->generatorList as $generator) { + $generator->execute($entry, $xml); + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/GeneratorInterface.php b/Model/Config/Generator/GeneratorInterface.php new file mode 100644 index 0000000..d34dc08 --- /dev/null +++ b/Model/Config/Generator/GeneratorInterface.php @@ -0,0 +1,12 @@ +castBooleanValue = $castBooleanValue; + $this->getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageInterface|BlockInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $node = $this->getNodeByKey->execute($xml, $entry->getKey()); + if ($node) { + $dom = dom_import_simplexml($node); + $dom->parentNode->removeChild($dom); + } + + $childNode = $xml->addChild('page'); + $childNode->addAttribute('key', $entry->getKey()); + $childNode->addAttribute('identifier', $entry->getIdentifier()); + $childNode->addAttribute('active', $this->castBooleanValue->execute($entry->isActive())); + $childNode->addAttribute('maintained', $this->castBooleanValue->execute($entry->isMaintained())); + } +} \ No newline at end of file diff --git a/Model/Config/Generator/Query/GetNodeByKey.php b/Model/Config/Generator/Query/GetNodeByKey.php new file mode 100644 index 0000000..91136f5 --- /dev/null +++ b/Model/Config/Generator/Query/GetNodeByKey.php @@ -0,0 +1,19 @@ +xpath("(page|block)[@key='" . $key . "']"); + if ($nodes) { + $node = array_shift($nodes); + } + + return $node ?? null; + } +} \ No newline at end of file diff --git a/Model/Config/Generator/SeoGenerator.php b/Model/Config/Generator/SeoGenerator.php new file mode 100644 index 0000000..ce81c77 --- /dev/null +++ b/Model/Config/Generator/SeoGenerator.php @@ -0,0 +1,59 @@ +getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageEntryInterface|BlockEntryInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $entryNode = $this->getNodeByKey->execute($xml, $entry->getKey()); + if (!$entryNode) { + return; + } + + $seoTitle = $entry->getMetaTitle(); + $seoKeywords = $entry->getMetaKeywords(); + $seoDescription = $entry->getMetaDescription(); + + if (!$seoTitle && !$seoKeywords && !$seoDescription) { + return; + } + + $nodeCustomDesign = $entryNode->addChild('seo'); + + if ($seoTitle) { + $nodeCustomDesign->addChild('title', $seoTitle); + } + if ($seoKeywords) { + $nodeCustomDesign->addChild('keywords', $seoKeywords); + } + if ($seoDescription) { + $nodeCustomDesign->addChild('description', $seoDescription); + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/StoresGenerator.php b/Model/Config/Generator/StoresGenerator.php new file mode 100644 index 0000000..8aeeecf --- /dev/null +++ b/Model/Config/Generator/StoresGenerator.php @@ -0,0 +1,45 @@ +getNodeByKey = $getNodeByKey; + $this->storeCodesByStoreIdsResolver = $storeCodesByStoreIdsResolver; + } + + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $nodeEntry = $this->getNodeByKey->execute($xml, $entry->getKey()); + + if (!$nodeEntry) { + return; + } + + $nodeStores = $nodeEntry->addChild('stores'); + + foreach ($this->storeCodesByStoreIdsResolver->execute($entry->getStores()) as $storeCode) { + $nodeStore = $nodeStores->addChild('store'); + $nodeStore->addAttribute('code', $storeCode); + } + } +} \ No newline at end of file diff --git a/Model/Config/Generator/TitleGenerator.php b/Model/Config/Generator/TitleGenerator.php new file mode 100644 index 0000000..4bec788 --- /dev/null +++ b/Model/Config/Generator/TitleGenerator.php @@ -0,0 +1,41 @@ +getNodeByKey = $getNodeByKey; + } + + /** + * @param EntryInterface|PageEntryInterface|BlockEntryInterface $entry + * @param SimpleXMLElement $xml + */ + public function execute(EntryInterface $entry, SimpleXMLElement $xml): void + { + $entryNode = $this->getNodeByKey->execute($xml, $entry->getKey()); + if (!$entryNode) { + return; + } + + $entryNode->addChild('title', $entry->getTitle()); + } +} \ No newline at end of file diff --git a/Model/EntryBuilder.php b/Model/EntryBuilder.php new file mode 100644 index 0000000..9f2f3c1 --- /dev/null +++ b/Model/EntryBuilder.php @@ -0,0 +1,48 @@ +pageBuilder = $pageBuilder; + $this->blockBuilder = $blockBuilder; + } + + /** + * @param string $cmsType + * @param string $identifier + * @return EntryInterface + * @throws InputException + * @throws LocalizedException + */ + public function build(string $cmsType, string $identifier): EntryInterface + { + switch ($cmsType) { + case 'page': + return $this->pageBuilder->build($identifier); + case 'block': + return $this->blockBuilder->build($identifier); + default: + throw new InputException(__('Cms Type: %cms_type not found.', ['cms_type' => $cmsType])); + } + } +} \ No newline at end of file diff --git a/Model/Resolver/PathResolver.php b/Model/Resolver/PathResolver.php index 8d67b80..a28c9b7 100644 --- a/Model/Resolver/PathResolver.php +++ b/Model/Resolver/PathResolver.php @@ -3,9 +3,6 @@ namespace Firegento\ContentProvisioning\Model\Resolver; -use DOMElement; -use Firegento\ContentProvisioning\Api\ContentResolverInterface; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem\DirectoryList; use Magento\Framework\Module\Dir\Reader; diff --git a/Model/Resolver/StoreCodesByStoreIdsResolver.php b/Model/Resolver/StoreCodesByStoreIdsResolver.php new file mode 100644 index 0000000..e6de0a6 --- /dev/null +++ b/Model/Resolver/StoreCodesByStoreIdsResolver.php @@ -0,0 +1,39 @@ +storeManager = $storeManager; + } + + /** + * @param int[] $storeIds + * @return string[] + * @throws NoSuchEntityException + */ + public function execute(array $storeIds): array + { + $storeCodes = []; + foreach ($storeIds as $storeId) { + $storeCodes[] = $this->storeManager->getStore($storeId)->getCode(); + } + return $storeCodes; + } +} \ No newline at end of file diff --git a/Model/Strategy/ExportToModule.php b/Model/Strategy/ExportToModule.php index 489ec21..e404194 100644 --- a/Model/Strategy/ExportToModule.php +++ b/Model/Strategy/ExportToModule.php @@ -4,15 +4,78 @@ namespace Firegento\ContentProvisioning\Model\Strategy; use Firegento\ContentProvisioning\Api\StrategyInterface; +use Magento\Framework\Module\Dir\Reader; class ExportToModule implements StrategyInterface { + /** + * @var string + */ + private $moduleName; + + /** + * @var Reader + */ + private $moduleReader; + + /** + * @param string $moduleName + * @param Reader $moduleReader + */ + public function __construct( + string $moduleName, + Reader $moduleReader + ) { + $this->moduleName = $moduleName; + $this->moduleReader = $moduleReader; + } + + /** + * @return string + */ + public function getXmlPath(): string + { + return implode(DIRECTORY_SEPARATOR, [ + $this->moduleReader->getModuleDir('etc', $this->moduleName), + 'content_provisioning.xml' + ]); + } + + /** + * @return string + */ + public function getContentDirectoryPath(): string + { + return implode(DIRECTORY_SEPARATOR, [ + $this->moduleReader->getModuleDir('', $this->moduleName), + 'content' + ]); + } + + /** + * @return string + */ + public function getMediaDirectoryPath(): string + { + return implode(DIRECTORY_SEPARATOR, [ + $this->getContentDirectoryPath(), + 'media' + ]); + } + + /** + * @return string + */ + public function getContentNamespacePath(): string + { + return $this->moduleName . '::content'; + } /** * @return string */ - public function getTargetPath(): string + public function getMediaNamespacePath(): string { - // TODO: Implement getTargetPath() method. + return $this->moduleName . '::content/media'; } } diff --git a/Model/Strategy/ExportToVar.php b/Model/Strategy/ExportToVar.php index 8907332..b6d870f 100644 --- a/Model/Strategy/ExportToVar.php +++ b/Model/Strategy/ExportToVar.php @@ -4,15 +4,86 @@ namespace Firegento\ContentProvisioning\Model\Strategy; use Firegento\ContentProvisioning\Api\StrategyInterface; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Exception\FileSystemException; class ExportToVar implements StrategyInterface { + /** + * @var string + */ + private $moduleName; + + /** + * @var DirectoryList + */ + private $directoryList; + + /** + * @param string $moduleName + * @param DirectoryList $directoryList + */ + public function __construct( + string $moduleName, + DirectoryList $directoryList + ) { + $this->moduleName = $moduleName; + $this->directoryList = $directoryList; + } + + /** + * @return string + * @throws FileSystemException + */ + public function getXmlPath(): string + { + return implode(DIRECTORY_SEPARATOR, [ + $this->directoryList->getPath(DirectoryList::VAR_DIR), + 'content_provisioning', + $this->moduleName, + 'content_provisioning.xml' + ]); + } + + /** + * @return string + * @throws FileSystemException + */ + public function getContentDirectoryPath(): string + { + return implode(DIRECTORY_SEPARATOR, [ + $this->directoryList->getPath(DirectoryList::VAR_DIR), + 'content_provisioning', + $this->moduleName, + 'content' + ]); + } + + /** + * @return string + * @throws FileSystemException + */ + public function getMediaDirectoryPath(): string + { + return implode(DIRECTORY_SEPARATOR, [ + $this->getContentDirectoryPath(), + 'media' + ]); + } + + /** + * @return string + */ + public function getContentNamespacePath(): string + { + return $this->moduleName . '::content'; + } /** * @return string */ - public function getTargetPath(): string + public function getMediaNamespacePath(): string { - // TODO: Implement getTargetPath() method. + return $this->moduleName . '::content/media'; } } diff --git a/Model/Strategy/Provider.php b/Model/Strategy/Provider.php deleted file mode 100644 index 25698df..0000000 --- a/Model/Strategy/Provider.php +++ /dev/null @@ -1,52 +0,0 @@ - StrategyInterface::class] - )); - } - } - $this->strategies = $strategies; - } - - /** - * @param string $strategyCode - * @return StrategyInterface - * - * @throws NotFoundException - */ - public function get(string $strategyCode): StrategyInterface - { - $strategy = $this->strategies[$strategyCode] ?? null; - - if (!$strategy) { - throw new NotFoundException(__('Strategy %strategy_code not found.', ['strategy_code' => $strategyCode])); - } - - return $strategy; - } -} diff --git a/Test/Integration/Model/Config/_files/content_provisioning.xml b/Test/Integration/Model/Config/_files/content_provisioning.xml deleted file mode 100644 index 4affb24..0000000 --- a/Test/Integration/Model/Config/_files/content_provisioning.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - Test Page 1 - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/file-1.html - - - Title 2 - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/file-1.html - - - - - - SEO Page Title - Some, SEO, keywords - SEO description - - - 3columns - bar]]> - - - 2019-03-03 - 2019-03-29 - 3columns - 3 - - - - Page With Images - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/content-with-images-1.html - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/media - - - Test Block 1 - test foobar Aenean commodo ligula eget dolor aenean massa]]> - - - Test Block 2 - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/file-1.html - - - - - - - Block With Images - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/content-with-images-1.html - Firegento_ContentProvisioning::Test/Integration/Model/Config/_files/test-files/media - - \ No newline at end of file diff --git a/Test/Integration/Model/Config/_files/result.php b/Test/Integration/Model/Config/_files/result.php deleted file mode 100644 index 5f2fdf3..0000000 --- a/Test/Integration/Model/Config/_files/result.php +++ /dev/null @@ -1,97 +0,0 @@ - [ - 'test.page.1' => [ - PageEntryInterface::TITLE => 'Test Page 1', - PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/test-files/file-1.html'), - PageEntryInterface::KEY => 'test.page.1', - PageEntryInterface::IDENTIFIER => 'test-page-1', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['admin'], - PageEntryInterface::CONTENT_HEADING => '', - PageEntryInterface::MEDIA_DIRECTORY => null, - PageEntryInterface::MEDIA_FILES => [], - ], - 'test.page.2' => [ - PageEntryInterface::TITLE => 'Title 2', - PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/test-files/file-1.html'), - PageEntryInterface::KEY => 'test.page.2', - PageEntryInterface::IDENTIFIER => 'test-page-2', - PageEntryInterface::IS_ACTIVE => false, - PageEntryInterface::IS_MAINTAINED => false, - PageEntryInterface::STORES => ['default', 'admin'], - PageEntryInterface::CONTENT_HEADING => 'New Page Heading 2', - PageEntryInterface::META_TITLE => 'SEO Page Title', - PageEntryInterface::META_KEYWORDS => 'Some, SEO, keywords', - PageEntryInterface::META_DESCRIPTION => 'SEO description', - PageEntryInterface::PAGE_LAYOUT => '3columns', - PageEntryInterface::LAYOUT_UPDATE_XML => 'bar', - PageEntryInterface::CUSTOM_THEME_FROM => '2019-03-03', - PageEntryInterface::CUSTOM_THEME_TO => '2019-03-29', - PageEntryInterface::CUSTOM_THEME => '3', - PageEntryInterface::CUSTOM_ROOT_TEMPLATE => '3columns', - PageEntryInterface::MEDIA_DIRECTORY => null, - PageEntryInterface::MEDIA_FILES => [], - ], - 'test.page.3' => [ - PageEntryInterface::TITLE => 'Page With Images', - PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/test-files/content-with-images-1.html'), - PageEntryInterface::KEY => 'test.page.3', - PageEntryInterface::IDENTIFIER => 'test-page-3', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['admin'], - PageEntryInterface::CONTENT_HEADING => '', - PageEntryInterface::MEDIA_DIRECTORY => __DIR__ . '/test-files/media', - PageEntryInterface::MEDIA_FILES => [ - 'image-1.png', - 'some-test-image.png', - 'foobar/test.png', - ], - ] - ], - 'blocks' => [ - 'test.block.1' => [ - BlockEntryInterface::TITLE => 'Test Block 1', - BlockEntryInterface::CONTENT => '

test foobar Aenean commodo ligula eget dolor aenean massa

', - BlockEntryInterface::KEY => 'test.block.1', - BlockEntryInterface::IDENTIFIER => 'test-block-1', - BlockEntryInterface::IS_ACTIVE => true, - BlockEntryInterface::IS_MAINTAINED => true, - BlockEntryInterface::STORES => ['admin'], - BlockEntryInterface::MEDIA_DIRECTORY => null, - BlockEntryInterface::MEDIA_FILES => [], - ], - 'test.block.2' => [ - BlockEntryInterface::TITLE => 'Test Block 2', - BlockEntryInterface::CONTENT => file_get_contents(__DIR__ . '/test-files/file-1.html'), - BlockEntryInterface::KEY => 'test.block.2', - BlockEntryInterface::IDENTIFIER => 'test-block-2', - BlockEntryInterface::IS_ACTIVE => true, - BlockEntryInterface::IS_MAINTAINED => false, - BlockEntryInterface::STORES => ['default', 'admin'], - BlockEntryInterface::MEDIA_DIRECTORY => null, - BlockEntryInterface::MEDIA_FILES => [], - ], - 'test.block.3' => [ - BlockEntryInterface::TITLE => 'Block With Images', - BlockEntryInterface::CONTENT => file_get_contents(__DIR__ . '/test-files/content-with-images-1.html'), - BlockEntryInterface::KEY => 'test.block.3', - BlockEntryInterface::IDENTIFIER => 'test-block-3', - BlockEntryInterface::IS_ACTIVE => true, - BlockEntryInterface::IS_MAINTAINED => true, - BlockEntryInterface::STORES => ['admin'], - BlockEntryInterface::MEDIA_DIRECTORY => __DIR__ . '/test-files/media', - BlockEntryInterface::MEDIA_FILES => [ - 'image-1.png', - 'some-test-image.png', - 'foobar/test.png', - ], - ], - ], -]; diff --git a/Test/Integration/Model/Config/_files/test-files/content-with-images-1.html b/Test/Integration/Model/Config/_files/test-files/content-with-images-1.html deleted file mode 100644 index dc3c06d..0000000 --- a/Test/Integration/Model/Config/_files/test-files/content-with-images-1.html +++ /dev/null @@ -1,5 +0,0 @@ -
Some foobar
-

Foobar: Link zu einem Bilder

-

Dummy content...

-

Image: fooo

-

Image 2: 

\ No newline at end of file diff --git a/Test/Integration/Model/Config/_files/test-files/file-1.html b/Test/Integration/Model/Config/_files/test-files/file-1.html deleted file mode 100644 index 38c9499..0000000 --- a/Test/Integration/Model/Config/_files/test-files/file-1.html +++ /dev/null @@ -1,3 +0,0 @@ -

- Some test page content -

\ No newline at end of file diff --git a/Test/Integration/Model/Config/_files/test-files/media/foobar/test.png b/Test/Integration/Model/Config/_files/test-files/media/foobar/test.png deleted file mode 100644 index 9a5de74..0000000 Binary files a/Test/Integration/Model/Config/_files/test-files/media/foobar/test.png and /dev/null differ diff --git a/Test/Integration/Model/Config/_files/test-files/media/image-1.png b/Test/Integration/Model/Config/_files/test-files/media/image-1.png deleted file mode 100644 index ce2393e..0000000 Binary files a/Test/Integration/Model/Config/_files/test-files/media/image-1.png and /dev/null differ diff --git a/Test/Integration/Model/Config/_files/test-files/media/some-test-image.png b/Test/Integration/Model/Config/_files/test-files/media/some-test-image.png deleted file mode 100644 index aadbb12..0000000 Binary files a/Test/Integration/Model/Config/_files/test-files/media/some-test-image.png and /dev/null differ diff --git a/Test/Integration/Model/Export/BlockExportTestCase.php b/Test/Integration/Model/Export/BlockExportTestCase.php new file mode 100644 index 0000000..3d6491e --- /dev/null +++ b/Test/Integration/Model/Export/BlockExportTestCase.php @@ -0,0 +1,61 @@ +export = Bootstrap::getObjectManager() + ->create(ExportInterface::class); + + /** @var BlockEntryInterfaceFactory $blockEntryFactory */ + $this->blockEntryFactory = Bootstrap::getObjectManager() + ->create(BlockEntryInterfaceFactory::class); + + + $this->fileSystem = vfsStream::setup('root', null, [ + 'app' => [ + 'code' => [ + 'ModuleNamespace' => [ + 'CustomModule' => [ + 'etc' => [ + 'module.xml' => 'XML-Content...' + ], + 'registration.php' => 'PHP-Content...', + 'composer.json' => 'JSON-Content', + ] + ] + ] + ], + 'pub' => [ + 'media' => [ + 'existing' => [ + 'dummy-image.png' => '', + ], + 'image.jpg' => '', + ] + ], + ]); + } +} diff --git a/Test/Integration/Model/Export/ExportBlockEntryToModuleTest.php b/Test/Integration/Model/Export/ExportBlockEntryToModuleTest.php new file mode 100644 index 0000000..e4bddd2 --- /dev/null +++ b/Test/Integration/Model/Export/ExportBlockEntryToModuleTest.php @@ -0,0 +1,62 @@ +getMockBuilder(ExportToModule::class) + ->disableOriginalConstructor() + ->getMock(); + + $strategyMock->method('getXmlPath')->will($this->returnValue( + $this->fileSystem->getChild('app/code/ModuleNamespace/CustomModule')->url() . + '/etc/content_provisioning.xml' + )); + $strategyMock->method('getContentDirectoryPath')->will($this->returnValue( + $this->fileSystem->getChild('app/code/ModuleNamespace/CustomModule')->url() . + '/content' + )); + $strategyMock->method('getMediaDirectoryPath')->will($this->returnValue( + $this->fileSystem->getChild('app/code/ModuleNamespace/CustomModule')->url() . + '/content/media' + )); + $strategyMock->method('getContentNamespacePath')->will($this->returnValue( + 'ModuleNamespace_CustomModule::content' + )); + $strategyMock->method('getMediaNamespacePath')->will($this->returnValue( + 'ModuleNamespace_CustomModule::content/media' + )); + + $entry = $this->blockEntryFactory->create(['data' => [ + BlockEntryInterface::TITLE => 'Test Export Block 1', + BlockEntryInterface::CONTENT => '

test foobar Aenean commodo ligula eget dolor aenean massa

', + BlockEntryInterface::KEY => 'test.export.block.1', + BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-export-test-1', + BlockEntryInterface::IS_ACTIVE => false, + BlockEntryInterface::IS_MAINTAINED => true, + BlockEntryInterface::STORES => ['admin'], + ]]); + + $this->export->execute( + $strategyMock, + $entry + ); + + $targetXmlPath = 'app/code/ModuleNamespace/CustomModule/etc/content_provisioning.xml'; + $expectedXmlPath = __DIR__ . '/_files/export-block-entry-to-module.xml'; + $this->assertTrue($this->fileSystem->hasChild($targetXmlPath)); + $this->assertFileExists($this->fileSystem->getChild($targetXmlPath)->url()); + $this->assertXmlStringEqualsXmlString( + file_get_contents($expectedXmlPath), + file_get_contents($this->fileSystem->getChild($targetXmlPath)->url()) + ); + } +} diff --git a/Test/Integration/Model/Export/ExportPageEntryToModuleTest.php b/Test/Integration/Model/Export/ExportPageEntryToModuleTest.php new file mode 100644 index 0000000..3cd7995 --- /dev/null +++ b/Test/Integration/Model/Export/ExportPageEntryToModuleTest.php @@ -0,0 +1,72 @@ +getMockBuilder(ExportToModule::class) + ->disableOriginalConstructor() + ->getMock(); + + $strategyMock->method('getXmlPath')->will($this->returnValue( + $this->fileSystem->getChild('app/code/ModuleNamespace/CustomModule')->url() . + '/etc/content_provisioning.xml' + )); + $strategyMock->method('getContentDirectoryPath')->will($this->returnValue( + $this->fileSystem->getChild('app/code/ModuleNamespace/CustomModule')->url() . + '/content' + )); + $strategyMock->method('getMediaDirectoryPath')->will($this->returnValue( + $this->fileSystem->getChild('app/code/ModuleNamespace/CustomModule')->url() . + '/content/media' + )); + $strategyMock->method('getContentNamespacePath')->will($this->returnValue( + 'ModuleNamespace_CustomModule::content' + )); + $strategyMock->method('getMediaNamespacePath')->will($this->returnValue( + 'ModuleNamespace_CustomModule::content/media' + )); + + $entry = $this->pageEntryFactory->create(['data' => [ + PageEntryInterface::TITLE => 'Test Page 1', + PageEntryInterface::CONTENT => '

test foobar Aenean commodo ligula eget dolor aenean massa

', + PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', + PageEntryInterface::KEY => 'test.page.1', + PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-1', + PageEntryInterface::IS_ACTIVE => false, + PageEntryInterface::IS_MAINTAINED => true, + PageEntryInterface::STORES => ['default', 'admin'], + PageEntryInterface::META_DESCRIPTION => 'Some seo description', + PageEntryInterface::META_KEYWORDS => 'Some, seo, keywords', + PageEntryInterface::META_TITLE => 'Seo title', + PageEntryInterface::PAGE_LAYOUT => '3columns', + PageEntryInterface::LAYOUT_UPDATE_XML => 'bar', + PageEntryInterface::CUSTOM_THEME => 3, + PageEntryInterface::CUSTOM_THEME_FROM => '2019-03-03', + PageEntryInterface::CUSTOM_THEME_TO => '2019-05-29', + PageEntryInterface::CUSTOM_ROOT_TEMPLATE => '3columns', + ]]); + + $this->export->execute( + $strategyMock, + $entry + ); + + $targetXmlPath = 'app/code/ModuleNamespace/CustomModule/etc/content_provisioning.xml'; + $expectedXmlPath = __DIR__ . '/_files/export-page-entry-to-module.xml'; + $this->assertTrue($this->fileSystem->hasChild($targetXmlPath)); + $this->assertFileExists($this->fileSystem->getChild($targetXmlPath)->url()); + $this->assertXmlStringEqualsXmlString( + file_get_contents($expectedXmlPath), + file_get_contents($this->fileSystem->getChild($targetXmlPath)->url()) + ); + } +} diff --git a/Test/Integration/Model/Export/PageExportTestCase.php b/Test/Integration/Model/Export/PageExportTestCase.php new file mode 100644 index 0000000..8fc457c --- /dev/null +++ b/Test/Integration/Model/Export/PageExportTestCase.php @@ -0,0 +1,61 @@ +export = Bootstrap::getObjectManager() + ->create(ExportInterface::class); + + /** @var PageEntryInterfaceFactory $blockEntryFactory */ + $this->pageEntryFactory = Bootstrap::getObjectManager() + ->create(PageEntryInterfaceFactory::class); + + + $this->fileSystem = vfsStream::setup('root', null, [ + 'app' => [ + 'code' => [ + 'ModuleNamespace' => [ + 'CustomModule' => [ + 'etc' => [ + 'module.xml' => 'XML-Content...' + ], + 'registration.php' => 'PHP-Content...', + 'composer.json' => 'JSON-Content', + ] + ] + ] + ], + 'pub' => [ + 'media' => [ + 'existing' => [ + 'dummy-image.png' => '', + ], + 'image.jpg' => '', + ] + ], + ]); + } +} diff --git a/Test/Integration/Model/Export/_files/export-block-entry-to-module.xml b/Test/Integration/Model/Export/_files/export-block-entry-to-module.xml new file mode 100644 index 0000000..4fc512d --- /dev/null +++ b/Test/Integration/Model/Export/_files/export-block-entry-to-module.xml @@ -0,0 +1,11 @@ + + + + Test Export Block 1 + test foobar Aenean commodo ligula eget dolor aenean massa]]> + ModuleNamespace_CustomModule::content/media + + + + + diff --git a/Test/Integration/Model/Export/_files/export-page-entry-to-module.xml b/Test/Integration/Model/Export/_files/export-page-entry-to-module.xml new file mode 100644 index 0000000..3f454de --- /dev/null +++ b/Test/Integration/Model/Export/_files/export-page-entry-to-module.xml @@ -0,0 +1,26 @@ + + + + Test Page 1 + test foobar Aenean commodo ligula eget dolor aenean massa]]> + + + + + + Seo title + Some, seo, keywords + Some seo description + + + 3columns + bar]]> + + + 2019-03-03 + 2019-05-29 + 3columns + 3 + + + diff --git a/Test/Integration/Model/_files/dummy-content.html b/Test/Integration/Model/_files/dummy-content.html deleted file mode 100644 index e512db4..0000000 --- a/Test/Integration/Model/_files/dummy-content.html +++ /dev/null @@ -1,4 +0,0 @@ -

Dummy Content

-

- Some test block content -

\ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index a00e2d4..b256729 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -83,10 +83,10 @@ - Firegento\ContentProvisioning\Model\Console\PageListCommand - Firegento\ContentProvisioning\Model\Console\BlockListCommand - Firegento\ContentProvisioning\Model\Console\AddPageCommand - Firegento\ContentProvisioning\Model\Console\AddBlockCommand + Firegento\ContentProvisioning\Console\PageListCommand + Firegento\ContentProvisioning\Console\BlockListCommand + Firegento\ContentProvisioning\Console\AddPageCommand + Firegento\ContentProvisioning\Console\AddBlockCommand @@ -107,4 +107,40 @@ + + + + + + + Firegento\ContentProvisioning\Model\Config\Generator\BlockNodeGenerator + Firegento\ContentProvisioning\Model\Config\Generator\TitleGenerator + Firegento\ContentProvisioning\Model\Config\Generator\ContentGenerator + Firegento\ContentProvisioning\Model\Config\Generator\StoresGenerator + + + + + + + Firegento\ContentProvisioning\Model\Config\Generator\PageNodeGenerator + Firegento\ContentProvisioning\Model\Config\Generator\TitleGenerator + Firegento\ContentProvisioning\Model\Config\Generator\ContentGenerator + Firegento\ContentProvisioning\Model\Config\Generator\StoresGenerator + Firegento\ContentProvisioning\Model\Config\Generator\SeoGenerator + Firegento\ContentProvisioning\Model\Config\Generator\DesignGenerator + Firegento\ContentProvisioning\Model\Config\Generator\CustomDesignGenerator + + + + + + Firegento\ContentProvisioning\Virtual\Config\Generator\BlockGeneratorChain + Firegento\ContentProvisioning\Virtual\Config\Generator\PageGeneratorChain + + +