From e040fd316bbe6512a2a97d90f0eb807c899929cf Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Tue, 21 Jun 2016 14:45:53 +0300 Subject: [PATCH 01/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../FileGenerator/PublicationDecorator.php | 36 ++++- .../PreProcessor/PreprocessorStrategy.php | 35 ++++- .../View/Page/Config/RendererFactory.php | 6 +- .../PublicationDecoratorTest.php | 124 +++++++++++++----- .../PreProcessor/PreprocessorStrategyTest.php | 51 +++++-- .../View/Page/Config/RendererFactoryTest.php | 93 ++++++++----- 6 files changed, 268 insertions(+), 77 deletions(-) diff --git a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php index 57af124ba1182..1d36d543451d2 100644 --- a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php +++ b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php @@ -5,6 +5,9 @@ */ namespace Magento\Developer\Model\Css\PreProcessor\FileGenerator; +use Magento\Framework\App\ObjectManagerFactory; +use Magento\Framework\App\State; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Filesystem; use Magento\Framework\View\Asset\Repository; use Magento\Framework\App\View\Asset\Publisher; @@ -36,6 +39,11 @@ class PublicationDecorator extends RelatedGenerator */ private $hasRelatedPublishing; + /** + * @var State + */ + private $state; + /** * Constructor * @@ -66,12 +74,34 @@ public function __construct( protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); - if ($this->hasRelatedPublishing - || WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH) - ) { + $isClientSideCompilation = + $this->getState()->getMode() !== State::MODE_PRODUCTION + && WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH); + + if ($this->hasRelatedPublishing || $isClientSideCompilation) { $this->assetPublisher->publish($relatedAsset); } return $relatedAsset; } + + /** + * @return State + * @deprecated + */ + private function getState() + { + if (null === $this->state) { + /** + * TODO: Fix this in scope of MAGETWO-54595 + * + * @var ObjectManagerFactory $objectManagerFactory + */ + $objectManagerFactory = ObjectManager::getInstance()->get(ObjectManagerFactory::class); + + $this->state = $objectManagerFactory->create([])->create(State::class); + } + + return $this->state; + } } diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php index a3051ce443b19..a2ec03086d79e 100644 --- a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php @@ -5,6 +5,10 @@ */ namespace Magento\Developer\Model\View\Asset\PreProcessor; +use Magento\Framework\App\ObjectManager; +use Magento\Deploy\Model\Mode; +use Magento\Framework\App\ObjectManagerFactory; +use Magento\Framework\App\State; use Magento\Framework\View\Asset\PreProcessor; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Developer\Model\Config\Source\WorkflowType; @@ -31,6 +35,11 @@ class PreprocessorStrategy implements PreProcessorInterface */ private $scopeConfig; + /** + * @var State + */ + private $state; + /** * Constructor * @@ -56,10 +65,34 @@ public function __construct( */ public function process(PreProcessor\Chain $chain) { - if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { + $isClientSideCompilation = + $this->getState()->getMode() !== State::MODE_PRODUCTION + && WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH); + + if ($isClientSideCompilation) { $this->frontendCompilation->process($chain); } else { $this->alternativeSource->process($chain); } } + + /** + * @return State + * @deprecated + */ + private function getState() + { + if (null === $this->state) { + /** + * TODO: Fix this in scope of MAGETWO-54595 + * + * @var ObjectManagerFactory $objectManagerFactory + */ + $objectManagerFactory = ObjectManager::getInstance()->get(ObjectManagerFactory::class); + + $this->state = $objectManagerFactory->create([])->create(State::class); + } + + return $this->state; + } } diff --git a/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php b/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php index c6e68be05acc9..3301d4b553c63 100644 --- a/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php +++ b/app/code/Magento/Developer/Model/View/Page/Config/RendererFactory.php @@ -6,6 +6,8 @@ namespace Magento\Developer\Model\View\Page\Config; use Magento\Developer\Model\Config\Source\WorkflowType; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\State; use Magento\Store\Model\ScopeInterface; /** @@ -58,7 +60,9 @@ public function __construct( */ public function create(array $data = []) { - $renderer = $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE); + $renderer = $this->objectManager->get(State::class)->getMode() === State::MODE_PRODUCTION ? + WorkflowType::SERVER_SIDE_COMPILATION : + $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE); return $this->objectManager->create( $this->rendererTypes[$renderer], diff --git a/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php b/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php index 1140e0fa74927..160c6164ac1fa 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php @@ -5,10 +5,17 @@ */ namespace Magento\Developer\Test\Unit\Model\Css\PreProcessor\FileGenerator; +use Magento\Framework\App\State; +use Magento\Framework\App\View\Asset\Publisher; +use Magento\Framework\Css\PreProcessor\Instruction\Import; use Magento\Framework\Filesystem; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Css\PreProcessor\File\Temporary; use Magento\Developer\Model\Css\PreProcessor\FileGenerator\PublicationDecorator; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\View\Asset\File; +use Magento\Framework\View\Asset\LocalInterface; +use Magento\Framework\View\Asset\Repository; /** * Class PublicationDecoratorTest @@ -16,60 +23,113 @@ class PublicationDecoratorTest extends \PHPUnit_Framework_TestCase { /** - * Calls generate method to access protected method generateRelatedFile + * @var PublicationDecorator */ - public function testGenerateRelatedFile() + private $model; + + /** + * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject + */ + private $filesystemMock; + + /** + * @var Temporary|\PHPUnit_Framework_MockObject_MockObject + */ + private $temporaryFileMock; + + /** + * @var Publisher|\PHPUnit_Framework_MockObject_MockObject + */ + private $publisherMock; + + /** + * @var Repository|\PHPUnit_Framework_MockObject_MockObject + */ + private $assetRepositoryMock; + + /** + * @var File|\PHPUnit_Framework_MockObject_MockObject + */ + private $relatedAssetMock; + + /** + * @var Import|\PHPUnit_Framework_MockObject_MockObject + */ + private $importGeneratorMock; + + /** + * @var LocalInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $localAssetMock; + + /** + * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $scopeConfigMock; + + /** + * @var State|\PHPUnit_Framework_MockObject_MockObject + */ + private $stateMock; + + protected function setUp() { - $filesystemMock = $this->getMockBuilder(Filesystem::class) + $this->filesystemMock = $this->getMockBuilder(Filesystem::class) ->disableOriginalConstructor() ->getMock(); - $fileTemporaryMock = $this->getMockBuilder(Temporary::class) + $this->temporaryFileMock = $this->getMockBuilder(Temporary::class) ->disableOriginalConstructor() ->getMock(); - - $publisherMock = $this->getMockBuilder('Magento\Framework\App\View\Asset\Publisher') + $this->publisherMock = $this->getMockBuilder(Publisher::class) ->disableOriginalConstructor() ->getMock(); - $assetRepoMock = $this->getMockBuilder('Magento\Framework\View\Asset\Repository') + $this->assetRepositoryMock = $this->getMockBuilder(Repository::class) ->disableOriginalConstructor() ->getMock(); - $relatedAssetMock = $this->getMockBuilder('Magento\Framework\View\Asset\File') + $this->relatedAssetMock = $this->getMockBuilder(File::class) ->disableOriginalConstructor() ->getMock(); - $importGeneratorMock = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\Instruction\Import') + $this->importGeneratorMock = $this->getMockBuilder(Import::class) ->disableOriginalConstructor() ->getMock(); - $localAssetMock = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface') + $this->localAssetMock = $this->getMockBuilder(LocalInterface::class) ->disableOriginalConstructor() ->getMock(); - $scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) ->getMockForAbstractClass(); + $this->stateMock = $this->getMockBuilder(State::class) + ->disableOriginalConstructor() + ->getMock(); - $relatedFileId = 'file_id'; + $this->model = (new ObjectManager($this))->getObject(PublicationDecorator::class, [ + 'filesystem' => $this->filesystemMock, + 'assetRepository' => $this->assetRepositoryMock, + 'temporaryFile' => $this->temporaryFileMock, + 'assetPublisher' => $this->publisherMock, + 'scopeConfig' => $this->scopeConfigMock, + 'state' => $this->stateMock, + 'hasRelatedPublishing' => true + ]); + } - $relatedFiles = [[$relatedFileId, $localAssetMock]]; + /** + * Calls generate method to access protected method generateRelatedFile + */ + public function testGenerateRelatedFile() + { + $relatedFileId = 'file_id'; + $relatedFiles = [[$relatedFileId, $this->localAssetMock]]; - $importGeneratorMock->expects(self::any()) + $this->importGeneratorMock->expects($this->any()) ->method('getRelatedFiles') - ->will(self::onConsecutiveCalls($relatedFiles, [])); - - $assetRepoMock->expects(self::any()) + ->willReturnOnConsecutiveCalls($relatedFiles, []); + $this->assetRepositoryMock->expects($this->any()) ->method('createRelated') - ->willReturn($relatedAssetMock); - - $publisherMock->expects(self::once()) + ->willReturn($this->relatedAssetMock); + $this->publisherMock->expects($this->once()) ->method('publish') - ->with($relatedAssetMock); - - $model = new PublicationDecorator( - $filesystemMock, - $assetRepoMock, - $fileTemporaryMock, - $publisherMock, - $scopeConfigMock, - true - ); - - $model->generate($importGeneratorMock); + ->with($this->relatedAssetMock); + + $this->model->generate($this->importGeneratorMock); } } diff --git a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php index 25fbe112e7dc8..fd2ce98a0dcf9 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Developer\Test\Unit\Model\View\Asset\PreProcessor; +use Magento\Framework\App\State; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\View\Asset\PreProcessor\Chain; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Developer\Model\Config\Source\WorkflowType; @@ -39,6 +41,11 @@ class PreprocessorStrategyTest extends \PHPUnit_Framework_TestCase */ private $scopeConfigMock; + /** + * @var State|\PHPUnit_Framework_MockObject_MockObject + */ + private $stateMock; + /** * Set up */ @@ -51,12 +58,16 @@ protected function setUp() ->getMock(); $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) ->getMockForAbstractClass(); + $this->stateMock = $this->getMockBuilder(State::class) + ->disableOriginalConstructor() + ->getMock(); - $this->preprocessorStrategy = new PreprocessorStrategy( - $this->alternativeSourceMock, - $this->frontendCompilationMock, - $this->scopeConfigMock - ); + $this->preprocessorStrategy = (new ObjectManager($this))->getObject(PreprocessorStrategy::class, [ + 'alternativeSource' => $this->alternativeSourceMock, + 'frontendCompilation' => $this->frontendCompilationMock, + 'scopeConfig' => $this->scopeConfigMock, + 'state' => $this->stateMock, + ]); } /** @@ -70,13 +81,34 @@ public function testProcessClientSideCompilation() ->method('getValue') ->with(WorkflowType::CONFIG_NAME_PATH) ->willReturn(WorkflowType::CLIENT_SIDE_COMPILATION); - $this->frontendCompilationMock->expects(self::once()) ->method('process') ->with($chainMock); + $this->alternativeSourceMock->expects(self::never()) + ->method('process'); + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_DEVELOPER); + + $this->preprocessorStrategy->process($chainMock); + } + + public function testProcessClientSideCompilationWithDefaultMode() + { + $chainMock = $this->getChainMock(); + $this->scopeConfigMock->expects(self::once()) + ->method('getValue') + ->with(WorkflowType::CONFIG_NAME_PATH) + ->willReturn(WorkflowType::CLIENT_SIDE_COMPILATION); + $this->frontendCompilationMock->expects(self::once()) + ->method('process') + ->with($chainMock); $this->alternativeSourceMock->expects(self::never()) ->method('process'); + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_DEFAULT); $this->preprocessorStrategy->process($chainMock); } @@ -88,17 +120,18 @@ public function testProcessAlternativeSource() { $chainMock = $this->getChainMock(); - $this->scopeConfigMock->expects(self::once()) + $this->scopeConfigMock->expects($this->never()) ->method('getValue') ->with(WorkflowType::CONFIG_NAME_PATH) ->willReturn('off'); - $this->alternativeSourceMock->expects(self::once()) ->method('process') ->with($chainMock); - $this->frontendCompilationMock->expects(self::never()) ->method('process'); + $this->stateMock->expects($this->once()) + ->method('getMode') + ->willReturn(State::MODE_PRODUCTION); $this->preprocessorStrategy->process($chainMock); } diff --git a/app/code/Magento/Developer/Test/Unit/Model/View/Page/Config/RendererFactoryTest.php b/app/code/Magento/Developer/Test/Unit/Model/View/Page/Config/RendererFactoryTest.php index 450ef2567bda0..94305fca9f9aa 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/View/Page/Config/RendererFactoryTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/View/Page/Config/RendererFactoryTest.php @@ -6,51 +6,82 @@ namespace Magento\Developer\Test\Unit\Model\View\Page\Config; use Magento\Developer\Model\Config\Source\WorkflowType; +use Magento\Developer\Model\View\Page\Config\RendererFactory; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\State; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\View\Page\Config\RendererInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +/** + * Class RendererFactoryTest + */ class RendererFactoryTest extends \PHPUnit_Framework_TestCase { - const RENDERER_TYPE = 'renderer_type'; + /** + * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $objectManagerMock; - const RENDERER_INSTANCE_NAME = 'renderer'; + /** + * @var RendererInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $rendererMock; - public function testCreate() + /** + * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $configMock; + + /** + * @var State|\PHPUnit_Framework_MockObject_MockObject + */ + private $stateMock; + + /** + * @var RendererFactory + */ + private $model; + + protected function setUp() { - // Set up mocks - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->getMockForAbstractClass(); + $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->getMockForAbstractClass(); + $this->rendererMock = $this->getMockBuilder(RendererInterface::class) ->disableOriginalConstructor() ->getMock(); - $configMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface') + $this->stateMock = $this->getMockBuilder(State::class) ->disableOriginalConstructor() ->getMock(); - $rendererMock = $this->getMockBuilder('Magento\Framework\View\Page\Config\RendererInterface') - ->disableOriginalConstructor() - ->getMock(); - $createArgs = [1,2,3]; - $objectManagerMock->expects($this->once()) + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->with(State::class) + ->willReturn($this->stateMock); + + $this->model = (new ObjectManagerHelper($this))->getObject(RendererFactory::class, [ + 'objectManager' => $this->objectManagerMock, + 'scopeConfig' => $this->configMock, + 'rendererTypes' => ['renderer_type' => 'renderer'], + ]); + } + + public function testCreate() + { + $this->stateMock->expects($this->once()) + ->method('getMode'); + $this->objectManagerMock->expects($this->once()) ->method('create') - ->with(self::RENDERER_INSTANCE_NAME, $createArgs) - ->willReturn($rendererMock); - $configMock->expects($this->once()) + ->with('renderer', []) + ->willReturn($this->rendererMock); + $this->configMock->expects($this->once()) ->method('getValue') ->with(WorkflowType::CONFIG_NAME_PATH, ScopeInterface::SCOPE_STORE) - ->willReturn(self::RENDERER_TYPE); - - // Set up System Under Test - $rendererTypes = [ - self::RENDERER_TYPE => self::RENDERER_INSTANCE_NAME - ]; - $sutArgs = [ - 'objectManager' => $objectManagerMock, - 'scopeConfig' => $configMock, - 'rendererTypes' => $rendererTypes - ]; - - $model = $objectManager->getObject('Magento\Developer\Model\View\Page\Config\RendererFactory', $sutArgs); - - // Test - $this->assertSame($rendererMock, $model->create($createArgs)); + ->willReturn('renderer_type'); + + $this->assertSame($this->rendererMock, $this->model->create()); } } From 442de0d9e58ed96a6c50de1d7641d2f08899b5e4 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Tue, 21 Jun 2016 14:53:48 +0300 Subject: [PATCH 02/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../Model/View/Asset/PreProcessor/PreprocessorStrategy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php index a2ec03086d79e..236a3fb1b6851 100644 --- a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php @@ -6,7 +6,6 @@ namespace Magento\Developer\Model\View\Asset\PreProcessor; use Magento\Framework\App\ObjectManager; -use Magento\Deploy\Model\Mode; use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\App\State; use Magento\Framework\View\Asset\PreProcessor; From 92268aeeb9ff7fda82295de36d869d622dfd33c6 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Wed, 22 Jun 2016 10:54:41 +0300 Subject: [PATCH 03/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../FileGenerator/PublicationDecorator.php | 25 ++++++++++++------- .../PreProcessor/PreprocessorStrategy.php | 25 ++++++++++++------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php index 1d36d543451d2..33b1e86d5104a 100644 --- a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php +++ b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php @@ -5,6 +5,7 @@ */ namespace Magento\Developer\Model\Css\PreProcessor\FileGenerator; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\App\State; use Magento\Framework\App\ObjectManager; @@ -75,7 +76,7 @@ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); $isClientSideCompilation = - $this->getState()->getMode() !== State::MODE_PRODUCTION + $this->getAppMode() !== State::MODE_PRODUCTION && WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH); if ($this->hasRelatedPublishing || $isClientSideCompilation) { @@ -92,16 +93,22 @@ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) private function getState() { if (null === $this->state) { - /** - * TODO: Fix this in scope of MAGETWO-54595 - * - * @var ObjectManagerFactory $objectManagerFactory - */ - $objectManagerFactory = ObjectManager::getInstance()->get(ObjectManagerFactory::class); - - $this->state = $objectManagerFactory->create([])->create(State::class); + $this->state = ObjectManager::getInstance()->get(ObjectManagerFactory::class)->create(State::class); } return $this->state; } + + /** + * TODO: Fix this in scope of MAGETWO-54595 + * + * @return string + * @deprecated + */ + private function getAppMode() + { + return $this->getState() === State::MODE_DEFAULT + ? ObjectManager::getInstance()->get(DeploymentConfig::class)->get(State::PARAM_MODE) + : $this->getState()->getMode(); + } } diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php index 236a3fb1b6851..6bb331e678717 100644 --- a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php @@ -5,6 +5,7 @@ */ namespace Magento\Developer\Model\View\Asset\PreProcessor; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\App\State; @@ -65,7 +66,7 @@ public function __construct( public function process(PreProcessor\Chain $chain) { $isClientSideCompilation = - $this->getState()->getMode() !== State::MODE_PRODUCTION + $this->getAppMode() !== State::MODE_PRODUCTION && WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH); if ($isClientSideCompilation) { @@ -82,16 +83,22 @@ public function process(PreProcessor\Chain $chain) private function getState() { if (null === $this->state) { - /** - * TODO: Fix this in scope of MAGETWO-54595 - * - * @var ObjectManagerFactory $objectManagerFactory - */ - $objectManagerFactory = ObjectManager::getInstance()->get(ObjectManagerFactory::class); - - $this->state = $objectManagerFactory->create([])->create(State::class); + $this->state = ObjectManager::getInstance()->get(ObjectManagerFactory::class)->create(State::class); } return $this->state; } + + /** + * TODO: Fix this in scope of MAGETWO-54595 + * + * @return string + * @deprecated + */ + private function getAppMode() + { + return $this->getState() === State::MODE_DEFAULT + ? ObjectManager::getInstance()->get(DeploymentConfig::class)->get(State::PARAM_MODE) + : $this->getState()->getMode(); + } } From ad0032c3a488140ac6249571580d4986bf453af0 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Wed, 22 Jun 2016 11:16:46 +0300 Subject: [PATCH 04/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../Css/PreProcessor/FileGenerator/PublicationDecorator.php | 3 +-- .../Model/View/Asset/PreProcessor/PreprocessorStrategy.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php index 33b1e86d5104a..44a7e1a4d7beb 100644 --- a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php +++ b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php @@ -6,7 +6,6 @@ namespace Magento\Developer\Model\Css\PreProcessor\FileGenerator; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\App\State; use Magento\Framework\App\ObjectManager; use Magento\Framework\Filesystem; @@ -93,7 +92,7 @@ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) private function getState() { if (null === $this->state) { - $this->state = ObjectManager::getInstance()->get(ObjectManagerFactory::class)->create(State::class); + $this->state = ObjectManager::getInstance()->get(State::class); } return $this->state; diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php index 6bb331e678717..b392264042309 100644 --- a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php @@ -7,7 +7,6 @@ use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\ObjectManager; -use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\App\State; use Magento\Framework\View\Asset\PreProcessor; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -83,7 +82,7 @@ public function process(PreProcessor\Chain $chain) private function getState() { if (null === $this->state) { - $this->state = ObjectManager::getInstance()->get(ObjectManagerFactory::class)->create(State::class); + $this->state = ObjectManager::getInstance()->get(State::class); } return $this->state; From 5e0d505dd9812639ac204aa0284e537112799e81 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 22 Jun 2016 17:39:40 +0300 Subject: [PATCH 05/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Backup/Controller/Adminhtml/Index/Rollback.php | 2 +- .../Magento/Framework/Backup/Filesystem/Helper.php | 4 ++++ .../Magento/Framework/Backup/Filesystem/Rollback/Fs.php | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php b/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php index be7a7a894d580..ec4d79c88ef31 100644 --- a/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php +++ b/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php @@ -127,7 +127,7 @@ public function execute() $errorMsg = __('Failed to validate FTP.'); } catch (\Magento\Framework\Backup\Exception\NotEnoughPermissions $e) { $this->_objectManager->get('Psr\Log\LoggerInterface')->info($e->getMessage()); - $errorMsg = __('You need more permissions to perform a rollback.'); + $errorMsg = $e->getMessage(); } catch (\Exception $e) { $this->_objectManager->get('Psr\Log\LoggerInterface')->info($e->getMessage()); $errorMsg = __('Failed to rollback.'); diff --git a/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php b/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php index 355f10226622a..2587cd543818a 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php @@ -87,10 +87,12 @@ public function getInfo($path, $infoOptions = self::INFO_ALL, $skipFiles = []) $info = []; if ($infoOptions & self::INFO_READABLE) { $info['readable'] = true; + $info['readableMeta'] = []; } if ($infoOptions & self::INFO_WRITABLE) { $info['writable'] = true; + $info['writableMeta'] = []; } if ($infoOptions & self::INFO_SIZE) { @@ -111,10 +113,12 @@ public function getInfo($path, $infoOptions = self::INFO_ALL, $skipFiles = []) if ($infoOptions & self::INFO_WRITABLE && !$item->isWritable()) { $info['writable'] = false; + $info['writableMeta'][] = $item->getPathname(); } if ($infoOptions & self::INFO_READABLE && !$item->isReadable()) { $info['readable'] = false; + $info['readableMeta'][] = $item->getPathname(); } if ($infoOptions & self::INFO_SIZE && !$item->isDir()) { diff --git a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php index 0339195bbb96a..ea081145175b7 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php @@ -39,6 +39,15 @@ public function run() ); if (!$filesInfo['writable']) { + if (!empty($filesInfo['writableMeta'])) { + throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( + new \Magento\Framework\Phrase( + 'You need write permissions for: %1', + [implode(', ', $filesInfo['writableMeta'])] + ) + ); + } + throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( new \Magento\Framework\Phrase('Unable to make rollback because not all files are writable') ); From 296e4b35a04a25d90a815e5db5d8c0e28978320c Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Thu, 23 Jun 2016 12:34:32 +0300 Subject: [PATCH 06/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../FileGenerator/PublicationDecorator.php | 2 +- .../PreProcessor/PreprocessorStrategy.php | 2 +- .../PreProcessor/PreprocessorStrategyTest.php | 30 +++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php index 44a7e1a4d7beb..0e73b4b948582 100644 --- a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php +++ b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php @@ -106,7 +106,7 @@ private function getState() */ private function getAppMode() { - return $this->getState() === State::MODE_DEFAULT + return $this->getState()->getMode() === State::MODE_DEFAULT ? ObjectManager::getInstance()->get(DeploymentConfig::class)->get(State::PARAM_MODE) : $this->getState()->getMode(); } diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php index b392264042309..ce3acccc099b4 100644 --- a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php @@ -96,7 +96,7 @@ private function getState() */ private function getAppMode() { - return $this->getState() === State::MODE_DEFAULT + return $this->getState()->getMode() === State::MODE_DEFAULT ? ObjectManager::getInstance()->get(DeploymentConfig::class)->get(State::PARAM_MODE) : $this->getState()->getMode(); } diff --git a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php index fd2ce98a0dcf9..431c5d28c707f 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Developer\Test\Unit\Model\View\Asset\PreProcessor; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\State; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\View\Asset\PreProcessor\Chain; @@ -46,6 +47,16 @@ class PreprocessorStrategyTest extends \PHPUnit_Framework_TestCase */ private $stateMock; + /** + * @var \Magento\Framework\App\ObjectManager|\PHPUnit_Framework_MockObject_MockObject + */ + private $objectMangerMock; + + /** + * @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + */ + private $deploymentConfigMock; + /** * Set up */ @@ -61,6 +72,12 @@ protected function setUp() $this->stateMock = $this->getMockBuilder(State::class) ->disableOriginalConstructor() ->getMock(); + $this->objectMangerMock = $this->getMockBuilder(\Magento\Framework\App\ObjectManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class) + ->disableOriginalConstructor() + ->getMock(); $this->preprocessorStrategy = (new ObjectManager($this))->getObject(PreprocessorStrategy::class, [ 'alternativeSource' => $this->alternativeSourceMock, @@ -86,7 +103,7 @@ public function testProcessClientSideCompilation() ->with($chainMock); $this->alternativeSourceMock->expects(self::never()) ->method('process'); - $this->stateMock->expects($this->once()) + $this->stateMock->expects($this->atLeastOnce()) ->method('getMode') ->willReturn(State::MODE_DEVELOPER); @@ -109,6 +126,15 @@ public function testProcessClientSideCompilationWithDefaultMode() $this->stateMock->expects($this->once()) ->method('getMode') ->willReturn(State::MODE_DEFAULT); + $this->objectMangerMock->expects($this->once()) + ->method('get') + ->with(DeploymentConfig::class) + ->willReturn($this->deploymentConfigMock); + $this->deploymentConfigMock->expects($this->once()) + ->method('get') + ->willReturn(State::MODE_DEFAULT); + + \Magento\Framework\App\ObjectManager::setInstance($this->objectMangerMock); $this->preprocessorStrategy->process($chainMock); } @@ -129,7 +155,7 @@ public function testProcessAlternativeSource() ->with($chainMock); $this->frontendCompilationMock->expects(self::never()) ->method('process'); - $this->stateMock->expects($this->once()) + $this->stateMock->expects($this->atLeastOnce()) ->method('getMode') ->willReturn(State::MODE_PRODUCTION); From 6d2aea9c8d6ca9a32361fd02cb934dae73416027 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Thu, 23 Jun 2016 15:48:05 +0300 Subject: [PATCH 07/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Adminhtml/Index/RollbackTest.php | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php new file mode 100644 index 0000000000000..a1a144aef0838 --- /dev/null +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php @@ -0,0 +1,173 @@ +objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->getMock(); + $this->requestMock = $this->getMockForAbstractClass( + 'Magento\Framework\App\RequestInterface', + [], + '', + false, + true, + true, + ['initForward', 'setDispatched', 'isAjax'] + ); + $this->responseMock = $this->getMockForAbstractClass( + 'Magento\Framework\App\ResponseInterface', + [], + '', + false, + true, + true, + ['setRedirect'] + ); + $this->backupModelFactoryMock = $this->getMockBuilder('Magento\Backup\Model\BackupFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->backupModelMock = $this->getMockBuilder('Magento\Backup\Model\Backup') + ->disableOriginalConstructor() + ->setMethods(['getTime', 'exists', 'getSize', 'output']) + ->getMock(); + $this->dataHelperMock = $this->getMockBuilder('Magento\Backup\Helper\Data') + ->disableOriginalConstructor() + ->setMethods(['isRollbackAllowed']) + ->getMock(); + $this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\App\Response\Http\FileFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManager = new ObjectManager($this); + $this->context = $this->objectManager->getObject( + 'Magento\Backend\App\Action\Context', + [ + 'objectManager' => $this->objectManagerMock, + 'request' => $this->requestMock, + 'response' => $this->responseMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock + ] + ); + $this->rollbackController = $this->objectManager->getObject( + 'Magento\Backup\Controller\Adminhtml\Index\Rollback', + [ + 'context' => $this->context, + 'backupModelFactory' => $this->backupModelFactoryMock, + 'fileFactory' => $this->fileFactoryMock + ] + ); + } + + public function testExecuteRollbackDisabled() + { + $rollbackAllowed = false; + + $this->dataHelperMock->expects($this->once()) + ->method('isRollbackAllowed') + ->willReturn($rollbackAllowed); + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with('Magento\Backup\Helper\Data') + ->willReturn($this->dataHelperMock); + + $this->rollbackController->execute(); + } +} From c95a620800001549a5ae43210d2e2fc98003ebb4 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Thu, 23 Jun 2016 15:53:27 +0300 Subject: [PATCH 08/35] MAGETWO-52153: [FT] CreateProductAttributeEntityTest: CreateProductAttributeEntityTestVariation8 failed --- .../Product/Attribute/CustomAttribute.php | 62 +++++++++++---- .../CreateProductAttributeEntityTest.xml | 6 ++ .../tests/app/Magento/Catalog/Test/etc/di.xml | 30 +++++++ .../Edit/Section/ProductDetails/Fpt.php | 79 +++++++++++++++++++ .../tests/app/Magento/Weee/Test/etc/di.xml | 20 +++-- 5 files changed, 177 insertions(+), 20 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php index 91d722f8ef4eb..d593e81e009c3 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php @@ -8,6 +8,10 @@ use Magento\Mtf\Client\Locator; use Magento\Mtf\Client\Element\SimpleElement; +use Magento\Mtf\Client\DriverInterface; +use Magento\Mtf\Client\ElementInterface; +use Magento\Mtf\System\Event\EventManagerInterface; +use Magento\Ui\Component\DynamicRows; /** * Catalog product custom attribute element. @@ -15,25 +19,45 @@ class CustomAttribute extends SimpleElement { /** - * Attribute input selector; + * Attribute input selector. * * @var string */ - protected $inputSelector = '[name="product[%s]"]'; + private $inputSelector = '[name="product[%s]"]'; + + /** + * Locator for data grid. + * + * @var string + */ + private $dataGrid = '[data-role="grid"]'; /** * Attribute class to element type reference. * * @var array */ - protected $classReference = [ - 'admin__control-text' => null, - 'textarea' => null, - 'hasDatepicker' => 'datepicker', - 'admin__control-select' => 'select', - 'admin__control-multiselect' => 'multiselect', - 'admin__actions-switch-checkbox' => 'switcher' - ]; + private $classReferences = []; + + /** + * Constructor + * + * @param DriverInterface $driver + * @param EventManagerInterface $eventManager + * @param Locator $locator + * @param ElementInterface $context + * @param array $classReferences + */ + public function __construct( + DriverInterface $driver, + EventManagerInterface $eventManager, + Locator $locator, + ElementInterface $context, + array $classReferences + ) { + parent::__construct($driver, $eventManager, $locator, $context); + $this->classReferences = $classReferences; + } /** * Set attribute value. @@ -48,7 +72,11 @@ public function setValue($data) $element = $this->getElementByClass($this->getElementClass($code)); $value = is_array($data) ? $data['value'] : $data; if ($value !== null) { - $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS, $element)->setValue($value); + $this->find( + str_replace('%code%', $code, $element['selector']), + Locator::SELECTOR_CSS, + $element['type'] + )->setValue($value); } } @@ -66,15 +94,15 @@ public function getValue() } /** - * Get element type by class. + * Get element data by class. * * @param string $class - * @return string + * @return array */ private function getElementByClass($class) { $element = null; - foreach ($this->classReference as $key => $reference) { + foreach ($this->classReferences as $key => $reference) { if (strpos($class, $key) !== false) { $element = $reference; } @@ -90,7 +118,11 @@ private function getElementByClass($class) */ private function getElementClass($code) { - return $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS)->getAttribute('class'); + if ($this->find($this->dataGrid)->isVisible()) { + return DynamicRows::NAME; + } else { + return $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS)->getAttribute('class'); + } } /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml index d61ef9004b2f1..2a94a12c0dbdf 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml @@ -174,6 +174,12 @@ Fixed Product Tax attr_fpt_code_%isolation% Fixed_Product_Tax_Storeview + + United States + 10 + All Websites USD + * + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml index 2356222387920..bed538ff0d8c7 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml @@ -156,4 +156,34 @@ low + + + + + [name="product[%code%]"] + null + + + [name="product[%code%]"] + null + + + [name="product[%code%]"] + \Magento\Mtf\Client\Element\DatepickerElement + + + [name="product[%code%]"] + \Magento\Mtf\Client\Element\SelectElement + + + [name="product[%code%]"] + \Magento\Mtf\Client\Element\MultiselectElement + + + [name="product[%code%]"] + \Magento\Mtf\Client\Element\SwitcherElement + + + + diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php new file mode 100644 index 0000000000000..cc5fa67779755 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php @@ -0,0 +1,79 @@ +find($this->buttonFormLocator)->isVisible()) { + $this->find($this->buttonFormLocator)->click(); + } + $countryElement = $this->find($this->country, Locator::SELECTOR_CSS, 'select'); + if ($countryElement->isVisible()) { + $countryElement->setValue($value['country']); + } + $taxElement = $this->find($this->tax, Locator::SELECTOR_CSS, 'input'); + if ($taxElement->isVisible()) { + $taxElement->setValue($value['tax']); + } + $websiteElement = $this->find($this->website, Locator::SELECTOR_CSS, 'select'); + if ($websiteElement->isVisible()) { + $websiteElement->setValue($value['website']); + } + $stateElement = $this->find($this->state, Locator::SELECTOR_CSS, 'select'); + if ($stateElement->isVisible()) { + $stateElement->setValue($value['state']); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/Weee/Test/etc/di.xml index 2097566cc2463..30be698de32ea 100644 --- a/dev/tests/functional/tests/app/Magento/Weee/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/etc/di.xml @@ -6,9 +6,19 @@ */ --> - - - high - - + + + high + + + + + + + [data-role="grid"] + \Magento\Weee\Test\Block\Adminhtml\Product\Edit\Section\ProductDetails\Fpt + + + + From ac683d4194d95d8d49c56980d8a8a2163ed827f9 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Fri, 24 Jun 2016 16:17:46 +0300 Subject: [PATCH 09/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Adminhtml/Index/RollbackTest.php | 162 ++++++++++++++++-- 1 file changed, 147 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php index a1a144aef0838..bbed8855f98a7 100644 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php @@ -63,21 +63,11 @@ class RollbackTest extends \PHPUnit_Framework_TestCase */ private $fileFactoryMock; - /** - * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $resultRawFactoryMock; - /** * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject */ private $resultRedirectFactoryMock; - /** - * @var \Magento\Framework\Controller\Result\Raw|\PHPUnit_Framework_MockObject_MockObject - */ - private $resultRawMock; - /** * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ @@ -88,6 +78,21 @@ class RollbackTest extends \PHPUnit_Framework_TestCase */ private $resultForwardMock; + /** + * @var \Magento\Framework\Backup\Factory|\PHPUnit_Framework_MockObject_MockObject + */ + private $backupFactoryMock; + + /** + * @var \Magento\Framework\Backup\BackupInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $backupManagerMock; + + /** + * @var \Magento\Backup\Model\ResourceModel\Db|\PHPUnit_Framework_MockObject_MockObject + */ + private $backupResourceModelMock; + protected function setUp() { $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') @@ -108,7 +113,7 @@ protected function setUp() false, true, true, - ['setRedirect'] + ['setRedirect', 'representJson'] ); $this->backupModelFactoryMock = $this->getMockBuilder('Magento\Backup\Model\BackupFactory') ->disableOriginalConstructor() @@ -116,11 +121,14 @@ protected function setUp() ->getMock(); $this->backupModelMock = $this->getMockBuilder('Magento\Backup\Model\Backup') ->disableOriginalConstructor() - ->setMethods(['getTime', 'exists', 'getSize', 'output']) + ->setMethods(['getTime', 'exists', 'getSize', 'output', 'validateUserPassword']) + ->getMock(); + $this->backupResourceModelMock = $this->getMockBuilder('Magento\Backup\Model\ResourceModel\Db') + ->disableOriginalConstructor() ->getMock(); $this->dataHelperMock = $this->getMockBuilder('Magento\Backup\Helper\Data') ->disableOriginalConstructor() - ->setMethods(['isRollbackAllowed']) + ->setMethods(['isRollbackAllowed', 'getBackupsDir', 'invalidateCache']) ->getMock(); $this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\App\Response\Http\FileFactory') ->disableOriginalConstructor() @@ -135,7 +143,19 @@ protected function setUp() $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') ->disableOriginalConstructor() ->getMock(); - + $this->backupFactoryMock = $this->getMockBuilder('Magento\Framework\Backup\Factory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->backupManagerMock = $this->getMockForAbstractClass( + 'Magento\Framework\Backup\BackupInterface', + [], + '', + false, + true, + true, + ['setName'] + ); $this->objectManager = new ObjectManager($this); $this->context = $this->objectManager->getObject( 'Magento\Backend\App\Action\Context', @@ -150,6 +170,7 @@ protected function setUp() 'Magento\Backup\Controller\Adminhtml\Index\Rollback', [ 'context' => $this->context, + 'backupFactory' => $this->backupFactoryMock, 'backupModelFactory' => $this->backupModelFactoryMock, 'fileFactory' => $this->fileFactoryMock ] @@ -167,7 +188,118 @@ public function testExecuteRollbackDisabled() ->method('get') ->with('Magento\Backup\Helper\Data') ->willReturn($this->dataHelperMock); - + + $this->assertSame($this->responseMock, $this->rollbackController->execute()); + } + + public function testExecuteBackupNotFound() + { + $rollbackAllowed = true; + $isAjax = true; + $time = 0; + $type = 'db'; + $exists = false; + + $this->dataHelperMock->expects($this->once()) + ->method('isRollbackAllowed') + ->willReturn($rollbackAllowed); + $this->objectManagerMock->expects($this->atLeastOnce()) + ->method('get') + ->with('Magento\Backup\Helper\Data') + ->willReturn($this->dataHelperMock); + $this->requestMock->expects($this->once()) + ->method('isAjax') + ->willReturn($isAjax); + $this->backupModelMock->expects($this->atLeastOnce()) + ->method('getTime') + ->willReturn($time); + $this->backupModelMock->expects($this->any()) + ->method('exists') + ->willReturn($exists); + $this->requestMock->expects($this->any()) + ->method('getParam') + ->willReturnMap( + [ + ['time', null, $time], + ['type', null, $type] + ] + ); + $this->backupModelFactoryMock->expects($this->once()) + ->method('create') + ->with($time, $type) + ->willReturn($this->backupModelMock); + + $this->assertSame($this->responseMock, $this->rollbackController->execute()); + } + + public function testExecute() + { + $rollbackAllowed = true; + $isAjax = true; + $time = 1; + $type = 'db'; + $exists = true; + $passwordValid = true; + + $this->dataHelperMock->expects($this->once()) + ->method('isRollbackAllowed') + ->willReturn($rollbackAllowed); + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->with('Magento\Backup\Helper\Data') + ->willReturn($this->dataHelperMock); + $this->requestMock->expects($this->once()) + ->method('isAjax') + ->willReturn($isAjax); + $this->backupModelMock->expects($this->atLeastOnce()) + ->method('getTime') + ->willReturn($time); + $this->backupModelMock->expects($this->any()) + ->method('exists') + ->willReturn($exists); + $this->requestMock->expects($this->any()) + ->method('getParam') + ->willReturnMap( + [ + ['time', null, $time], + ['type', null, $type] + ] + ); + $this->backupModelFactoryMock->expects($this->once()) + ->method('create') + ->with($time, $type) + ->willReturn($this->backupModelMock); + $this->backupManagerMock->expects($this->once()) + ->method('setBackupExtension') + ->willReturn($this->backupManagerMock); + $this->backupManagerMock->expects($this->once()) + ->method('setTime') + ->willReturn($this->backupManagerMock); + $this->backupManagerMock->expects($this->once()) + ->method('setBackupsDir') + ->willReturn($this->backupManagerMock); + $this->backupManagerMock->expects($this->once()) + ->method('setName') + ->willReturn($this->backupManagerMock); + $this->backupManagerMock->expects($this->once()) + ->method('setResourceModel') + ->willReturn($this->backupManagerMock); + $this->backupFactoryMock->expects($this->once()) + ->method('create') + ->with($type) + ->willReturn($this->backupManagerMock); + $this->objectManagerMock->expects($this->at(2)) + ->method('create') + ->with('Magento\Backup\Model\ResourceModel\Db', []) + ->willReturn($this->backupResourceModelMock); + $this->objectManagerMock->expects($this->at(3)) + ->method('create') + ->with('Magento\Backup\Model\Backup', []) + ->willReturn($this->backupModelMock); + $this->backupModelMock->expects($this->once()) + ->method('validateUserPassword') + ->willReturn($passwordValid); + $this->rollbackController->execute(); } } From dae989a8c01dd23bfc2aa1e83aea2bf5d64debb2 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 29 Jun 2016 14:53:54 +0300 Subject: [PATCH 10/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Test/Unit/Filesystem/Rollback/FsTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php b/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php new file mode 100644 index 0000000000000..8ea14becf68c0 --- /dev/null +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php @@ -0,0 +1,47 @@ +objectManager = new ObjectManager($this); + $this->snapshotMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem::class) + ->getMock(); + $this->fs = $this->objectManager->getObject( + \Magento\Framework\Backup\Filesystem\Rollback\Fs::class, + ['snapshotObject' => $this->snapshotMock] + ); + + } + + /** + * @expectedException \Magento\Framework\Backup\Exception\CantLoadSnapshot + * @expectedExceptionMessage Can't load snapshot archive + */ + public function testRunCantLoadSnapshotException() + { + $this->fs->run(); + } +} From 372947d5c7ae87685e87d089cd8192d07607c4f8 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 29 Jun 2016 14:54:09 +0300 Subject: [PATCH 11/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Adminhtml/Index/RollbackTest.php | 69 +++++++------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php index bbed8855f98a7..a04d5157f461f 100644 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php @@ -95,70 +95,53 @@ class RollbackTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class) ->getMock(); - $this->requestMock = $this->getMockForAbstractClass( - 'Magento\Framework\App\RequestInterface', - [], - '', - false, - true, - true, - ['initForward', 'setDispatched', 'isAjax'] - ); - $this->responseMock = $this->getMockForAbstractClass( - 'Magento\Framework\App\ResponseInterface', - [], - '', - false, - true, - true, - ['setRedirect', 'representJson'] - ); - $this->backupModelFactoryMock = $this->getMockBuilder('Magento\Backup\Model\BackupFactory') + $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class) + ->setMethods(['initForward', 'setDispatched', 'isAjax']) + ->getMockForAbstractClass(); + $this->responseMock = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class) + ->setMethods(['setRedirect', 'representJson']) + ->getMockForAbstractClass(); + $this->backupModelFactoryMock = $this->getMockBuilder(\Magento\Backup\Model\BackupFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->backupModelMock = $this->getMockBuilder('Magento\Backup\Model\Backup') + $this->backupModelMock = $this->getMockBuilder(\Magento\Backup\Model\Backup::class) ->disableOriginalConstructor() ->setMethods(['getTime', 'exists', 'getSize', 'output', 'validateUserPassword']) ->getMock(); - $this->backupResourceModelMock = $this->getMockBuilder('Magento\Backup\Model\ResourceModel\Db') + $this->backupResourceModelMock = $this->getMockBuilder(\Magento\Backup\Model\ResourceModel\Db::class) ->disableOriginalConstructor() ->getMock(); - $this->dataHelperMock = $this->getMockBuilder('Magento\Backup\Helper\Data') + $this->dataHelperMock = $this->getMockBuilder(\Magento\Backup\Helper\Data::class) ->disableOriginalConstructor() ->setMethods(['isRollbackAllowed', 'getBackupsDir', 'invalidateCache']) ->getMock(); - $this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\App\Response\Http\FileFactory') + $this->fileFactoryMock = $this->getMockBuilder(\Magento\Framework\App\Response\Http\FileFactory::class) ->disableOriginalConstructor() ->getMock(); - $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + $this->resultRedirectFactoryMock = + $this->getMockBuilder(\Magento\Backend\Model\View\Result\RedirectFactory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + $this->resultRedirectMock = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class) ->disableOriginalConstructor() ->getMock(); - $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + $this->resultForwardMock = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Forward::class) ->disableOriginalConstructor() ->getMock(); - $this->backupFactoryMock = $this->getMockBuilder('Magento\Framework\Backup\Factory') + $this->backupFactoryMock = $this->getMockBuilder(\Magento\Framework\Backup\Factory::class) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->backupManagerMock = $this->getMockForAbstractClass( - 'Magento\Framework\Backup\BackupInterface', - [], - '', - false, - true, - true, - ['setName'] - ); + $this->backupManagerMock = $this->getMockBuilder(\Magento\Framework\Backup\BackupInterface::class) + ->setMethods(['setName']) + ->getMockForAbstractClass(); $this->objectManager = new ObjectManager($this); $this->context = $this->objectManager->getObject( - 'Magento\Backend\App\Action\Context', + \Magento\Backend\App\Action\Context::class, [ 'objectManager' => $this->objectManagerMock, 'request' => $this->requestMock, @@ -167,7 +150,7 @@ protected function setUp() ] ); $this->rollbackController = $this->objectManager->getObject( - 'Magento\Backup\Controller\Adminhtml\Index\Rollback', + \Magento\Backup\Controller\Adminhtml\Index\Rollback::class, [ 'context' => $this->context, 'backupFactory' => $this->backupFactoryMock, @@ -205,7 +188,7 @@ public function testExecuteBackupNotFound() ->willReturn($rollbackAllowed); $this->objectManagerMock->expects($this->atLeastOnce()) ->method('get') - ->with('Magento\Backup\Helper\Data') + ->with(\Magento\Backup\Helper\Data::class) ->willReturn($this->dataHelperMock); $this->requestMock->expects($this->once()) ->method('isAjax') @@ -246,7 +229,7 @@ public function testExecute() ->willReturn($rollbackAllowed); $this->objectManagerMock->expects($this->any()) ->method('get') - ->with('Magento\Backup\Helper\Data') + ->with(\Magento\Backup\Helper\Data::class) ->willReturn($this->dataHelperMock); $this->requestMock->expects($this->once()) ->method('isAjax') @@ -290,11 +273,11 @@ public function testExecute() ->willReturn($this->backupManagerMock); $this->objectManagerMock->expects($this->at(2)) ->method('create') - ->with('Magento\Backup\Model\ResourceModel\Db', []) + ->with(\Magento\Backup\Model\ResourceModel\Db::class, []) ->willReturn($this->backupResourceModelMock); $this->objectManagerMock->expects($this->at(3)) ->method('create') - ->with('Magento\Backup\Model\Backup', []) + ->with(\Magento\Backup\Model\Backup::class, []) ->willReturn($this->backupModelMock); $this->backupModelMock->expects($this->once()) ->method('validateUserPassword') From ce907ab9e0de6955b00be946dbdc3d4b3c98d131 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 29 Jun 2016 14:54:23 +0300 Subject: [PATCH 12/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Backup/Filesystem/Rollback/FsTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php b/dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php new file mode 100644 index 0000000000000..c7359a0991dad --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php @@ -0,0 +1,14 @@ + Date: Thu, 30 Jun 2016 15:35:23 +0300 Subject: [PATCH 13/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Backup/Filesystem/Rollback/FsTest.php | 14 ---- .../Backup/Filesystem/Rollback/Fs.php | 22 +++++- .../Test/Unit/Filesystem/Rollback/FsTest.php | 72 +++++++++++++++++-- .../Filesystem/Rollback/_files/ioMock.php | 28 ++++++++ 4 files changed, 117 insertions(+), 19 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php create mode 100644 lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/_files/ioMock.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php b/dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php deleted file mode 100644 index c7359a0991dad..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Backup/Filesystem/Rollback/FsTest.php +++ /dev/null @@ -1,14 +0,0 @@ -getFsHelper(); $filesInfo = $fsHelper->getInfo( $this->_snapshot->getRootDir(), @@ -68,4 +75,17 @@ public function run() $fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths()); $archiver->unpack($snapshotPath, $this->_snapshot->getRootDir()); } + + /** + * @return \Magento\Framework\Backup\Filesystem\Helper + * @deprecated + */ + private function getFsHelper() + { + if (!$this->fsHelper) { + $this->fsHelper = ObjectManager::getInstance()->get(\Magento\Framework\Backup\Filesystem\Helper::class); + } + + return $this->fsHelper; + } } diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php b/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php index 8ea14becf68c0..dbd830a8fc9f2 100644 --- a/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/FsTest.php @@ -7,6 +7,8 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +require_once __DIR__ . '/_files/ioMock.php'; + class FsTest extends \PHPUnit_Framework_TestCase { /** @@ -19,29 +21,91 @@ class FsTest extends \PHPUnit_Framework_TestCase */ private $snapshotMock; + /** + * @var \Magento\Framework\Backup\Filesystem\Helper|\PHPUnit_Framework_MockObject_MockObject + */ + private $fsHelperMock; + /** * @var \Magento\Framework\Backup\Filesystem\Rollback\Fs */ private $fs; + /** + * @var string + */ + private $backupPath; + + /** + * @var string + */ + private $rootDir; + + /** + * @var array + */ + private $ignorePaths; + protected function setUp() { + $this->backupPath = '/some/test/path'; + $this->rootDir = '/'; + $this->ignorePaths = []; + $this->objectManager = new ObjectManager($this); $this->snapshotMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem::class) + ->setMethods(['getBackupPath', 'getRootDir', 'getIgnorePaths']) + ->getMock(); + $this->snapshotMock->expects($this->any()) + ->method('getBackupPath') + ->willReturn($this->backupPath); + $this->snapshotMock->expects($this->any()) + ->method('getRootDir') + ->willReturn($this->rootDir); + $this->snapshotMock->expects($this->any()) + ->method('getIgnorePaths') + ->willReturn($this->ignorePaths); + $this->fsHelperMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem\Helper::class) + ->setMethods(['getInfo', 'rm']) ->getMock(); $this->fs = $this->objectManager->getObject( \Magento\Framework\Backup\Filesystem\Rollback\Fs::class, - ['snapshotObject' => $this->snapshotMock] + [ + 'snapshotObject' => $this->snapshotMock, + 'fsHelper' => $this->fsHelperMock + ] ); } /** - * @expectedException \Magento\Framework\Backup\Exception\CantLoadSnapshot - * @expectedExceptionMessage Can't load snapshot archive + * @expectedException \Magento\Framework\Backup\Exception\NotEnoughPermissions + * @expectedExceptionMessage You need write permissions for: test1, test2 */ - public function testRunCantLoadSnapshotException() + public function testRunNotEnoughPermissions() { + $fsInfo = [ + 'writable' => false, + 'writableMeta' => ['test1', 'test2'] + ]; + + $this->fsHelperMock->expects($this->once()) + ->method('getInfo') + ->willReturn($fsInfo); + $this->fs->run(); + } + + public function testRun() + { + $fsInfo = ['writable' => true]; + + $this->fsHelperMock->expects($this->once()) + ->method('getInfo') + ->willReturn($fsInfo); + $this->fsHelperMock->expects($this->once()) + ->method('rm') + ->with($this->rootDir, $this->ignorePaths); + $this->fs->run(); } } diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/_files/ioMock.php b/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/_files/ioMock.php new file mode 100644 index 0000000000000..3ac56872e87b9 --- /dev/null +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/Filesystem/Rollback/_files/ioMock.php @@ -0,0 +1,28 @@ + Date: Fri, 1 Jul 2016 11:02:13 +0300 Subject: [PATCH 14/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Magento/Framework/Backup/Filesystem.php | 50 +++++++++++++++-- .../Backup/Test/Unit/FilesystemTest.php | 56 +++++++++++++++++++ .../Framework/Backup/Test/Unit/MediaTest.php | 24 +++++++- 3 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 lib/internal/Magento/Framework/Backup/Test/Unit/FilesystemTest.php diff --git a/lib/internal/Magento/Framework/Backup/Filesystem.php b/lib/internal/Magento/Framework/Backup/Filesystem.php index ce1aa07ea37a3..8731e18816aec 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem.php @@ -7,7 +7,9 @@ // @codingStandardsIgnoreFile namespace Magento\Framework\Backup; + use Magento\Framework\Filesystem\DriverInterface; +use Magento\Framework\App\ObjectManager; /** * Class to work with filesystem backups @@ -58,6 +60,16 @@ class Filesystem extends AbstractBackup */ protected $_ftpPath; + /** + * @var \Magento\Framework\Backup\Filesystem\Rollback\Ftp + */ + protected $rollBackFtp; + + /** + * @var \Magento\Framework\Backup\Filesystem\Rollback\Fs + */ + protected $rollBackFs; + /** * Implementation Rollback functionality for Filesystem * @@ -71,11 +83,7 @@ public function rollback() set_time_limit(0); ignore_user_abort(true); - $rollbackWorker = $this->_useFtp ? new \Magento\Framework\Backup\Filesystem\Rollback\Ftp( - $this - ) : new \Magento\Framework\Backup\Filesystem\Rollback\Fs( - $this - ); + $rollbackWorker = $this->_useFtp ? $this->getRollBackFtp() : $this->getRollBackFs(); $rollbackWorker->run(); $this->_lastOperationSucceed = true; @@ -299,4 +307,36 @@ protected function _getTarTmpPath() $tmpName = '~tmp-' . microtime(true) . '.tar'; return $this->getBackupsDir() . '/' . $tmpName; } + + /** + * @return \Magento\Framework\Backup\Filesystem\Rollback\Ftp + * @deprecated + */ + protected function getRollBackFtp() + { + if (!$this->rollBackFtp) { + $this->rollBackFtp = ObjectManager::getInstance()->create( + \Magento\Framework\Backup\Filesystem\Rollback\Ftp::class, + [$this] + ); + } + + return $this->rollBackFtp; + } + + /** + * @return \Magento\Framework\Backup\Filesystem\Rollback\Fs + * @deprecated + */ + protected function getRollBackFs() + { + if (!$this->rollBackFs) { + $this->rollBackFs = ObjectManager::getInstance()->create( + \Magento\Framework\Backup\Filesystem\Rollback\Fs::class, + [$this] + ); + } + + return $this->rollBackFs; + } } diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/FilesystemTest.php b/lib/internal/Magento/Framework/Backup/Test/Unit/FilesystemTest.php new file mode 100644 index 0000000000000..9b607e1569a38 --- /dev/null +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/FilesystemTest.php @@ -0,0 +1,56 @@ +objectManager = new ObjectManager($this); + $this->fsMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem\Rollback\Fs::class) + ->disableOriginalConstructor() + ->getMock(); + $this->ftpMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem\Rollback\Ftp::class) + ->disableOriginalConstructor() + ->getMock(); + $this->snapshotMock = $this->getMockBuilder(\Magento\Framework\Backup\Filesystem::class) + ->getMock(); + $this->filesystem = $this->objectManager->getObject( + \Magento\Framework\Backup\Filesystem::class, + [ + 'rollBackFtp' => $this->ftpMock, + 'rollBackFs' => $this->fsMock + ] + ); + } + + public function testRollback() + { + $this->assertTrue($this->filesystem->rollback()); + } +} diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/MediaTest.php b/lib/internal/Magento/Framework/Backup/Test/Unit/MediaTest.php index c58cb128895f9..64856f65c8ca3 100644 --- a/lib/internal/Magento/Framework/Backup/Test/Unit/MediaTest.php +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/MediaTest.php @@ -5,10 +5,17 @@ */ namespace Magento\Framework\Backup\Test\Unit; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + require_once __DIR__ . '/_files/io.php'; class MediaTest extends \PHPUnit_Framework_TestCase { + /** + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + private $objectManager; + /** * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */ @@ -24,6 +31,11 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ protected $_backupDbMock; + /** + * @var \Magento\Framework\Backup\Filesystem\Rollback\Fs + */ + private $fsMock; + public static function setUpBeforeClass() { require __DIR__ . '/_files/app_dirs.php'; @@ -36,6 +48,7 @@ public static function tearDownAfterClass() protected function setUp() { + $this->objectManager = new ObjectManager($this); $this->_backupDbMock = $this->getMock('Magento\Framework\Backup\Db', [], [], '', false); $this->_backupDbMock->expects($this->any())->method('setBackupExtension')->will($this->returnSelf()); @@ -69,6 +82,8 @@ protected function setUp() )->will( $this->returnValue($this->_backupDbMock) ); + + $this->fsMock = $this->getMock('Magento\Framework\Backup\Filesystem\Rollback\Fs', [], [], '', false); } /** @@ -81,7 +96,14 @@ public function testAction($action) $rootDir = str_replace('\\', '/', TESTS_TEMP_DIR) . '/Magento/Backup/data'; - $model = new \Magento\Framework\Backup\Media($this->_filesystemMock, $this->_backupFactoryMock); + $model = $this->objectManager->getObject( + \Magento\Framework\Backup\Media::class, + [ + 'filesystem' => $this->_filesystemMock, + 'backupFactory' => $this->_backupFactoryMock, + 'rollBackFs' => $this->fsMock + ] + ); $model->setRootDir($rootDir); $model->setBackupsDir($rootDir); $model->{$action}(); From ef42ac8ea958d7173cb90907c112f00a2db86bd9 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Fri, 1 Jul 2016 11:18:22 +0300 Subject: [PATCH 15/35] MAGETWO-44479: Rollback database and media backup is not functioning --- .../Backup/Test/Unit/NomediaTest.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/NomediaTest.php b/lib/internal/Magento/Framework/Backup/Test/Unit/NomediaTest.php index 53829a16d82e5..4126614cdb76b 100644 --- a/lib/internal/Magento/Framework/Backup/Test/Unit/NomediaTest.php +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/NomediaTest.php @@ -5,10 +5,17 @@ */ namespace Magento\Framework\Backup\Test\Unit; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + require_once __DIR__ . '/_files/io.php'; class NomediaTest extends \PHPUnit_Framework_TestCase { + /** + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + private $objectManager; + /** * @var \Magento\Framework\Filesystem */ @@ -24,6 +31,11 @@ class NomediaTest extends \PHPUnit_Framework_TestCase */ protected $_backupDbMock; + /** + * @var \Magento\Framework\Backup\Filesystem\Rollback\Fs + */ + private $fsMock; + public static function setUpBeforeClass() { require __DIR__ . '/_files/app_dirs.php'; @@ -36,6 +48,7 @@ public static function tearDownAfterClass() protected function setUp() { + $this->objectManager = new ObjectManager($this); $this->_backupDbMock = $this->getMock('Magento\Framework\Backup\Db', [], [], '', false); $this->_backupDbMock->expects($this->any())->method('setBackupExtension')->will($this->returnSelf()); @@ -69,6 +82,8 @@ protected function setUp() )->will( $this->returnValue($this->_backupDbMock) ); + + $this->fsMock = $this->getMock('Magento\Framework\Backup\Filesystem\Rollback\Fs', [], [], '', false); } /** @@ -81,7 +96,14 @@ public function testAction($action) $rootDir = TESTS_TEMP_DIR . '/Magento/Backup/data'; - $model = new \Magento\Framework\Backup\Nomedia($this->_filesystemMock, $this->_backupFactoryMock); + $model = $this->objectManager->getObject( + \Magento\Framework\Backup\Nomedia::class, + [ + 'filesystem' => $this->_filesystemMock, + 'backupFactory' => $this->_backupFactoryMock, + 'rollBackFs' => $this->fsMock + ] + ); $model->setRootDir($rootDir); $model->setBackupsDir($rootDir); $model->{$action}(); From 42b0a12a99057f302191752826cfdf0fd8bee8e0 Mon Sep 17 00:00:00 2001 From: Viktor Paladiychuk Date: Mon, 11 Jul 2016 19:04:32 +0300 Subject: [PATCH 16/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- app/code/Magento/Deploy/Model/Deployer.php | 81 +++++++++++++++++++++- app/code/Magento/Deploy/composer.json | 3 +- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 5ce8251db1e8b..673ab11fd64bc 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -6,6 +6,10 @@ namespace Magento\Deploy\Model; +use Magento\Developer\Model\Config\Source\WorkflowType; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\State; +use Magento\Config\Model\Config; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Asset\ContentProcessorException; use Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface; @@ -74,6 +78,21 @@ class Deployer */ private $alternativeSources; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @var State + */ + private $state; + + /** + * @var Config\Factory + */ + private $configFactory; + /** * Constructor * @@ -107,6 +126,63 @@ function (AlternativeSourceInterface $alternative) { $this->alternativeSources = $alternativeSources; } + /** + * @return Config\Factory + */ + private function getConfigFactory() + { + if ($this->configFactory === null) { + $this->configFactory = $this->objectManager->get(Config\Factory::class); + } + return $this->configFactory; + } + + /** + * Return ScopeConfig instance + * + * @return ScopeConfigInterface + * @deprecated + */ + private function getScopeConfig() + { + if ($this->scopeConfig === null) { + $this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + } + return $this->scopeConfig; + } + + /** + * Enable server side compilation of static files for production mode + * + * @throws \Exception + */ + private function ensureServerSideCompilationForProduction() + { + if ($this->getScopeConfig()->getValue(WorkflowType::CONFIG_NAME_PATH) + == WorkflowType::CLIENT_SIDE_COMPILATION + && $this->getState()->getMode() == State::MODE_PRODUCTION) { + + /** @var Config $config */ + $config = $this->getConfigFactory()->create(); + $config->setDataByPath(WorkflowType::CONFIG_NAME_PATH, WorkflowType::SERVER_SIDE_COMPILATION); + $config->save(); + } + } + + /** + * Return State instance + * + * @return State + * @deprecated + */ + private function getState() + { + if ($this->state === null) { + $this->state = $this->objectManager->get(State::class); + } + return $this->state; + } + /** * Populate all static view files for specified root path and list of languages * @@ -257,12 +333,13 @@ private function collectAppFiles($requestedLocales) */ private function emulateApplicationArea($areaCode) { - $this->objectManager = $this->omFactory->create( - [\Magento\Framework\App\State::PARAM_MODE => \Magento\Framework\App\State::MODE_DEFAULT] + $this->objectManager = $this->omFactory->create([] +// [\Magento\Framework\App\State::PARAM_MODE => \Magento\Framework\App\State::MODE_DEFAULT] ); /** @var \Magento\Framework\App\State $appState */ $appState = $this->objectManager->get('Magento\Framework\App\State'); $appState->setAreaCode($areaCode); + $this->ensureServerSideCompilationForProduction(); $this->assetRepo = $this->objectManager->get('Magento\Framework\View\Asset\Repository'); $this->assetPublisher = $this->objectManager->create('Magento\Framework\App\View\Asset\Publisher'); $this->htmlMinifier = $this->objectManager->get('Magento\Framework\View\Template\Html\MinifierInterface'); diff --git a/app/code/Magento/Deploy/composer.json b/app/code/Magento/Deploy/composer.json index 3d69f9864698a..cfe31bae3c370 100644 --- a/app/code/Magento/Deploy/composer.json +++ b/app/code/Magento/Deploy/composer.json @@ -7,7 +7,8 @@ "magento/module-store": "100.2.*", "magento/module-theme": "100.2.*", "magento/module-require-js": "100.2.*", - "magento/module-user": "100.2.*" + "magento/module-user": "100.2.*", + "magento/module-config": "100.2.*" }, "type": "magento2-module", "version": "100.2.0-dev", From bb98ed9a4b300561624b647c71230b3a48e548fd Mon Sep 17 00:00:00 2001 From: Viktor Paladiychuk Date: Tue, 12 Jul 2016 11:20:33 +0300 Subject: [PATCH 17/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- app/code/Magento/Deploy/Model/Deployer.php | 80 +--------------------- 1 file changed, 1 insertion(+), 79 deletions(-) diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 673ab11fd64bc..0aa9f1d6f4048 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -6,8 +6,6 @@ namespace Magento\Deploy\Model; -use Magento\Developer\Model\Config\Source\WorkflowType; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\State; use Magento\Config\Model\Config; use Magento\Framework\Exception\LocalizedException; @@ -78,21 +76,6 @@ class Deployer */ private $alternativeSources; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - - /** - * @var State - */ - private $state; - - /** - * @var Config\Factory - */ - private $configFactory; - /** * Constructor * @@ -126,63 +109,6 @@ function (AlternativeSourceInterface $alternative) { $this->alternativeSources = $alternativeSources; } - /** - * @return Config\Factory - */ - private function getConfigFactory() - { - if ($this->configFactory === null) { - $this->configFactory = $this->objectManager->get(Config\Factory::class); - } - return $this->configFactory; - } - - /** - * Return ScopeConfig instance - * - * @return ScopeConfigInterface - * @deprecated - */ - private function getScopeConfig() - { - if ($this->scopeConfig === null) { - $this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); - } - return $this->scopeConfig; - } - - /** - * Enable server side compilation of static files for production mode - * - * @throws \Exception - */ - private function ensureServerSideCompilationForProduction() - { - if ($this->getScopeConfig()->getValue(WorkflowType::CONFIG_NAME_PATH) - == WorkflowType::CLIENT_SIDE_COMPILATION - && $this->getState()->getMode() == State::MODE_PRODUCTION) { - - /** @var Config $config */ - $config = $this->getConfigFactory()->create(); - $config->setDataByPath(WorkflowType::CONFIG_NAME_PATH, WorkflowType::SERVER_SIDE_COMPILATION); - $config->save(); - } - } - - /** - * Return State instance - * - * @return State - * @deprecated - */ - private function getState() - { - if ($this->state === null) { - $this->state = $this->objectManager->get(State::class); - } - return $this->state; - } - /** * Populate all static view files for specified root path and list of languages * @@ -333,18 +259,14 @@ private function collectAppFiles($requestedLocales) */ private function emulateApplicationArea($areaCode) { - $this->objectManager = $this->omFactory->create([] -// [\Magento\Framework\App\State::PARAM_MODE => \Magento\Framework\App\State::MODE_DEFAULT] - ); + $this->objectManager = $this->omFactory->create([]); /** @var \Magento\Framework\App\State $appState */ $appState = $this->objectManager->get('Magento\Framework\App\State'); $appState->setAreaCode($areaCode); - $this->ensureServerSideCompilationForProduction(); $this->assetRepo = $this->objectManager->get('Magento\Framework\View\Asset\Repository'); $this->assetPublisher = $this->objectManager->create('Magento\Framework\App\View\Asset\Publisher'); $this->htmlMinifier = $this->objectManager->get('Magento\Framework\View\Template\Html\MinifierInterface'); $this->bundleManager = $this->objectManager->get('Magento\Framework\View\Asset\Bundle\Manager'); - } /** From 06e5c8b8da7a9bdb22a111d3a6e9687d3d2ca118 Mon Sep 17 00:00:00 2001 From: Viktor Paladiychuk Date: Tue, 12 Jul 2016 13:15:21 +0300 Subject: [PATCH 18/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- app/code/Magento/Deploy/composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Deploy/composer.json b/app/code/Magento/Deploy/composer.json index cfe31bae3c370..3d69f9864698a 100644 --- a/app/code/Magento/Deploy/composer.json +++ b/app/code/Magento/Deploy/composer.json @@ -7,8 +7,7 @@ "magento/module-store": "100.2.*", "magento/module-theme": "100.2.*", "magento/module-require-js": "100.2.*", - "magento/module-user": "100.2.*", - "magento/module-config": "100.2.*" + "magento/module-user": "100.2.*" }, "type": "magento2-module", "version": "100.2.0-dev", From 7e181d1344578771f624726a99374432ff468062 Mon Sep 17 00:00:00 2001 From: Viktor Paladiychuk Date: Tue, 12 Jul 2016 14:07:13 +0300 Subject: [PATCH 19/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../FileGenerator/PublicationDecorator.php | 15 +-------------- .../Asset/PreProcessor/PreprocessorStrategy.php | 16 +--------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php index 0e73b4b948582..ab7b46ed35d7e 100644 --- a/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php +++ b/app/code/Magento/Developer/Model/Css/PreProcessor/FileGenerator/PublicationDecorator.php @@ -75,7 +75,7 @@ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); $isClientSideCompilation = - $this->getAppMode() !== State::MODE_PRODUCTION + $this->getState()->getMode() !== State::MODE_PRODUCTION && WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH); if ($this->hasRelatedPublishing || $isClientSideCompilation) { @@ -97,17 +97,4 @@ private function getState() return $this->state; } - - /** - * TODO: Fix this in scope of MAGETWO-54595 - * - * @return string - * @deprecated - */ - private function getAppMode() - { - return $this->getState()->getMode() === State::MODE_DEFAULT - ? ObjectManager::getInstance()->get(DeploymentConfig::class)->get(State::PARAM_MODE) - : $this->getState()->getMode(); - } } diff --git a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php index ce3acccc099b4..aa40db410a4ce 100644 --- a/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php +++ b/app/code/Magento/Developer/Model/View/Asset/PreProcessor/PreprocessorStrategy.php @@ -65,7 +65,7 @@ public function __construct( public function process(PreProcessor\Chain $chain) { $isClientSideCompilation = - $this->getAppMode() !== State::MODE_PRODUCTION + $this->getState()->getMode() !== State::MODE_PRODUCTION && WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH); if ($isClientSideCompilation) { @@ -84,20 +84,6 @@ private function getState() if (null === $this->state) { $this->state = ObjectManager::getInstance()->get(State::class); } - return $this->state; } - - /** - * TODO: Fix this in scope of MAGETWO-54595 - * - * @return string - * @deprecated - */ - private function getAppMode() - { - return $this->getState()->getMode() === State::MODE_DEFAULT - ? ObjectManager::getInstance()->get(DeploymentConfig::class)->get(State::PARAM_MODE) - : $this->getState()->getMode(); - } } From fd1cec8c260b8dea16fc11b88197f3b42210ee42 Mon Sep 17 00:00:00 2001 From: Viktor Paladiychuk Date: Tue, 12 Jul 2016 14:12:02 +0300 Subject: [PATCH 20/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- app/code/Magento/Deploy/Model/Deployer.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index 0aa9f1d6f4048..0e49272c0c1ca 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -6,8 +6,6 @@ namespace Magento\Deploy\Model; -use Magento\Framework\App\State; -use Magento\Config\Model\Config; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Asset\ContentProcessorException; use Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface; From d7c23c162259d28d64ccd41de0a1f0d061d7b4a1 Mon Sep 17 00:00:00 2001 From: Viktor Paladiychuk Date: Tue, 12 Jul 2016 14:37:37 +0300 Subject: [PATCH 21/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../Asset/PreProcessor/PreprocessorStrategyTest.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php index 431c5d28c707f..36e3f4a49ce6e 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php @@ -75,9 +75,6 @@ protected function setUp() $this->objectMangerMock = $this->getMockBuilder(\Magento\Framework\App\ObjectManager::class) ->disableOriginalConstructor() ->getMock(); - $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class) - ->disableOriginalConstructor() - ->getMock(); $this->preprocessorStrategy = (new ObjectManager($this))->getObject(PreprocessorStrategy::class, [ 'alternativeSource' => $this->alternativeSourceMock, @@ -126,13 +123,6 @@ public function testProcessClientSideCompilationWithDefaultMode() $this->stateMock->expects($this->once()) ->method('getMode') ->willReturn(State::MODE_DEFAULT); - $this->objectMangerMock->expects($this->once()) - ->method('get') - ->with(DeploymentConfig::class) - ->willReturn($this->deploymentConfigMock); - $this->deploymentConfigMock->expects($this->once()) - ->method('get') - ->willReturn(State::MODE_DEFAULT); \Magento\Framework\App\ObjectManager::setInstance($this->objectMangerMock); From a533518f8c1ef6b000d8cbcdad0fb5607ff29df4 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Tue, 19 Jul 2016 10:51:22 +0300 Subject: [PATCH 22/35] MAGETWO-53344: Unable to upload change robots.txt file via admin panel --- .../Magento/Framework/Filesystem/Directory/Write.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php index 0a46a17c10b22..b440f65f6581c 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php @@ -240,12 +240,22 @@ public function isWritable($path = null) * @param string $path * @param string $mode * @return \Magento\Framework\Filesystem\File\WriteInterface + * @throws \Magento\Framework\Exception\FileSystemException */ public function openFile($path, $mode = 'w') { $folder = dirname($path); $this->create($folder); - $this->assertWritable($folder); + if (!$this->isExist($path)) { + $this->assertWritable($folder); + } else { + if (!$this->isWritable($path)) { + throw new FileSystemException(new \Magento\Framework\Phrase( + 'The path "%1" is not writable', + [$this->getAbsolutePath($path)] + )); + } + } $absolutePath = $this->driver->getAbsolutePath($this->path, $path); return $this->fileFactory->create($absolutePath, $this->driver, $mode); } From 61e345d6a23db28921bde3f3e03616f027249ef1 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Tue, 19 Jul 2016 19:25:45 +0300 Subject: [PATCH 23/35] MAGETWO-52153: [FT] CreateProductAttributeEntityTest: CreateProductAttributeEntityTestVariation8 failed - Updated CustomAttribute data source; --- .../Product/Attribute/CustomAttribute.php | 15 +++---- .../CatalogProductSimple/CustomAttribute.php | 39 ++++++++++++++++--- .../CreateProductAttributeEntityTest.xml | 2 +- .../tests/app/Magento/Catalog/Test/etc/di.xml | 10 ++--- .../Edit/Section/ProductDetails/Fpt.php | 27 +++++-------- 5 files changed, 56 insertions(+), 37 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php index d593e81e009c3..fb3fb87e56c19 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php @@ -11,7 +11,6 @@ use Magento\Mtf\Client\DriverInterface; use Magento\Mtf\Client\ElementInterface; use Magento\Mtf\System\Event\EventManagerInterface; -use Magento\Ui\Component\DynamicRows; /** * Catalog product custom attribute element. @@ -94,17 +93,17 @@ public function getValue() } /** - * Get element data by class. + * Get element by class. * * @param string $class - * @return array + * @return array|null */ private function getElementByClass($class) { $element = null; foreach ($this->classReferences as $key => $reference) { if (strpos($class, $key) !== false) { - $element = $reference; + return $this->classReferences[$class]; } } return $element; @@ -118,11 +117,9 @@ private function getElementByClass($class) */ private function getElementClass($code) { - if ($this->find($this->dataGrid)->isVisible()) { - return DynamicRows::NAME; - } else { - return $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS)->getAttribute('class'); - } + return $this->find($this->dataGrid)->isVisible() + ? 'dynamicRows' + : $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS)->getAttribute('class'); } /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php index a28a65de925a7..50337f922544d 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php @@ -20,24 +20,32 @@ class CustomAttribute extends DataSource * * @var CatalogProductAttribute */ - protected $attribute; + private $attribute; + + /** + * @var FixtureFactory + */ + private $fixtureFactory; /** - * @constructor * @param FixtureFactory $fixtureFactory * @param array $params * @param mixed $data */ public function __construct(FixtureFactory $fixtureFactory, array $params, $data) { + $this->fixtureFactory = $fixtureFactory; $this->params = $params; if (is_array($data) && isset($data['dataset'])) { /** @var CatalogProductAttribute $data */ $data = $fixtureFactory->createByCode('catalogProductAttribute', ['dataset' => $data['dataset']]); } - if (is_array($data) && isset($data['value'])) { + if (is_array($data) && isset($data['value']) && !is_array($data['value'])) { $this->data['value'] = $data['value']; $data = $data['attribute']; + } elseif (is_array($data) && isset($data['value']) && is_array($data['value'])) { + $this->data['value'] = $this->getWebsiteData($data['value']); + $data = $data['attribute']; } else { $this->data['value'] = $this->getDefaultAttributeValue($data); } @@ -54,7 +62,7 @@ public function __construct(FixtureFactory $fixtureFactory, array $params, $data * @param CatalogProductAttribute $attribute * @return string|null */ - protected function getDefaultAttributeValue(CatalogProductAttribute $attribute) + private function getDefaultAttributeValue(CatalogProductAttribute $attribute) { $data = $attribute->getData(); $value = ''; @@ -91,9 +99,30 @@ public function getAttribute() * @param CatalogProductAttribute $attribute * @return string */ - protected function createAttributeCode(CatalogProductAttribute $attribute) + private function createAttributeCode(CatalogProductAttribute $attribute) { $label = $attribute->getFrontendLabel(); return strtolower(preg_replace('@[\W\s]+@', '_', $label)); } + + /** + * Get website data. + * + * @param array $data + * @return array + */ + private function getWebsiteData(array &$data) + { + foreach ($data as $key => $value) { + if (strpos($key, '/dataset') !== false) { + list($code) = explode("/", $key); + /** @var \Magento\Store\Test\Fixture\Website $website */ + $website = $this->fixtureFactory->createByCode($code, ['dataset' => $value]); + unset($data[$key]); + $data[$code] = $website->getName() . " USD"; + } + } + + return $data; + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml index 2a94a12c0dbdf..a2841ff2dde5f 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml @@ -177,7 +177,7 @@ United States 10 - All Websites USD + all_websites * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml index bed538ff0d8c7..82a7c263b1ca9 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/di.xml @@ -163,25 +163,25 @@ [name="product[%code%]"] null - + [name="product[%code%]"] null [name="product[%code%]"] - \Magento\Mtf\Client\Element\DatepickerElement + datepicker [name="product[%code%]"] - \Magento\Mtf\Client\Element\SelectElement + select [name="product[%code%]"] - \Magento\Mtf\Client\Element\MultiselectElement + multiselect [name="product[%code%]"] - \Magento\Mtf\Client\Element\SwitcherElement + switcher diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php index cc5fa67779755..8e4078e58b9fc 100644 --- a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php @@ -9,7 +9,7 @@ use Magento\Mtf\Client\Locator; /** - * 'Fixed Product Tax' form. + * Fixed Product Tax. */ class Fpt extends SimpleElement { @@ -51,7 +51,7 @@ class Fpt extends SimpleElement /** * Fill Fixed Product Tax form. * - * @param array $value + * @param string|array $value * @return void */ public function setValue($value) @@ -59,21 +59,14 @@ public function setValue($value) if ($this->find($this->buttonFormLocator)->isVisible()) { $this->find($this->buttonFormLocator)->click(); } - $countryElement = $this->find($this->country, Locator::SELECTOR_CSS, 'select'); - if ($countryElement->isVisible()) { - $countryElement->setValue($value['country']); - } - $taxElement = $this->find($this->tax, Locator::SELECTOR_CSS, 'input'); - if ($taxElement->isVisible()) { - $taxElement->setValue($value['tax']); - } - $websiteElement = $this->find($this->website, Locator::SELECTOR_CSS, 'select'); - if ($websiteElement->isVisible()) { - $websiteElement->setValue($value['website']); - } - $stateElement = $this->find($this->state, Locator::SELECTOR_CSS, 'select'); - if ($stateElement->isVisible()) { - $stateElement->setValue($value['state']); + foreach ((array)$value as $name => $data) { + $element = $name === 'tax' + ? $this->find($this->$name, Locator::SELECTOR_CSS, 'input') + : $this->find($this->$name, Locator::SELECTOR_CSS, 'select'); + + if ($element->isVisible()) { + $element->setValue($data); + } } } } From b49fb91985c7403ab20c757d88dfe8d7883e66a0 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 20 Jul 2016 14:06:34 +0300 Subject: [PATCH 24/35] MAGETWO-53344: Unable to upload change robots.txt file via admin panel --- .../Framework/Filesystem/Directory/Write.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php index b440f65f6581c..12ccd5830dfa8 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php @@ -40,7 +40,7 @@ public function __construct( } /** - * Check if directory is writable + * Check if directory or file is writable * * @param string $path * @return void @@ -49,7 +49,9 @@ public function __construct( protected function assertWritable($path) { if ($this->isWritable($path) === false) { - $path = $this->getAbsolutePath($this->path, $path); + $path = (!$this->driver->isFile($path)) + ? $this->getAbsolutePath($this->path, $path) + : $this->getAbsolutePath($path); throw new FileSystemException(new \Magento\Framework\Phrase('The path "%1" is not writable', [$path])); } } @@ -249,12 +251,7 @@ public function openFile($path, $mode = 'w') if (!$this->isExist($path)) { $this->assertWritable($folder); } else { - if (!$this->isWritable($path)) { - throw new FileSystemException(new \Magento\Framework\Phrase( - 'The path "%1" is not writable', - [$this->getAbsolutePath($path)] - )); - } + $this->assertWritable($path); } $absolutePath = $this->driver->getAbsolutePath($this->path, $path); return $this->fileFactory->create($absolutePath, $this->driver, $mode); From 8d53481fe0507087ab8d8a1072792bc9967a8f86 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 20 Jul 2016 15:39:09 +0300 Subject: [PATCH 25/35] MAGETWO-53344: Unable to upload change robots.txt file via admin panel --- .../Test/Unit/Directory/WriteTest.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php b/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php index e7b687bcf279c..27c3b6c00a353 100644 --- a/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php +++ b/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php @@ -38,7 +38,13 @@ class WriteTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->driver = $this->getMock('Magento\Framework\Filesystem\Driver\File', [], [], '', false); + $this->driver = $this->getMock( + 'Magento\Framework\Filesystem\Driver\File', + [], + [], + '', + false + ); $this->fileFactory = $this->getMock( 'Magento\Framework\Filesystem\File\WriteFactory', [], @@ -88,7 +94,6 @@ public function testIsWritable() $this->assertTrue($this->write->isWritable('correct-path')); } - public function testCreateSymlinkTargetDirectoryExists() { $targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface') @@ -122,6 +127,17 @@ public function testCreateSymlinkTargetDirectoryExists() $this->assertTrue($this->write->createSymlink($sourcePath, $destinationFile, $targetDir)); } + /** + * @expectedException \Magento\Framework\Exception\FileSystemException + */ + public function testOpenFileNonWritable() + { + $targetPath = '/path/to/target.file'; + $this->driver->expects($this->once())->method('isExists')->will($this->returnValue(true)); + $this->driver->expects($this->once())->method('isWritable')->will($this->returnValue(false)); + $this->write->openFile($targetPath); + } + /** * Assert is file expectation * From ba11d24b8ca4dfa6fd526ba95be86e4bb838b822 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 20 Jul 2016 15:55:27 +0300 Subject: [PATCH 26/35] MAGETWO-53344: Unable to upload change robots.txt file via admin panel --- .../Magento/Framework/Filesystem/Directory/Write.php | 6 +----- .../Framework/Filesystem/Test/Unit/Directory/WriteTest.php | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php index 12ccd5830dfa8..25486562257ca 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php @@ -248,11 +248,7 @@ public function openFile($path, $mode = 'w') { $folder = dirname($path); $this->create($folder); - if (!$this->isExist($path)) { - $this->assertWritable($folder); - } else { - $this->assertWritable($path); - } + $this->assertWritable($this->isExist($path) ? $path : $folder); $absolutePath = $this->driver->getAbsolutePath($this->path, $path); return $this->fileFactory->create($absolutePath, $this->driver, $mode); } diff --git a/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php b/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php index 27c3b6c00a353..871a663d46986 100644 --- a/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php +++ b/lib/internal/Magento/Framework/Filesystem/Test/Unit/Directory/WriteTest.php @@ -133,8 +133,8 @@ public function testCreateSymlinkTargetDirectoryExists() public function testOpenFileNonWritable() { $targetPath = '/path/to/target.file'; - $this->driver->expects($this->once())->method('isExists')->will($this->returnValue(true)); - $this->driver->expects($this->once())->method('isWritable')->will($this->returnValue(false)); + $this->driver->expects($this->once())->method('isExists')->willReturn(true); + $this->driver->expects($this->once())->method('isWritable')->willReturn(false); $this->write->openFile($targetPath); } From 8318878aebc15b7bf7d4ba56af548d58f7a7bef0 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 27 Jul 2016 17:16:56 +0300 Subject: [PATCH 27/35] MAGETWO-52153: [FT] CreateProductAttributeEntityTest: CreateProductAttributeEntityTestVariation8 failed - Updated CustomAttribute data source; - Added mapping for Fpt fields; --- .../CatalogProductSimple/CustomAttribute.php | 33 ++----------------- .../CreateProductAttributeEntityTest.xml | 2 +- .../Edit/Section/ProductDetails/Fpt.php | 16 +++++++-- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php index 50337f922544d..f8be03d37846e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomAttribute.php @@ -23,29 +23,21 @@ class CustomAttribute extends DataSource private $attribute; /** - * @var FixtureFactory - */ - private $fixtureFactory; - - /** + * @constructor * @param FixtureFactory $fixtureFactory * @param array $params * @param mixed $data */ public function __construct(FixtureFactory $fixtureFactory, array $params, $data) { - $this->fixtureFactory = $fixtureFactory; $this->params = $params; if (is_array($data) && isset($data['dataset'])) { /** @var CatalogProductAttribute $data */ $data = $fixtureFactory->createByCode('catalogProductAttribute', ['dataset' => $data['dataset']]); } - if (is_array($data) && isset($data['value']) && !is_array($data['value'])) { + if (is_array($data) && isset($data['value'])) { $this->data['value'] = $data['value']; $data = $data['attribute']; - } elseif (is_array($data) && isset($data['value']) && is_array($data['value'])) { - $this->data['value'] = $this->getWebsiteData($data['value']); - $data = $data['attribute']; } else { $this->data['value'] = $this->getDefaultAttributeValue($data); } @@ -104,25 +96,4 @@ private function createAttributeCode(CatalogProductAttribute $attribute) $label = $attribute->getFrontendLabel(); return strtolower(preg_replace('@[\W\s]+@', '_', $label)); } - - /** - * Get website data. - * - * @param array $data - * @return array - */ - private function getWebsiteData(array &$data) - { - foreach ($data as $key => $value) { - if (strpos($key, '/dataset') !== false) { - list($code) = explode("/", $key); - /** @var \Magento\Store\Test\Fixture\Website $website */ - $website = $this->fixtureFactory->createByCode($code, ['dataset' => $value]); - unset($data[$key]); - $data[$code] = $website->getName() . " USD"; - } - } - - return $data; - } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml index a2841ff2dde5f..2a94a12c0dbdf 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/CreateProductAttributeEntityTest.xml @@ -177,7 +177,7 @@ United States 10 - all_websites + All Websites USD * diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php index 8e4078e58b9fc..5bd5579566c9a 100644 --- a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php @@ -48,6 +48,18 @@ class Fpt extends SimpleElement */ private $state = '[name$="[state]"]'; + /** + * Fields mapping. + * + * @var array + */ + private $fields = [ + 'country' => 'select', + 'website' => 'select', + 'tax' => 'input', + 'state' => 'select' + ]; + /** * Fill Fixed Product Tax form. * @@ -60,9 +72,7 @@ public function setValue($value) $this->find($this->buttonFormLocator)->click(); } foreach ((array)$value as $name => $data) { - $element = $name === 'tax' - ? $this->find($this->$name, Locator::SELECTOR_CSS, 'input') - : $this->find($this->$name, Locator::SELECTOR_CSS, 'select'); + $element = $this->find($this->$name, Locator::SELECTOR_CSS, $this->fields[$name]); if ($element->isVisible()) { $element->setValue($data); From 0097d34ae3da58e3d3aad8fe1526a74df45571a0 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 27 Jul 2016 18:33:38 +0300 Subject: [PATCH 28/35] MAGETWO-52153: [FT] CreateProductAttributeEntityTest: CreateProductAttributeEntityTestVariation8 failed - Removed unused properties; --- .../Product/Attribute/CustomAttribute.php | 2 +- .../Edit/Section/ProductDetails/Fpt.php | 52 +++++++------------ 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php index fb3fb87e56c19..d624fafa3143a 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Attribute/CustomAttribute.php @@ -101,7 +101,7 @@ public function getValue() private function getElementByClass($class) { $element = null; - foreach ($this->classReferences as $key => $reference) { + foreach (array_keys($this->classReferences) as $key) { if (strpos($class, $key) !== false) { return $this->classReferences[$class]; } diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php index 5bd5579566c9a..d9dafe0517c82 100644 --- a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php @@ -20,44 +20,28 @@ class Fpt extends SimpleElement */ private $buttonFormLocator = '[data-action="add_new_row"]'; - /** - * Locator for country. - * - * @var string - */ - private $country = '[name$="[country]"]'; - - /** - * Locator for tax. - * - * @var string - */ - private $tax = '[name$="[value]"]'; - - /** - * Locator for website id. - * - * @var string - */ - private $website = '[name$="[website_id]"]'; - - /** - * Locator for state. - * - * @var string - */ - private $state = '[name$="[state]"]'; - /** * Fields mapping. * * @var array */ private $fields = [ - 'country' => 'select', - 'website' => 'select', - 'tax' => 'input', - 'state' => 'select' + 'country' => [ + 'type' => 'select', + 'selector' => '[name$="[country]"]' + ], + 'website' => [ + 'type' => 'select', + 'selector' => '[name$="[website_id]"]' + ], + 'tax' => [ + 'type' => 'input', + 'selector' => '[name$="[value]"]' + ], + 'state' => [ + 'type' => 'select', + 'selector' => '[name$="[state]"]' + ] ]; /** @@ -72,7 +56,9 @@ public function setValue($value) $this->find($this->buttonFormLocator)->click(); } foreach ((array)$value as $name => $data) { - $element = $this->find($this->$name, Locator::SELECTOR_CSS, $this->fields[$name]); + $element = $this->find( + $this->fields[$name]['selector'], Locator::SELECTOR_CSS, $this->fields[$name]['type'] + ); if ($element->isVisible()) { $element->setValue($data); From 60387a0b5097af3d2c209007a57b634f01fc54b4 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 27 Jul 2016 18:40:13 +0300 Subject: [PATCH 29/35] MAGETWO-52153: [FT] CreateProductAttributeEntityTest: CreateProductAttributeEntityTestVariation8 failed --- .../Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php index d9dafe0517c82..e059563ff0fc4 100644 --- a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Adminhtml/Product/Edit/Section/ProductDetails/Fpt.php @@ -57,7 +57,9 @@ public function setValue($value) } foreach ((array)$value as $name => $data) { $element = $this->find( - $this->fields[$name]['selector'], Locator::SELECTOR_CSS, $this->fields[$name]['type'] + $this->fields[$name]['selector'], + Locator::SELECTOR_CSS, + $this->fields[$name]['type'] ); if ($element->isVisible()) { From aa753af9fcdc266c92a022220a6273d256d9e140 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 1 Aug 2016 15:37:44 +0300 Subject: [PATCH 30/35] MAGETWO-55668: Processing PR for bugs - Added suppress warning to unit test; --- .../Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php index a04d5157f461f..2539a0ff27339 100644 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php @@ -10,6 +10,7 @@ /** * Class RollbackTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class RollbackTest extends \PHPUnit_Framework_TestCase { From 8da309f2ec9d04e88cae516952ec4bc0cc98bd4b Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 1 Aug 2016 16:33:10 +0300 Subject: [PATCH 31/35] MAGETWO-55668: Processing PR for bugs - Code style fixed; --- .../Test/Unit/Controller/Adminhtml/Index/RollbackTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php index 2539a0ff27339..112fcccce179f 100644 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php @@ -170,7 +170,7 @@ public function testExecuteRollbackDisabled() ->willReturn($rollbackAllowed); $this->objectManagerMock->expects($this->once()) ->method('get') - ->with('Magento\Backup\Helper\Data') + ->with(\Magento\Backup\Helper\Data::class) ->willReturn($this->dataHelperMock); $this->assertSame($this->responseMock, $this->rollbackController->execute()); From 339cafead605b990f506be8f3a329eb94bb56ae2 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 1 Aug 2016 17:50:03 +0300 Subject: [PATCH 32/35] MAGETWO-53094: Client side compilation mode take an effect in production mode - Fixed unit test; - Added suppress warning; --- app/code/Magento/Deploy/Model/Deployer.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index be221bf3b5707..25b58e0b2b04b 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -26,6 +26,7 @@ * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @SuppressWarnings(PHPMD.TooManyFields) */ class Deployer { @@ -180,7 +181,14 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales) $this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath) )) ) { - $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, $module, $fullPath); + $compiledFile = $this->deployFile( + $filePath, + $area, + $themePath, + $locale, + $module, + $fullPath + ); if ($compiledFile !== '') { $this->deployFile($compiledFile, $area, $themePath, $locale, $module, $fullPath); } From 222c41f2eb63948a58ea71602376823139769710 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 1 Aug 2016 18:14:36 +0300 Subject: [PATCH 33/35] MAGETWO-55668: Processing PR for bugs --- .../Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php index 112fcccce179f..9f306cfc576d8 100644 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/RollbackTest.php @@ -8,7 +8,6 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; /** - * Class RollbackTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) */ From 0e2316fb548bbf5df0fe70dd58697c37995b3036 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 1 Aug 2016 18:30:36 +0300 Subject: [PATCH 34/35] MAGETWO-53094: Client side compilation mode take an effect in production mode - Fixed unit tests; --- .../PreProcessor/FileGenerator/PublicationDecoratorTest.php | 2 +- .../View/Asset/PreProcessor/PreprocessorStrategyTest.php | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php b/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php index 160c6164ac1fa..8233437cf927f 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/Css/PreProcessor/FileGenerator/PublicationDecoratorTest.php @@ -18,7 +18,7 @@ use Magento\Framework\View\Asset\Repository; /** - * Class PublicationDecoratorTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PublicationDecoratorTest extends \PHPUnit_Framework_TestCase { diff --git a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php index 36e3f4a49ce6e..844b2633da648 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php @@ -52,11 +52,6 @@ class PreprocessorStrategyTest extends \PHPUnit_Framework_TestCase */ private $objectMangerMock; - /** - * @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject - */ - private $deploymentConfigMock; - /** * Set up */ From 9ce4ea8d061ad412a04649fadcbfbd2b835e4715 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Mon, 1 Aug 2016 19:01:06 +0300 Subject: [PATCH 35/35] MAGETWO-53094: Client side compilation mode take an effect in production mode --- .../Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php index 844b2633da648..d27fa0642d061 100644 --- a/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php +++ b/app/code/Magento/Developer/Test/Unit/Model/View/Asset/PreProcessor/PreprocessorStrategyTest.php @@ -19,6 +19,7 @@ * Class PreprocessorStrategyTest * * @see \Magento\Developer\Model\View\Asset\PreProcessor\PreprocessorStrategy + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PreprocessorStrategyTest extends \PHPUnit_Framework_TestCase {