diff --git a/Api/ConfigParserInterface.php b/Api/ConfigParserInterface.php index f07b25cd554d1cfbbb98eb60e34725786ad079db..03dbb4726742ddd7490516734ade0b2948198367 100644 --- a/Api/ConfigParserInterface.php +++ b/Api/ConfigParserInterface.php @@ -5,6 +5,9 @@ namespace Firegento\ContentProvisioning\Api; use DOMElement; +/** + * @api + */ interface ConfigParserInterface { /** diff --git a/Api/ConfigurationInterface.php b/Api/ConfigurationInterface.php index a608986ab37db64a5ccfb12e1365e66b9387b7aa..eb23a949e5c9dcad02c8ee330f33402c2bd41c13 100644 --- a/Api/ConfigurationInterface.php +++ b/Api/ConfigurationInterface.php @@ -5,6 +5,9 @@ namespace Firegento\ContentProvisioning\Api; use Magento\Framework\Config\DataInterface; +/** + * @api + */ interface ConfigurationInterface extends DataInterface { /** diff --git a/Api/ContentResolverInterface.php b/Api/ContentResolverInterface.php index e0e326fa7266977425ec51407cd004981b7bd398..9e67d80f00b565bb81bb95d9b2e84288644e13e5 100644 --- a/Api/ContentResolverInterface.php +++ b/Api/ContentResolverInterface.php @@ -5,6 +5,9 @@ namespace Firegento\ContentProvisioning\Api; use DOMElement; +/** + * @api + */ interface ContentResolverInterface { /** diff --git a/Api/Data/BlockEntryInterface.php b/Api/Data/BlockEntryInterface.php index 4cf070a38e6d19a37bc006bafcd1c643697452ee..9b98731f1453b6168af3fe4a0aa948b45e2462ed 100644 --- a/Api/Data/BlockEntryInterface.php +++ b/Api/Data/BlockEntryInterface.php @@ -5,6 +5,9 @@ namespace Firegento\ContentProvisioning\Api\Data; use Magento\Cms\Api\Data\BlockInterface; +/** + * @api + */ interface BlockEntryInterface extends BlockInterface, EntryInterface { } diff --git a/Api/Data/EntryInterface.php b/Api/Data/EntryInterface.php index da79fdd2aeeaf04826ac4b2c867c24bfb8254404..1788b3c040da0aa2cac86b8ea7269fc34df33010 100644 --- a/Api/Data/EntryInterface.php +++ b/Api/Data/EntryInterface.php @@ -3,13 +3,16 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Api\Data; +/** + * @api + */ interface EntryInterface { - const KEY = 'key'; - const IS_MAINTAINED = 'is_maintained'; - const STORES = 'stores'; - const MEDIA_DIRECTORY = 'media_directory'; - const MEDIA_FILES = 'media_files'; + public const KEY = 'key'; + public const IS_MAINTAINED = 'is_maintained'; + public const STORES = 'stores'; + public const MEDIA_DIRECTORY = 'media_directory'; + public const MEDIA_FILES = 'media_files'; /** * @return string diff --git a/Api/Data/PageEntryInterface.php b/Api/Data/PageEntryInterface.php index 6873731cdb4b22a8ac79139f47c6dedcaf983c7e..dae3a9a51eb0073fa450adfd2cfba9336e41753e 100644 --- a/Api/Data/PageEntryInterface.php +++ b/Api/Data/PageEntryInterface.php @@ -5,6 +5,9 @@ namespace Firegento\ContentProvisioning\Api\Data; use Magento\Cms\Api\Data\PageInterface; +/** + * @api + */ interface PageEntryInterface extends PageInterface, EntryInterface { } diff --git a/Api/MediaFilesParserInterface.php b/Api/MediaFilesParserInterface.php index ed0127942405cd55bd58f17c6e03410683a12f25..549a0215c0a5d9a88d372d3a4239bdd01f7eb2e3 100644 --- a/Api/MediaFilesParserInterface.php +++ b/Api/MediaFilesParserInterface.php @@ -3,6 +3,9 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Api; +/** + * @api + */ interface MediaFilesParserInterface { /** diff --git a/Api/StoreCodeResolverInterface.php b/Api/StoreCodeResolverInterface.php index e28dfc27ebf7697e6db7251de3db1560d4a9e40a..2cfc6081fee5deec5ef0ff8aa0d8794c7d282226 100644 --- a/Api/StoreCodeResolverInterface.php +++ b/Api/StoreCodeResolverInterface.php @@ -3,6 +3,9 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Api; +/** + * @api + */ interface StoreCodeResolverInterface { /** diff --git a/Api/TargetMediaDirectoryPathProviderInterface.php b/Api/TargetMediaDirectoryPathProviderInterface.php index 1dcf75aa6f8fa6d0ac2f10a08b48438842b91a61..32fd157cadf6c18bcce5f592aff75e61e019d1c5 100644 --- a/Api/TargetMediaDirectoryPathProviderInterface.php +++ b/Api/TargetMediaDirectoryPathProviderInterface.php @@ -3,6 +3,9 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Api; +/** + * @api + */ interface TargetMediaDirectoryPathProviderInterface { /** diff --git a/Block/Adminhtml/Block/Edit/SaveButton.php b/Block/Adminhtml/Block/Edit/SaveButton.php index b28f573ea044a9f1a667ed1f52a209b4ac88474f..69f2974e422dc2968dc01dc77554512e8b09f577 100644 --- a/Block/Adminhtml/Block/Edit/SaveButton.php +++ b/Block/Adminhtml/Block/Edit/SaveButton.php @@ -122,28 +122,34 @@ class SaveButton extends GenericButton implements ButtonProviderInterface ], ]; - if ($this->hasDefaultConfiguration->get((int)$this->getBlockId())) { - $options = array_merge($options, [[ - 'is_hard' => 'apply_default', - 'label' => __('Reset to Default & Save'), - 'data_attribute' => [ - 'mage-init' => [ - 'buttonAdapter' => [ - 'actions' => [ - [ - 'targetName' => 'cms_block_form.cms_block_form', - 'actionName' => 'save', - 'params' => [ - true, + if ($this->hasDefaultConfiguration->execute((int)$this->getBlockId())) { + $options = array_merge( + $options, + [ + [ + 'is_hard' => 'apply_default', + 'label' => __('Reset to Default & Save'), + 'data_attribute' => [ + 'mage-init' => [ + 'buttonAdapter' => [ + 'actions' => [ [ - 'back' => 'applyDefault', + 'targetName' => 'cms_block_form.cms_block_form', + 'actionName' => 'save', + 'params' => [ + true, + [ + 'back' => 'applyDefault', + ], + ], ], ], ], ], - ], - ], - ]]]); + ] + ] + ] + ); } return $options; diff --git a/Block/Adminhtml/Page/Edit/SaveButton.php b/Block/Adminhtml/Page/Edit/SaveButton.php index 4af0006e3154116eff9eb1cc7ee7661c09a72c23..411ddeaabf03b3980f8cb6ad1e665d68090553c6 100644 --- a/Block/Adminhtml/Page/Edit/SaveButton.php +++ b/Block/Adminhtml/Page/Edit/SaveButton.php @@ -122,28 +122,34 @@ class SaveButton extends GenericButton implements ButtonProviderInterface ], ]; - if ($this->hasDefaultConfiguration->get((int)$this->getPageId())) { - $options = array_merge($options, [[ - 'is_hard' => 'apply_default', - 'label' => __('Reset to Default & Save'), - 'data_attribute' => [ - 'mage-init' => [ - 'buttonAdapter' => [ - 'actions' => [ - [ - 'targetName' => 'cms_page_form.cms_page_form', - 'actionName' => 'save', - 'params' => [ - true, + if ($this->hasDefaultConfiguration->execute((int)$this->getPageId())) { + $options = array_merge( + $options, + [ + [ + 'is_hard' => 'apply_default', + 'label' => __('Reset to Default & Save'), + 'data_attribute' => [ + 'mage-init' => [ + 'buttonAdapter' => [ + 'actions' => [ [ - 'back' => 'applyDefault', + 'targetName' => 'cms_page_form.cms_page_form', + 'actionName' => 'save', + 'params' => [ + true, + [ + 'back' => 'applyDefault', + ], + ], ], ], ], ], - ], - ], - ]]]); + ] + ] + ] + ); } return $options; diff --git a/Controller/Adminhtml/Block/Save.php b/Controller/Adminhtml/Block/Save.php index b464178550322db071d5210b269383198ce037aa..cb9cd647e368f6d89f323fddec13b5491b412305 100644 --- a/Controller/Adminhtml/Block/Save.php +++ b/Controller/Adminhtml/Block/Save.php @@ -56,6 +56,8 @@ class Save extends \Magento\Cms\Controller\Adminhtml\Block implements HttpPostAc * @param Context $context * @param Registry $coreRegistry * @param DataPersistorInterface $dataPersistor + * @param GetBlockEntryByBlock $getBlockEntryByBlock + * @param ApplyBlockEntry $applyBlockEntry * @param BlockFactory|null $blockFactory * @param BlockRepositoryInterface|null $blockRepository */ diff --git a/Controller/Adminhtml/Page/Save.php b/Controller/Adminhtml/Page/Save.php index 2f0dd1a7ed895b04df3ea8669c15f3153bef1658..51fcf370b795528c575872464c099bd54fa6eb1b 100644 --- a/Controller/Adminhtml/Page/Save.php +++ b/Controller/Adminhtml/Page/Save.php @@ -25,6 +25,7 @@ use Magento\Framework\Exception\LocalizedException; /** * Save CMS page action. + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Save extends Action implements HttpPostActionInterface { @@ -33,7 +34,7 @@ class Save extends Action implements HttpPostActionInterface * * @see _isAllowed() */ - const ADMIN_RESOURCE = 'Magento_Cms::save'; + public const ADMIN_RESOURCE = 'Magento_Cms::save'; /** * @var PostDataProcessor @@ -69,6 +70,8 @@ class Save extends Action implements HttpPostActionInterface * @param Action\Context $context * @param PostDataProcessor $dataProcessor * @param DataPersistorInterface $dataPersistor + * @param GetPageEntryByPage $getPageEntryByPage + * @param ApplyPageEntry $applyPageEntry * @param PageFactory|null $pageFactory * @param PageRepositoryInterface|null $pageRepository */ diff --git a/Exception/CommandInputException.php b/Exception/CommandInputException.php new file mode 100644 index 0000000000000000000000000000000000000000..57ecb2c8a4b1f20935314851135fa80c8a1ee71a --- /dev/null +++ b/Exception/CommandInputException.php @@ -0,0 +1,10 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Exception; + +use Exception; + +class CommandInputException extends Exception +{ +} diff --git a/Model/BlockInstaller.php b/Model/BlockInstaller.php index 6333d1c50cbc9a6177284f48f964583dc55c790a..3d20c24fd436513abacc7d5d0ea26b080ecc5850 100644 --- a/Model/BlockInstaller.php +++ b/Model/BlockInstaller.php @@ -72,13 +72,16 @@ class BlockInstaller $this->applyMediaFiles->execute($blockEntry); } } catch (Exception $exception) { - $this->logger->error(sprintf( - 'An error appeared while applying cms block content: %s', - $exception->getMessage() - ), [ - 'block-data' => $blockEntry->getData(), - 'trace' => $exception->getTrace(), - ]); + $this->logger->error( + sprintf( + 'An error appeared while applying cms block content: %s', + $exception->getMessage() + ), + [ + 'block-data' => $blockEntry->getData(), + 'trace' => $exception->getTrace(), + ] + ); } } } diff --git a/Model/Command/ApplyMediaFiles.php b/Model/Command/ApplyMediaFiles.php index 570acea23364d8c444989353e6c8313b64564bf1..a636d399019e1f3188e4c0a0009583ce8278760b 100644 --- a/Model/Command/ApplyMediaFiles.php +++ b/Model/Command/ApplyMediaFiles.php @@ -5,6 +5,8 @@ namespace Firegento\ContentProvisioning\Model\Command; use Firegento\ContentProvisioning\Api\Data\EntryInterface; use Firegento\ContentProvisioning\Api\TargetMediaDirectoryPathProviderInterface; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem\DriverInterface; use SplFileInfo; class ApplyMediaFiles @@ -14,17 +16,26 @@ class ApplyMediaFiles */ private $targetMediaDirectoryPathProvider; + /** + * @var DriverInterface + */ + private $fileSystemDriver; + /** * @param TargetMediaDirectoryPathProviderInterface $targetMediaDirectoryPathProvider + * @param DriverInterface $fileSystemDriver */ public function __construct( - TargetMediaDirectoryPathProviderInterface $targetMediaDirectoryPathProvider + TargetMediaDirectoryPathProviderInterface $targetMediaDirectoryPathProvider, + DriverInterface $fileSystemDriver ) { $this->targetMediaDirectoryPathProvider = $targetMediaDirectoryPathProvider; + $this->fileSystemDriver = $fileSystemDriver; } /** * @param EntryInterface $entry + * @throws FileSystemException */ public function execute(EntryInterface $entry): void { @@ -41,6 +52,7 @@ class ApplyMediaFiles /** * @param string $sourceDirPath * @param string $fileName + * @throws FileSystemException */ private function copyFile(string $sourceDirPath, string $fileName): void { @@ -48,24 +60,30 @@ class ApplyMediaFiles $sourcePathname = $sourceDirPath . DIRECTORY_SEPARATOR . $fileName; $targetPathname = $targetDirPath . DIRECTORY_SEPARATOR . $fileName; - $sourceInfo = new SplFileInfo($sourcePathname); - if ($sourceInfo->isFile() && $sourceInfo->isReadable()) { - $this->createDirectory($targetDirPath, $sourceDirPath, $sourceInfo); - copy($sourceInfo->getPathname(), $targetPathname); + if ($this->fileSystemDriver->isFile($sourcePathname) + && $this->fileSystemDriver->isReadable($sourcePathname)() + ) { + $this->createDirectory($targetDirPath, $sourceDirPath, $sourcePathname); + $this->fileSystemDriver->copy($sourcePathname, $targetPathname); } } /** * @param string $targetDirPath * @param string $sourceDirPath - * @param SplFileInfo $sourceInfo + * @param string $sourcePathname + * @throws FileSystemException */ - private function createDirectory(string $targetDirPath, string $sourceDirPath, SplFileInfo $sourceInfo): void + private function createDirectory(string $targetDirPath, string $sourceDirPath, string $sourcePathname): void { - $subPath = str_replace($sourceDirPath, '', $sourceInfo->getPath()); + $subPath = str_replace( + $sourceDirPath, + '', + $this->fileSystemDriver->getParentDirectory($sourcePathname) + ); $pathname = $targetDirPath . DIRECTORY_SEPARATOR . $subPath; - if (!is_dir($pathname)) { - mkdir($pathname, 0775, true); + if (!$this->fileSystemDriver->isDirectory($pathname)) { + $this->fileSystemDriver->createDirectory($pathname); } } } diff --git a/Model/Command/ApplyPageEntry.php b/Model/Command/ApplyPageEntry.php index ed881625bc01a747e2c3927f0a321fcebdc084a8..3b330529f96374353a293de2eb9740448d02fc1a 100644 --- a/Model/Command/ApplyPageEntry.php +++ b/Model/Command/ApplyPageEntry.php @@ -64,4 +64,4 @@ class ApplyPageEntry $page->addData($this->normalizeData->execute($pageEntry->getData())); $this->pageRepository->save($page); } -} \ No newline at end of file +} diff --git a/Model/Command/NormalizeData.php b/Model/Command/NormalizeData.php index 69ebfc7431aa7d0714089f122dd0e4a249d86a2b..53f83cf1b5b9a4424f439c9fe5477f8d88f02838 100644 --- a/Model/Command/NormalizeData.php +++ b/Model/Command/NormalizeData.php @@ -46,4 +46,4 @@ class NormalizeData return $data; } -} \ No newline at end of file +} diff --git a/Model/Config/Converter.php b/Model/Config/Converter.php index 80d5ebc0dbcf74c63a25a92dc7dac914d1119838..5867edaa45e7a2a6547888fe610a9a706600039d 100644 --- a/Model/Config/Converter.php +++ b/Model/Config/Converter.php @@ -3,9 +3,9 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Config; +use DOMDocument; use Exception; use Magento\Framework\Config\ConverterInterface; -use Magento\Framework\Exception\LocalizedException; use Psr\Log\LoggerInterface; class Converter implements ConverterInterface @@ -41,8 +41,8 @@ class Converter implements ConverterInterface } /** - * {@inheritdoc} - * @throws LocalizedException + * @param DOMDocument $source + * @return array */ public function convert($source): array { diff --git a/Model/Config/Data.php b/Model/Config/Data.php index 9aaac204cd3865f6a1ce146e67af323812c4d47c..c9d85c398c3d1c29087837a6555bcb83e4c6aaaf 100644 --- a/Model/Config/Data.php +++ b/Model/Config/Data.php @@ -14,4 +14,4 @@ class Data extends \Magento\Framework\Config\Data implements ConfigurationInterf { return $this->_data; } -} \ No newline at end of file +} diff --git a/Model/Config/Parser/ParserChain.php b/Model/Config/Parser/ParserChain.php index eefbbe8b47234f9274e53718ac9d1d35708008b3..27c6f1373d5391b3512ad8268f637d0db41add23 100644 --- a/Model/Config/Parser/ParserChain.php +++ b/Model/Config/Parser/ParserChain.php @@ -22,10 +22,12 @@ class ParserChain implements ConfigParserInterface { foreach ($parser as $parserInstance) { if (!($parserInstance instanceof ConfigParserInterface)) { - throw new LocalizedException(__( - 'Parser needs to be instance of %interface', - ['interface' => ConfigParserInterface::class] - )); + throw new LocalizedException( + __( + 'Parser needs to be instance of %interface', + ['interface' => ConfigParserInterface::class] + ) + ); } } diff --git a/Model/Config/Parser/Query/FetchMediaFilesChain.php b/Model/Config/Parser/Query/FetchMediaFilesChain.php index ce8e147d0e4a59262e7cf214a9dfc6bf50bebfc6..b20834c581867192230d297cec59f0bb8ba0cd8e 100644 --- a/Model/Config/Parser/Query/FetchMediaFilesChain.php +++ b/Model/Config/Parser/Query/FetchMediaFilesChain.php @@ -21,10 +21,12 @@ class FetchMediaFilesChain implements MediaFilesParserInterface { foreach ($parsers as $parserInstance) { if (!($parserInstance instanceof MediaFilesParserInterface)) { - throw new LocalizedException(__( - 'Parser needs to be instance of %interface', - ['interface' => MediaFilesParserInterface::class] - )); + throw new LocalizedException( + __( + 'Parser needs to be instance of %interface', + ['interface' => MediaFilesParserInterface::class] + ) + ); } } diff --git a/Model/Config/Parser/StoresParser.php b/Model/Config/Parser/StoresParser.php index de86af1642f112c431e3a4a7490b594ac1d10615..e210e4aebd60cc7ef5ba23ff281b20149c3e61a2 100644 --- a/Model/Config/Parser/StoresParser.php +++ b/Model/Config/Parser/StoresParser.php @@ -38,18 +38,21 @@ class StoresParser implements ConfigParserInterface */ public function execute(DOMElement $element): array { - $output = []; + $storeCodes = []; foreach ($element->getElementsByTagName('store') as $store) { - $storeCodes = $this->storeCodeResolver->execute( + $storeCodes[] = $this->storeCodeResolver->execute( (string)$this->fetchAttributeValue->execute($store, 'code', '*') ); - $output = array_merge($output, $storeCodes); } - if (empty($output)) { - $output = $this->storeCodeResolver->execute('*'); + if (!empty($storeCodes)) { + $storeCodes = array_merge(...$storeCodes); } - return ['stores' => $output]; + if (empty($storeCodes)) { + $storeCodes = $this->storeCodeResolver->execute('*'); + } + + return ['stores' => $storeCodes]; } } diff --git a/Model/Console/AddBlockCommand.php b/Model/Console/AddBlockCommand.php index 40264b9f5444d90d88a7cbd77901972433fb2489..48744f0b47100b464a2f173eb1f5380972efff00 100644 --- a/Model/Console/AddBlockCommand.php +++ b/Model/Console/AddBlockCommand.php @@ -6,6 +6,7 @@ namespace Firegento\ContentProvisioning\Model\Console; use Firegento\ContentProvisioning\Model\Command\ApplyBlockEntry; use Firegento\ContentProvisioning\Model\Query\GetBlockEntryByKey; use Firegento\ContentProvisioning\Model\Query\GetBlockEntryByKeyFactory; +use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -13,7 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface; class AddBlockCommand extends Command { - const ARG_BLOCK_KEY = 'key'; + public const ARG_BLOCK_KEY = 'key'; /** * @var GetBlockEntryByKey @@ -41,7 +42,12 @@ class AddBlockCommand extends Command } /** - * {@inheritdoc} + * @param InputInterface $input + * @param OutputInterface $output + * @return void + * @throws LocalizedException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -51,7 +57,7 @@ class AddBlockCommand extends Command } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/Model/Console/AddPageCommand.php b/Model/Console/AddPageCommand.php index ae986b25fa498e0795c3857c4084edf1f6ecda36..bee8a5c0fbcec1503b6fb69257dc239444f821a7 100644 --- a/Model/Console/AddPageCommand.php +++ b/Model/Console/AddPageCommand.php @@ -6,6 +6,7 @@ namespace Firegento\ContentProvisioning\Model\Console; use Firegento\ContentProvisioning\Model\Command\ApplyPageEntry; use Firegento\ContentProvisioning\Model\Query\GetPageEntryByKey; use Firegento\ContentProvisioning\Model\Query\GetPageEntryByKeyFactory; +use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -13,7 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface; class AddPageCommand extends Command { - const ARG_PAGE_KEY = 'key'; + public const ARG_PAGE_KEY = 'key'; /** * @var GetPageEntryByKey @@ -26,7 +27,7 @@ class AddPageCommand extends Command private $applyPageEntry; /** - * @param GetPageEntryByKeyFactory $getPageEntryByKey + * @param GetPageEntryByKeyFactory $getPageEntryByKeyFactory * @param ApplyPageEntry $applyPageEntry * @param string|null $name */ @@ -41,7 +42,12 @@ class AddPageCommand extends Command } /** - * {@inheritdoc} + * @param InputInterface $input + * @param OutputInterface $output + * @return void + * @throws LocalizedException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -51,7 +57,7 @@ class AddPageCommand extends Command } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/Model/Console/BlockListCommand.php b/Model/Console/BlockListCommand.php index a7dbe605fd2109ab9db71d0625966f86bbbb7772..efbe56e453bb88478347a6309c57fa5778f8673c 100644 --- a/Model/Console/BlockListCommand.php +++ b/Model/Console/BlockListCommand.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Console; use Firegento\ContentProvisioning\Api\Data\BlockEntryInterface; -use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList\Proxy as GetBlockEntryList; -use Firegento\ContentProvisioning\Model\Query\GetBlocksByBlockEntry\Proxy as GetBlocksByBlockEntry; +use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList as GetBlockEntryList; +use Firegento\ContentProvisioning\Model\Query\GetBlocksByBlockEntry as GetBlocksByBlockEntry; use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -40,7 +40,11 @@ class BlockListCommand extends Command } /** - * {@inheritdoc} + * @param InputInterface $input + * @param OutputInterface $output + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -48,22 +52,24 @@ class BlockListCommand extends Command $table->setHeaders(['Key', 'Identifier', 'Stores', 'Maintained', 'Active', 'Title', 'in DB (IDs)']); foreach ($this->getAllBlockEntries->get() as $entry) { - $table->addRow([ - $entry->getKey(), - $entry->getIdentifier(), - implode(', ', $entry->getStores()), - $entry->isMaintained() ? 'yes' : 'no', - $entry->isActive() ? 'yes' : 'no', - $entry->getTitle(), - $this->getExistsInDbValue($entry), - ]); + $table->addRow( + [ + $entry->getKey(), + $entry->getIdentifier(), + implode(', ', $entry->getStores()), + $entry->isMaintained() ? 'yes' : 'no', + $entry->isActive() ? 'yes' : 'no', + $entry->getTitle(), + $this->getExistsInDbValue($entry), + ] + ); } $table->render($output); } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/Model/Console/BlockResetCommand.php b/Model/Console/BlockResetCommand.php index e3c9947bc7db01ae99d0e9225b23c51f78dd003e..5a472c5d34d2593f063d4df36376524f57e5d58c 100644 --- a/Model/Console/BlockResetCommand.php +++ b/Model/Console/BlockResetCommand.php @@ -13,7 +13,9 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Console; +use Exception; use Firegento\ContentProvisioning\Api\Data\BlockEntryInterface; +use Firegento\ContentProvisioning\Exception\CommandInputException; use Firegento\ContentProvisioning\Model\Command\ApplyBlockEntry; use Firegento\ContentProvisioning\Model\Command\ApplyMediaFiles; use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList; @@ -31,13 +33,24 @@ use Symfony\Component\Console\Output\OutputInterface; */ class BlockResetCommand extends Command { - public const COMMAND = 'content-provisioning:block:reset'; - public const PARAM_KEY = 'key'; + public const COMMAND = 'content-provisioning:block:reset'; + public const PARAM_KEY = 'key'; public const PARAM_IDENTIFIER = 'identifier'; - private GetBlockEntryList $getBlockEntryList; - private ApplyBlockEntry $applyBlockEntry; - private ApplyMediaFiles $applyMediaFiles; + /** + * @var GetBlockEntryList + */ + private $getBlockEntryList; + + /** + * @var ApplyBlockEntry + */ + private $applyBlockEntry; + + /** + * @var ApplyMediaFiles + */ + private $applyMediaFiles; /** * @param GetBlockEntryList $getBlockEntryList @@ -46,14 +59,14 @@ class BlockResetCommand extends Command */ public function __construct( GetBlockEntryList $getBlockEntryList, - ApplyBlockEntry $applyBlockEntry, - ApplyMediaFiles $applyMediaFiles + ApplyBlockEntry $applyBlockEntry, + ApplyMediaFiles $applyMediaFiles ) { parent::__construct(); $this->getBlockEntryList = $getBlockEntryList; - $this->applyBlockEntry = $applyBlockEntry; - $this->applyMediaFiles = $applyMediaFiles; + $this->applyBlockEntry = $applyBlockEntry; + $this->applyMediaFiles = $applyMediaFiles; } /** @@ -78,13 +91,13 @@ class BlockResetCommand extends Command { try { [$search, $type] = $this->parseParams($input); - } catch (\Exception $e) { + } catch (CommandInputException $e) { $output->writeln('<error>' . $e->getMessage() . '</error>' . "\n"); return Cli::RETURN_FAILURE; } $blockEntries = $this->getBlockEntries($search, $type); - $updateCount = 0; + $updateCount = 0; if (empty($blockEntries)) { $output->writeln('<error>block entry not found for ' . $type . ' "' . $search . '"</error>' . "\n"); @@ -97,7 +110,7 @@ class BlockResetCommand extends Command $this->applyMediaFiles->execute($blockEntry); $updateCount++; } - } catch (\Exception $exception) { + } catch (Exception $exception) { $output->writeln('<error>' . $exception->getMessage() . '</error>' . "\n"); return Cli::RETURN_FAILURE; } @@ -111,25 +124,29 @@ class BlockResetCommand extends Command /** * @param InputInterface $input * @return string[] - * @throws \Exception + * @throws CommandInputException */ private function parseParams(InputInterface $input): array { - $key = $input->getOption(self::PARAM_KEY); + $key = $input->getOption(self::PARAM_KEY); $identifier = $input->getOption(self::PARAM_IDENTIFIER); if ((!empty($key)) && (!empty($identifier))) { - throw new \Exception('Provide either "' . self::PARAM_KEY . '" or "' . self::PARAM_IDENTIFIER . '", not both!'); + throw new CommandInputException( + 'Provide either "' . self::PARAM_KEY . '" or "' . self::PARAM_IDENTIFIER . '", not both!' + ); } if (!empty($key)) { $search = $key; - $type = self::PARAM_KEY; + $type = self::PARAM_KEY; } elseif (!empty($identifier)) { $search = $identifier; - $type = self::PARAM_IDENTIFIER; + $type = self::PARAM_IDENTIFIER; } else { - throw new \Exception('Provide either "' . self::PARAM_KEY . '" or "' . self::PARAM_IDENTIFIER . '"!'); + throw new CommandInputException( + 'Provide either "' . self::PARAM_KEY . '" or "' . self::PARAM_IDENTIFIER . '"!' + ); } return [$search, $type]; @@ -146,7 +163,7 @@ class BlockResetCommand extends Command return []; } - $method = 'get' . ucfirst($type); + $method = 'get' . ucfirst($type); $entries = []; foreach ($this->getBlockEntryList->get() as $blockEntry) { diff --git a/Model/Console/PageListCommand.php b/Model/Console/PageListCommand.php index 35bde4f04af78a505785f58391a9401174aaf5a6..a16dca9509dba3823a0cebb45f6290d321015d71 100644 --- a/Model/Console/PageListCommand.php +++ b/Model/Console/PageListCommand.php @@ -5,8 +5,8 @@ namespace Firegento\ContentProvisioning\Model\Console; use Firegento\ContentProvisioning\Api\Data\EntryInterface; use Firegento\ContentProvisioning\Api\Data\PageEntryInterface; -use Firegento\ContentProvisioning\Model\Query\GetPageEntryList\Proxy as GetPageEntryList; -use Firegento\ContentProvisioning\Model\Query\GetPagesByPageEntry\Proxy as GetPagesByPageEntry; +use Firegento\ContentProvisioning\Model\Query\GetPageEntryList as GetPageEntryList; +use Firegento\ContentProvisioning\Model\Query\GetPagesByPageEntry as GetPagesByPageEntry; use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -41,7 +41,11 @@ class PageListCommand extends Command } /** - * {@inheritdoc} + * @param InputInterface $input + * @param OutputInterface $output + * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -50,22 +54,24 @@ class PageListCommand extends Command /** @var EntryInterface $entry */ foreach ($this->getAllContentEntries->get() as $entry) { - $table->addRow([ - $entry->getKey(), - $entry->getIdentifier(), - implode(', ', $entry->getStores()), - $entry->isMaintained() ? 'yes' : 'no', - $entry->isActive() ? 'yes' : 'no', - $entry->getTitle(), - $this->getExistsInDbValue($entry), - ]); + $table->addRow( + [ + $entry->getKey(), + $entry->getIdentifier(), + implode(', ', $entry->getStores()), + $entry->isMaintained() ? 'yes' : 'no', + $entry->isActive() ? 'yes' : 'no', + $entry->getTitle(), + $this->getExistsInDbValue($entry), + ] + ); } $table->render($output); } /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { diff --git a/Model/PageInstaller.php b/Model/PageInstaller.php index 739fca4c2b8fd634fd25a8c38d9a6e61d747cc45..00dee78f66b61d82c5080214e6220b89b3767ddb 100644 --- a/Model/PageInstaller.php +++ b/Model/PageInstaller.php @@ -72,13 +72,16 @@ class PageInstaller $this->applyMediaFiles->execute($pageEntry); } } catch (Exception $exception) { - $this->logger->error(sprintf( - 'An error appeared while applying cms page content: %s', - $exception->getMessage() - ), [ - 'page-data' => $pageEntry->getData(), - 'trace' => $exception->getTrace(), - ]); + $this->logger->error( + sprintf( + 'An error appeared while applying cms page content: %s', + $exception->getMessage() + ), + [ + 'page-data' => $pageEntry->getData(), + 'trace' => $exception->getTrace(), + ] + ); } } } diff --git a/Model/Query/GetBlockEntryByKey.php b/Model/Query/GetBlockEntryByKey.php index 8515fcb3a1acdc197ff33cfe9f6e8cfb1649d678..7e77ee1d9b4e4c9adcb50d2894b0432bf2c86d86 100644 --- a/Model/Query/GetBlockEntryByKey.php +++ b/Model/Query/GetBlockEntryByKey.php @@ -33,10 +33,11 @@ class GetBlockEntryByKey } /** - * @return BlockEntryInterface[] + * @param string $key + * @return BlockEntryInterface * @throws NotFoundException */ - public function get(string $key) + public function get(string $key): BlockEntryInterface { $blocks = $this->configuration->getList()['blocks'] ?? []; diff --git a/Model/Query/GetBlockEntryList.php b/Model/Query/GetBlockEntryList.php index e3f865f4dfea70bc1f06a1c12028881ccf8403ac..924834595851d48e006440064a6867da9a48622a 100644 --- a/Model/Query/GetBlockEntryList.php +++ b/Model/Query/GetBlockEntryList.php @@ -58,4 +58,4 @@ class GetBlockEntryList $this->prepare(); return $this->items; } -} \ No newline at end of file +} diff --git a/Model/Query/GetPageEntryList.php b/Model/Query/GetPageEntryList.php index d9c9ff956b3c98bd5a4af31be6bdde8ae42beaf2..65f66ad8144d0e5db02b91db925451df6de370c4 100644 --- a/Model/Query/GetPageEntryList.php +++ b/Model/Query/GetPageEntryList.php @@ -58,4 +58,4 @@ class GetPageEntryList $this->prepare(); return $this->items; } -} \ No newline at end of file +} diff --git a/Model/Query/HasDefaultBlockConfiguration.php b/Model/Query/HasDefaultBlockConfiguration.php index f8e72ceba12c4bc5769a38e886938363cbb0ba98..e9deba19220dafca157c56d722c264be5371a67b 100644 --- a/Model/Query/HasDefaultBlockConfiguration.php +++ b/Model/Query/HasDefaultBlockConfiguration.php @@ -35,7 +35,7 @@ class HasDefaultBlockConfiguration * @param int $entityId * @return bool */ - public function get(int $entityId): bool + public function execute(int $entityId): bool { try { $block = $this->blockRepository->getById($entityId); diff --git a/Model/Query/HasDefaultPageConfiguration.php b/Model/Query/HasDefaultPageConfiguration.php index 22fe2bc4538f093b92fb70479b8def9f2ea4a065..046ed2f0ad1d6641e2c36da7d1e37612a5115ed4 100644 --- a/Model/Query/HasDefaultPageConfiguration.php +++ b/Model/Query/HasDefaultPageConfiguration.php @@ -35,7 +35,7 @@ class HasDefaultPageConfiguration * @param int $entityId * @return bool */ - public function get(int $entityId): bool + public function execute(int $entityId): bool { try { $page = $this->pageRepository->getById($entityId); diff --git a/Model/Query/IsBlockMaintained.php b/Model/Query/IsBlockMaintained.php index 285f353671dd0a02772153d01b96be65c1edd7a5..335f2fd15fc3e7d1d63cc7a34e6be69479b7b2e8 100644 --- a/Model/Query/IsBlockMaintained.php +++ b/Model/Query/IsBlockMaintained.php @@ -35,7 +35,7 @@ class IsBlockMaintained * @param int $entityId * @return bool */ - public function get(int $entityId): bool + public function execute(int $entityId): bool { try { $page = $this->blockRepository->getById($entityId); diff --git a/Model/Query/IsMaintainedContentRequested.php b/Model/Query/IsMaintainedContentRequested.php index 3b27e834d857460e48483901629e56f9767da54a..c4c699a24c357c2282f0ff2768ea27e2785393ed 100644 --- a/Model/Query/IsMaintainedContentRequested.php +++ b/Model/Query/IsMaintainedContentRequested.php @@ -36,11 +36,11 @@ class IsMaintainedContentRequested public function execute(RequestInterface $request): bool { if ($this->isCmsPageEditFormRequested($request)) { - return $this->isPageMaintained->get($this->getPageIdFromRequest($request)); + return $this->isPageMaintained->execute($this->getPageIdFromRequest($request)); } if ($this->isCmsBlockEditFormRequested($request)) { - return $this->isBlockMaintained->get($this->getBlockIdFromRequest($request)); + return $this->isBlockMaintained->execute($this->getBlockIdFromRequest($request)); } return false; @@ -85,4 +85,4 @@ class IsMaintainedContentRequested { return (int)$request->getParam('block_id', null); } -} \ No newline at end of file +} diff --git a/Model/Query/IsPageMaintained.php b/Model/Query/IsPageMaintained.php index 0d87976a870617a055ef98cc7a4c7af7c05a7f69..18896169e4128ad133a598e4b5739a865e91cc9d 100644 --- a/Model/Query/IsPageMaintained.php +++ b/Model/Query/IsPageMaintained.php @@ -35,7 +35,7 @@ class IsPageMaintained * @param int $entityId * @return bool */ - public function get(int $entityId): bool + public function execute(int $entityId): bool { try { $page = $this->pageRepository->getById($entityId); diff --git a/Model/Resolver/ContentResolverProvider.php b/Model/Resolver/ContentResolverProvider.php index 0bda99a726a53e6b5b01149d46e9b264c9a87f1e..71becb44f0bee15584995000c3eef6e0a2493b9f 100644 --- a/Model/Resolver/ContentResolverProvider.php +++ b/Model/Resolver/ContentResolverProvider.php @@ -22,10 +22,12 @@ class ContentResolverProvider ) { foreach ($contentResolvers as $resolver) { if (!($resolver instanceof ContentResolverInterface)) { - throw new LocalizedException(__( - 'Given resolver must be an instance of %interface', - ['interface' => ContentResolverInterface::class] - )); + throw new LocalizedException( + __( + 'Given resolver must be an instance of %interface', + ['interface' => ContentResolverInterface::class] + ) + ); } } $this->contentResolvers = $contentResolvers; @@ -39,12 +41,14 @@ class ContentResolverProvider public function get(string $typeCode): ContentResolverInterface { if (!isset($this->contentResolvers[$typeCode])) { - throw new LocalizedException(__( - 'There is no content resolver defined for given type code %code', - ['code' => $typeCode] - )); + throw new LocalizedException( + __( + 'There is no content resolver defined for given type code %code', + ['code' => $typeCode] + ) + ); } return $this->contentResolvers[$typeCode]; } -} \ No newline at end of file +} diff --git a/Model/Resolver/FileContentResolver.php b/Model/Resolver/FileContentResolver.php index 709b5558dcb22f7a770bdbc9a90bdcab84f86fea..6325483b6492ac152ea15578cc8085e18f8b4055 100644 --- a/Model/Resolver/FileContentResolver.php +++ b/Model/Resolver/FileContentResolver.php @@ -6,8 +6,7 @@ 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; +use Magento\Framework\Filesystem\DriverInterface; class FileContentResolver implements ContentResolverInterface { @@ -16,13 +15,21 @@ class FileContentResolver implements ContentResolverInterface */ private $pathResolver; + /** + * @var DriverInterface + */ + private $fileSystemDriver; + /** * @param PathResolver $pathResolver + * @param DriverInterface $fileSystemDriver */ public function __construct( - PathResolver $pathResolver + PathResolver $pathResolver, + DriverInterface $fileSystemDriver ) { $this->pathResolver = $pathResolver; + $this->fileSystemDriver = $fileSystemDriver; } /** @@ -33,10 +40,10 @@ class FileContentResolver implements ContentResolverInterface public function execute(DOMElement $node): string { $path = $this->pathResolver->execute((string)$node->textContent); - if (!is_file($path)) { + if (!$this->fileSystemDriver->isFile($path)) { throw new LocalizedException(__('Given content file %file does not exists.', ['file' => $path])); } - return file_get_contents($path); + return $this->fileSystemDriver->fileGetContents($path); } -} \ No newline at end of file +} diff --git a/Model/Resolver/PathResolver.php b/Model/Resolver/PathResolver.php index 879af160be0f4570fb6cecba4da7d60e916368c7..70b2a430ec716f3c7d73bd05bdf8461d398e6072 100644 --- a/Model/Resolver/PathResolver.php +++ b/Model/Resolver/PathResolver.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Resolver; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem\DirectoryList; use Magento\Framework\Module\Dir\Reader; @@ -42,15 +41,21 @@ class PathResolver $moduleName = $pathParts[0]; $filePath = $pathParts[1]; $moduleDirectory = $this->moduleReader->getModuleDir('', $moduleName); - return implode(DIRECTORY_SEPARATOR, [ - $moduleDirectory, - $filePath, - ]); + return implode( + DIRECTORY_SEPARATOR, + [ + $moduleDirectory, + $filePath, + ] + ); } else { - return implode(DIRECTORY_SEPARATOR, [ - $this->directoryList->getRoot(), - $path, - ]); + return implode( + DIRECTORY_SEPARATOR, + [ + $this->directoryList->getRoot(), + $path, + ] + ); } } } diff --git a/Model/Resolver/PlainContentResolver.php b/Model/Resolver/PlainContentResolver.php index 6bfac624405e43a0627904df4c2ac7471e54eb99..a900e641c8a27f2f538ff1324981e86c00aa69ec 100644 --- a/Model/Resolver/PlainContentResolver.php +++ b/Model/Resolver/PlainContentResolver.php @@ -16,4 +16,4 @@ class PlainContentResolver implements ContentResolverInterface { return (string)$node->textContent; } -} \ No newline at end of file +} diff --git a/Model/Resolver/StoreCodeResolver.php b/Model/Resolver/StoreCodeResolver.php index c2bdd77c240aff082c8152597a471c7a6bd7c50c..c0e089fe207ed2a230e3768b6ed07c5af3d23726 100644 --- a/Model/Resolver/StoreCodeResolver.php +++ b/Model/Resolver/StoreCodeResolver.php @@ -24,7 +24,8 @@ class StoreCodeResolver implements StoreCodeResolverInterface } /** - * {@inheritdoc} + * @param string $code + * @return array * @throws NoSuchEntityException */ public function execute(string $code): array @@ -39,4 +40,4 @@ class StoreCodeResolver implements StoreCodeResolverInterface return $output; } -} \ No newline at end of file +} diff --git a/Setup/RecurringData.php b/Setup/RecurringData.php index ccb740d282fb45a9b054088592559bcf0f409b01..3a32579201d5a3eed03521ad96bf762177d69f7b 100644 --- a/Setup/RecurringData.php +++ b/Setup/RecurringData.php @@ -37,7 +37,10 @@ class RecurringData implements InstallDataInterface } /** - * {@inheritdoc} + * @param ModuleDataSetupInterface $setup + * @param ModuleContextInterface $context + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { diff --git a/Test/Integration/Model/BlockInstaller/TestCase.php b/Test/Integration/Model/BlockInstaller/TestCase.php index 106b649eb52416c98d233d42d0ad3476f7c9eef1..a37eb4d73a97d4e77c8ec97a969ee7d673e1c919 100644 --- a/Test/Integration/Model/BlockInstaller/TestCase.php +++ b/Test/Integration/Model/BlockInstaller/TestCase.php @@ -84,25 +84,36 @@ class TestCase extends \PHPUnit\Framework\TestCase protected function initBlockEntries() { - $this->blockEntries[1] = $this->blockEntryInterfaceFactory->create(['data' => [ - BlockEntryInterface::TITLE => 'Test Block 1', - BlockEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', - BlockEntryInterface::KEY => 'test.block.1', - BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-1', - BlockEntryInterface::IS_ACTIVE => false, - BlockEntryInterface::IS_MAINTAINED => true, - BlockEntryInterface::STORES => ['admin'], - ]]); - - $this->blockEntries[2] = $this->blockEntryInterfaceFactory->create(['data' => [ - BlockEntryInterface::TITLE => 'Test Block 2', - BlockEntryInterface::CONTENT => file_get_contents(__DIR__ . '/../../_files/content/dummy-content.html'), - BlockEntryInterface::KEY => 'test.block.2', - BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-2', - BlockEntryInterface::IS_ACTIVE => true, - BlockEntryInterface::IS_MAINTAINED => false, - BlockEntryInterface::STORES => ['default', 'admin'], - ]]); + $this->blockEntries[1] = $this->blockEntryInterfaceFactory->create( + [ + 'data' => [ + BlockEntryInterface::TITLE => 'Test Block 1', + BlockEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget ' + . 'dolor aenean massa</h2>', + BlockEntryInterface::KEY => 'test.block.1', + BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-1', + BlockEntryInterface::IS_ACTIVE => false, + BlockEntryInterface::IS_MAINTAINED => true, + BlockEntryInterface::STORES => ['admin'], + ] + ] + ); + + $this->blockEntries[2] = $this->blockEntryInterfaceFactory->create( + [ + 'data' => [ + BlockEntryInterface::TITLE => 'Test Block 2', + BlockEntryInterface::CONTENT => file_get_contents( + __DIR__ . '/../../_files/content/dummy-content.html' + ), + BlockEntryInterface::KEY => 'test.block.2', + BlockEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-2', + BlockEntryInterface::IS_ACTIVE => true, + BlockEntryInterface::IS_MAINTAINED => false, + BlockEntryInterface::STORES => ['default', 'admin'], + ] + ] + ); $this->getBlockEntryListMock->method('get')->willReturn($this->blockEntries); } diff --git a/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php b/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php index 4a10298e45eb2ebbd4d9028ae340983fd5426ba0..b6355e27d15631038b43c581f2656b8a0f46951c 100644 --- a/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php +++ b/Test/Integration/Model/Config/Parser/Query/FetchMediaFilesChainTest.php @@ -37,32 +37,44 @@ class FetchMediaFilesChainTest extends TestCase ->getMock(); $this->chain = Bootstrap::getObjectManager() - ->create(FetchMediaFilesChain::class, ['parsers' => [ - $this->parser1, - $this->parser2, - ]]); + ->create( + FetchMediaFilesChain::class, + [ + 'parsers' => [ + $this->parser1, + $this->parser2, + ] + ] + ); } public function testMergingData() { - $this->parser1->method('execute')->willReturn([ - 'path/to/file1.png', - 'path/to/file2.png', - 'file3.png', - ]); - $this->parser2->method('execute')->willReturn([ - 'file3.png', - 'some/other/path.jpg', - ]); + $this->parser1->method('execute')->willReturn( + [ + 'path/to/file1.png', + 'path/to/file2.png', + 'file3.png', + ] + ); + $this->parser2->method('execute')->willReturn( + [ + 'file3.png', + 'some/other/path.jpg', + ] + ); $result = $this->chain->execute(''); - $this->assertSame([ - 'path/to/file1.png', - 'path/to/file2.png', - 'file3.png', - 'file3.png', - 'some/other/path.jpg', - ], $result); + $this->assertSame( + [ + 'path/to/file1.png', + 'path/to/file2.png', + 'file3.png', + 'file3.png', + 'some/other/path.jpg', + ], + $result + ); } } diff --git a/Test/Integration/Model/PageInstaller/InstallMediaFilesTest.php b/Test/Integration/Model/PageInstaller/InstallMediaFilesTest.php index 73ae70de865017707ddbc5191922ec1a0e09da49..bb6c6adc55266f1b0a8a028ff875011fd0f5dbf3 100644 --- a/Test/Integration/Model/PageInstaller/InstallMediaFilesTest.php +++ b/Test/Integration/Model/PageInstaller/InstallMediaFilesTest.php @@ -56,71 +56,102 @@ class InstallMediaFilesTest extends TestCase $this->fileSystem = vfsStream::setup('root', null, $structure); $this->targetMediaDirectoryPathProvider->method('get')->willReturn( - $this->fileSystem->getChild('pub/media')->url() + $this->getChildDirectoryUrl('pub/media') ); $applyMediaFiles = Bootstrap::getObjectManager() - ->create(ApplyMediaFiles::class, [ - 'targetMediaDirectoryPathProvider' => $this->targetMediaDirectoryPathProvider, - ]); + ->create( + ApplyMediaFiles::class, + ['targetMediaDirectoryPathProvider' => $this->targetMediaDirectoryPathProvider] + ); $this->installer = Bootstrap::getObjectManager() - ->create(PageInstaller::class, [ - 'getAllPageEntries' => $this->getPageEntryListMock, - 'applyMediaFiles' => $applyMediaFiles, - ]); + ->create( + PageInstaller::class, + [ + 'getAllPageEntries' => $this->getPageEntryListMock, + 'applyMediaFiles' => $applyMediaFiles, + ] + ); + } + + /** + * @param string $name + * @return string + */ + private function getChildDirectoryUrl(string $name): string + { + foreach ($this->fileSystem->getChildren() as $child) { + if ($child->getName() === $name) { + return $child->url(); + } + } + + $this->fail('Unknown child name for virtual directory!'); } protected function initEntries() { - $this->pageEntries[1] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Page with images 1', - PageEntryInterface::CONTENT => '', - PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', - PageEntryInterface::KEY => 'page.with.images.1', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-images-1', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['admin'], - PageEntryInterface::MEDIA_DIRECTORY => $this->fileSystem->getChild('source/media')->url(), - PageEntryInterface::MEDIA_FILES => [ - 'sub-directory/file-3.jpg', - 'file-1.png', - ], - ]]); - - $this->pageEntries[2] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Page with images 2', - PageEntryInterface::CONTENT => '', - PageEntryInterface::CONTENT_HEADING => '', - PageEntryInterface::KEY => 'page.with.images.2', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-images-2', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['admin'], - PageEntryInterface::MEDIA_DIRECTORY => $this->fileSystem->getChild('source/media')->url(), - PageEntryInterface::MEDIA_FILES => [ - 'file-2.txt', - 'existing/file-4.gif', - ], - ]]); - - $this->pageEntries[3] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Page with images 3', - PageEntryInterface::CONTENT => '', - PageEntryInterface::CONTENT_HEADING => '', - PageEntryInterface::KEY => 'page.with.images.3', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-images-3', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['admin'], - PageEntryInterface::MEDIA_DIRECTORY => $this->fileSystem->getChild('source/media')->url(), - PageEntryInterface::MEDIA_FILES => [ - 'sub-directory/file-3.jpg', - 'file-1.png', - 'not-existing/image.png', - ], - ]]); + $this->pageEntries[1] = $this->pageEntryInterfaceFactory->create( + [ + 'data' => [ + PageEntryInterface::TITLE => 'Page with images 1', + PageEntryInterface::CONTENT => '', + PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', + PageEntryInterface::KEY => 'page.with.images.1', + PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-images-1', + PageEntryInterface::IS_ACTIVE => true, + PageEntryInterface::IS_MAINTAINED => true, + PageEntryInterface::STORES => ['admin'], + PageEntryInterface::MEDIA_DIRECTORY => $this->getChildDirectoryUrl('source/media'), + PageEntryInterface::MEDIA_FILES => [ + 'sub-directory/file-3.jpg', + 'file-1.png', + ], + ] + ] + ); + + $this->pageEntries[2] = $this->pageEntryInterfaceFactory->create( + [ + 'data' => [ + PageEntryInterface::TITLE => 'Page with images 2', + PageEntryInterface::CONTENT => '', + PageEntryInterface::CONTENT_HEADING => '', + PageEntryInterface::KEY => 'page.with.images.2', + PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-images-2', + PageEntryInterface::IS_ACTIVE => true, + PageEntryInterface::IS_MAINTAINED => true, + PageEntryInterface::STORES => ['admin'], + PageEntryInterface::MEDIA_DIRECTORY => $this->getChildDirectoryUrl('source/media'), + PageEntryInterface::MEDIA_FILES => [ + 'file-2.txt', + 'existing/file-4.gif', + ], + ] + ] + ); + + $this->pageEntries[3] = $this->pageEntryInterfaceFactory->create( + [ + 'data' => [ + PageEntryInterface::TITLE => 'Page with images 3', + PageEntryInterface::CONTENT => '', + PageEntryInterface::CONTENT_HEADING => '', + PageEntryInterface::KEY => 'page.with.images.3', + PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-images-3', + PageEntryInterface::IS_ACTIVE => true, + PageEntryInterface::IS_MAINTAINED => true, + PageEntryInterface::STORES => ['admin'], + PageEntryInterface::MEDIA_DIRECTORY => $this->getChildDirectoryUrl('source/media'), + PageEntryInterface::MEDIA_FILES => [ + 'sub-directory/file-3.jpg', + 'file-1.png', + 'not-existing/image.png', + ], + ] + ] + ); $this->getPageEntryListMock->method('get')->willReturn($this->pageEntries); } diff --git a/Test/Integration/Model/PageInstaller/TestCase.php b/Test/Integration/Model/PageInstaller/TestCase.php index 9e47fa52df69724912abc6159612a1ba9094d631..c2d5490ee72c12f9691b39fac0f43867b56d04b0 100644 --- a/Test/Integration/Model/PageInstaller/TestCase.php +++ b/Test/Integration/Model/PageInstaller/TestCase.php @@ -46,8 +46,7 @@ class TestCase extends \PHPUnit\Framework\TestCase /** * @var GetFirstPageByPageEntry */ - protected $getFisrtPageByPageEntry; - + protected $getFirstPageByPageEntry; protected function setUp(): void { @@ -66,7 +65,7 @@ class TestCase extends \PHPUnit\Framework\TestCase $this->storeManager = Bootstrap::getObjectManager() ->create(StoreManagerInterface::class); - $this->getFisrtPageByPageEntry = Bootstrap::getObjectManager() + $this->getFirstPageByPageEntry = Bootstrap::getObjectManager() ->create(GetFirstPageByPageEntry::class); } @@ -92,52 +91,66 @@ class TestCase extends \PHPUnit\Framework\TestCase protected function initEntries() { - $this->pageEntries[1] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Test Page 1', - PageEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', - 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 => ['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 => '', - PageEntryInterface::CUSTOM_THEME => 3, - PageEntryInterface::CUSTOM_THEME_FROM => '2019-03-29', - PageEntryInterface::CUSTOM_THEME_TO => '2019-05-29', - PageEntryInterface::CUSTOM_ROOT_TEMPLATE => '3columns', - ]]); - - $this->pageEntries[2] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Test Page 2', - PageEntryInterface::CONTENT => file_get_contents(__DIR__ . '/../../_files/content/dummy-content.html'), - PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', - PageEntryInterface::KEY => 'test.page.2', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-2', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => false, - PageEntryInterface::STORES => ['default', 'admin'], - ]]); - - $this->pageEntries[3] = $this->pageEntryInterfaceFactory->create(['data' => [ - PageEntryInterface::TITLE => 'Test Page 3', - PageEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', - PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', - PageEntryInterface::KEY => 'test.page.3', - PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-3', - PageEntryInterface::IS_ACTIVE => true, - PageEntryInterface::IS_MAINTAINED => true, - PageEntryInterface::STORES => ['default'], - 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 => '', - ]]); + $this->pageEntries[1] = $this->pageEntryInterfaceFactory->create( + [ + 'data' => [ + PageEntryInterface::TITLE => 'Test Page 1', + PageEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', + 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 => ['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 => '', + PageEntryInterface::CUSTOM_THEME => 3, + PageEntryInterface::CUSTOM_THEME_FROM => '2019-03-29', + PageEntryInterface::CUSTOM_THEME_TO => '2019-05-29', + PageEntryInterface::CUSTOM_ROOT_TEMPLATE => '3columns', + ] + ] + ); + + $this->pageEntries[2] = $this->pageEntryInterfaceFactory->create( + [ + 'data' => [ + PageEntryInterface::TITLE => 'Test Page 2', + PageEntryInterface::CONTENT => file_get_contents( + __DIR__ . '/../../_files/content/dummy-content.html' + ), + PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', + PageEntryInterface::KEY => 'test.page.2', + PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-2', + PageEntryInterface::IS_ACTIVE => true, + PageEntryInterface::IS_MAINTAINED => false, + PageEntryInterface::STORES => ['default', 'admin'], + ] + ] + ); + + $this->pageEntries[3] = $this->pageEntryInterfaceFactory->create( + [ + 'data' => [ + PageEntryInterface::TITLE => 'Test Page 3', + PageEntryInterface::CONTENT => '<h2>test foobar Aenean commodo ligula eget dolor aenean massa</h2>', + PageEntryInterface::CONTENT_HEADING => 'Some Content Heading', + PageEntryInterface::KEY => 'test.page.3', + PageEntryInterface::IDENTIFIER => 'firegento-content-provisioning-test-3', + PageEntryInterface::IS_ACTIVE => true, + PageEntryInterface::IS_MAINTAINED => true, + PageEntryInterface::STORES => ['default'], + 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 => '', + ] + ] + ); $this->getPageEntryListMock->method('get')->willReturn($this->pageEntries); } @@ -166,6 +179,6 @@ class TestCase extends \PHPUnit\Framework\TestCase */ protected function getPageByPageEntry(PageEntryInterface $entry): PageInterface { - return $this->getFisrtPageByPageEntry->execute($entry); + return $this->getFirstPageByPageEntry->execute($entry); } } diff --git a/composer.json b/composer.json index ce23f883a163c15825a055c5d9895329161fc536..8ab8ba2ada9d6a7b6f77e494bcee85d25e1b3268 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,13 @@ "description": "N/A", "require": { "php": "~7.1.3|~7.2.0|~7.3.0|~7.4.0|~8.1.0", + "ext-dom": "*", "magento/framework": "100.1.*|101.0.*|102.0.*|103.0.*", "magento/module-cms": "101.0.*|102.0.*|103.0.*|104.0.*", - "magento/module-widget": "100.1.*|101.0.*|101.1.*|101.2.*" + "magento/module-widget": "100.1.*|101.0.*|101.1.*|101.2.*", + "magento/module-backend": "100.*|101.*|102.*", + "magento/module-ui": "100.*|101.*", + "magento/module-store": "100.*|101.*" }, "require-dev": { "mikey179/vfsstream": "^1.6" diff --git a/etc/di.xml b/etc/di.xml index dccdfbeaf058529d21b8d6908127e32a105f51b4..5eab44e3e9799332de6576b42e2ec270584ab344 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -92,6 +92,19 @@ </arguments> </type> + <type name="Firegento\ContentProvisioning\Model\Console\BlockListCommand"> + <arguments> + <argument name="getAllBlockEntries" xsi:type="object">Firegento\ContentProvisioning\Model\Query\GetBlockEntryList\Proxy</argument> + <argument name="getBlocksByBlockEntry" xsi:type="object">Firegento\ContentProvisioning\Model\Query\GetBlocksByBlockEntry\Proxy</argument> + </arguments> + </type> + <type name="Firegento\ContentProvisioning\Model\Console\PageListCommand"> + <arguments> + <argument name="getAllContentEntries" xsi:type="object">Firegento\ContentProvisioning\Model\Query\GetPageEntryList\Proxy</argument> + <argument name="getPagesByPageEntry" xsi:type="object">Firegento\ContentProvisioning\Model\Query\GetPagesByPageEntry\Proxy</argument> + </arguments> + </type> + <type name="Firegento\ContentProvisioning\Model\Resolver\ContentResolverProvider"> <arguments> <argument name="contentResolvers" xsi:type="array"> diff --git a/install-config-mysql.travis.2.3.php b/install-config-mysql.travis.2.3.php deleted file mode 100644 index 5341ac5261a25a9676cf738318cf8713e7f054ca..0000000000000000000000000000000000000000 --- a/install-config-mysql.travis.2.3.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -use Magento\TestFramework\Bootstrap; - -return [ - 'db-host' => '127.0.0.1', - 'db-user' => 'root', - 'db-password' => '', - 'db-name' => 'magento_integration_tests', - 'db-prefix' => 'trv_', - 'backend-frontname' => 'backend', - 'admin-user' => Bootstrap::ADMIN_NAME, - 'admin-password' => Bootstrap::ADMIN_PASSWORD, - 'admin-email' => Bootstrap::ADMIN_EMAIL, - 'admin-firstname' => Bootstrap::ADMIN_FIRSTNAME, - 'admin-lastname' => Bootstrap::ADMIN_LASTNAME, - 'amqp-host' => 'localhost', - 'amqp-port' => '5672', - 'amqp-user' => 'guest', - 'amqp-password' => 'guest', -]; diff --git a/install-config-mysql.travis.2.4.php b/install-config-mysql.travis.2.4.php deleted file mode 100644 index 2481f217991204832c09693064d4ac2aa4f27292..0000000000000000000000000000000000000000 --- a/install-config-mysql.travis.2.4.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -use Magento\TestFramework\Bootstrap; - -return [ - 'db-host' => '127.0.0.1', - 'db-user' => 'root', - 'db-password' => '', - 'db-name' => 'magento_integration_tests', - 'db-prefix' => 'trv_', - 'backend-frontname' => 'backend', - 'admin-user' => Bootstrap::ADMIN_NAME, - 'admin-password' => Bootstrap::ADMIN_PASSWORD, - 'admin-email' => Bootstrap::ADMIN_EMAIL, - 'admin-firstname' => Bootstrap::ADMIN_FIRSTNAME, - 'admin-lastname' => Bootstrap::ADMIN_LASTNAME, - 'amqp-host' => 'localhost', - 'amqp-port' => '5672', - 'amqp-user' => 'guest', - 'amqp-password' => 'guest', - 'elasticsearch-host' => '127.0.0.1', - 'elasticsearch-port' => '9200', -]; diff --git a/view/adminhtml/templates/maintained_content_warning.phtml b/view/adminhtml/templates/maintained_content_warning.phtml index a45234c456d250345c47ef42a334232effe5e887..c2c459b2c41a8742fe277ec54c5b830e40c8b329 100644 --- a/view/adminhtml/templates/maintained_content_warning.phtml +++ b/view/adminhtml/templates/maintained_content_warning.phtml @@ -1,14 +1,16 @@ <?php /** @var MaintainedContentWarning $block */ +/** @var Escaper $escaper */ use Firegento\ContentProvisioning\Block\MaintainedContentWarning; +use Magento\Framework\Escaper; ?> <?php if ($block->isMaintained()): ?> <div class="message-system-short"> <div class="message-system-wrapper" data-repeat-index="0"> <div class="message message-warning"> - <?= $block->getMessage() ?> + <?= $escaper->escapeHtml($block->getMessage()) ?> </div> </div> </div>