From c49aee0f4bea7d8589f2b7e6ec8c299516596ef9 Mon Sep 17 00:00:00 2001 From: Vadim Justus <v.justus@techdivision.com> Date: Fri, 27 May 2022 13:38:12 +0200 Subject: [PATCH] Fix static test issues --- Api/ConfigParserInterface.php | 3 + Api/ConfigurationInterface.php | 3 + Api/ContentResolverInterface.php | 3 + Api/Data/BlockEntryInterface.php | 3 + Api/Data/EntryInterface.php | 13 +- Api/Data/PageEntryInterface.php | 3 + Api/MediaFilesParserInterface.php | 3 + Api/StoreCodeResolverInterface.php | 3 + ...getMediaDirectoryPathProviderInterface.php | 3 + Block/Adminhtml/Block/Edit/SaveButton.php | 40 ++--- Block/Adminhtml/Page/Edit/SaveButton.php | 40 ++--- Controller/Adminhtml/Block/Save.php | 2 + Controller/Adminhtml/Page/Save.php | 5 +- Exception/CommandInputException.php | 10 ++ Model/BlockInstaller.php | 17 ++- Model/Command/ApplyMediaFiles.php | 38 +++-- Model/Command/ApplyPageEntry.php | 2 +- Model/Command/NormalizeData.php | 2 +- Model/Config/Converter.php | 6 +- Model/Config/Data.php | 2 +- Model/Config/Parser/ParserChain.php | 10 +- .../Parser/Query/FetchMediaFilesChain.php | 10 +- Model/Config/Parser/StoresParser.php | 15 +- Model/Console/AddBlockCommand.php | 12 +- Model/Console/AddPageCommand.php | 14 +- Model/Console/BlockListCommand.php | 32 ++-- Model/Console/BlockResetCommand.php | 55 ++++--- Model/Console/PageListCommand.php | 32 ++-- Model/PageInstaller.php | 17 ++- Model/Query/GetBlockEntryByKey.php | 5 +- Model/Query/GetBlockEntryList.php | 2 +- Model/Query/GetPageEntryList.php | 2 +- Model/Query/HasDefaultBlockConfiguration.php | 2 +- Model/Query/HasDefaultPageConfiguration.php | 2 +- Model/Query/IsBlockMaintained.php | 2 +- Model/Query/IsMaintainedContentRequested.php | 6 +- Model/Query/IsPageMaintained.php | 2 +- Model/Resolver/ContentResolverProvider.php | 22 +-- Model/Resolver/FileContentResolver.php | 19 ++- Model/Resolver/PathResolver.php | 23 +-- Model/Resolver/PlainContentResolver.php | 2 +- Model/Resolver/StoreCodeResolver.php | 5 +- Setup/RecurringData.php | 5 +- .../Model/BlockInstaller/TestCase.php | 49 +++--- .../Parser/Query/FetchMediaFilesChainTest.php | 52 ++++--- .../PageInstaller/InstallMediaFilesTest.php | 143 +++++++++++------- .../Model/PageInstaller/TestCase.php | 113 ++++++++------ composer.json | 6 +- etc/di.xml | 13 ++ install-config-mysql.travis.2.3.php | 25 --- install-config-mysql.travis.2.4.php | 27 ---- .../maintained_content_warning.phtml | 4 +- 52 files changed, 555 insertions(+), 374 deletions(-) create mode 100644 Exception/CommandInputException.php delete mode 100644 install-config-mysql.travis.2.3.php delete mode 100644 install-config-mysql.travis.2.4.php diff --git a/Api/ConfigParserInterface.php b/Api/ConfigParserInterface.php index f07b25c..03dbb47 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 a608986..eb23a94 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 e0e326f..9e67d80 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 4cf070a..9b98731 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 da79fdd..1788b3c 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 6873731..dae3a9a 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 ed01279..549a021 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 e28dfc2..2cfc608 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 1dcf75a..32fd157 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 b28f573..69f2974 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 4af0006..411ddea 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 b464178..cb9cd64 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 2f0dd1a..51fcf37 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 0000000..57ecb2c --- /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 6333d1c..3d20c24 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 570acea..a636d39 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 ed88162..3b33052 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 69ebfc7..53f83cf 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 80d5ebc..5867eda 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 9aaac20..c9d85c3 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 eefbbe8..27c6f13 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 ce8e147..b20834c 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 de86af1..e210e4a 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 40264b9..48744f0 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 ae986b2..bee8a5c 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 a7dbe60..efbe56e 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 e3c9947..5a472c5 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 35bde4f..a16dca9 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 739fca4..00dee78 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 8515fcb..7e77ee1 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 e3f865f..9248345 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 d9c9ff9..65f66ad 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 f8e72ce..e9deba1 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 22fe2bc..046ed2f 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 285f353..335f2fd 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 3b27e83..c4c699a 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 0d87976..1889616 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 0bda99a..71becb4 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 709b555..6325483 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 879af16..70b2a43 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 6bfac62..a900e64 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 c2bdd77..c0e089f 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 ccb740d..3a32579 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 106b649..a37eb4d 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 4a10298..b6355e2 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 73ae70d..bb6c6ad 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 9e47fa5..c2d5490 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 ce23f88..8ab8ba2 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 dccdfbe..5eab44e 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 5341ac5..0000000 --- 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 2481f21..0000000 --- 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 a45234c..c2c459b 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> -- GitLab