From bcf5dc5afa08b801196c800c2602b7ccf3ebcab8 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Wed, 20 Apr 2016 16:51:02 +0300 Subject: [PATCH 1/9] MAGETWO-49942: [CMS Page] Custom Design Update fields From and To cannot be overridden as empty --- .../Cms/Controller/Adminhtml/Page/PostDataProcessor.php | 8 +------- app/code/Magento/Cms/Model/ResourceModel/Page.php | 4 ++-- .../Magento/Framework/EntityManager/Db/UpdateRow.php | 4 ++++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php index 7c41fc1b59497..36e033f8a96fe 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php @@ -46,13 +46,7 @@ public function __construct( */ public function filter($data) { - $inputFilter = new \Zend_Filter_Input( - ['custom_theme_from' => $this->dateFilter, 'custom_theme_to' => $this->dateFilter], - [], - $data - ); - $data = $inputFilter->getUnescaped(); - return $data; + return (new \Zend_Filter_Input([], [], $data))->getUnescaped(); } /** diff --git a/app/code/Magento/Cms/Model/ResourceModel/Page.php b/app/code/Magento/Cms/Model/ResourceModel/Page.php index 31ab2dc9ce91e..535f29a2d3ad7 100644 --- a/app/code/Magento/Cms/Model/ResourceModel/Page.php +++ b/app/code/Magento/Cms/Model/ResourceModel/Page.php @@ -111,8 +111,8 @@ protected function _beforeSave(AbstractModel $object) * type NULL so in DB they will be empty and not some default value */ foreach (['custom_theme_from', 'custom_theme_to'] as $field) { - $value = !$object->getData($field) ? null : $object->getData($field); - $object->setData($field, $this->dateTime->formatDate($value)); + $value = !$object->getData($field) ? null : $this->dateTime->formatDate($object->getData($field)); + $object->setData($field, $value); } if (!$this->isValidPageIdentifier($object)) { diff --git a/lib/internal/Magento/Framework/EntityManager/Db/UpdateRow.php b/lib/internal/Magento/Framework/EntityManager/Db/UpdateRow.php index 928cf971a819d..3f65774cf10a6 100644 --- a/lib/internal/Magento/Framework/EntityManager/Db/UpdateRow.php +++ b/lib/internal/Magento/Framework/EntityManager/Db/UpdateRow.php @@ -53,13 +53,17 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' || $column['IDENTITY']) { continue; } + if (isset($data[strtolower($column['COLUMN_NAME'])])) { $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])]; + } elseif (!empty($column['NULLABLE'])) { + $output[strtolower($column['COLUMN_NAME'])] = null; } } if (empty($data[$metadata->getIdentifierField()])) { $output[$metadata->getIdentifierField()] = $metadata->generateIdentifier(); } + return $output; } From 4a5d566e1b406be38aa262d37ea35f00ba604874 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Wed, 20 Apr 2016 17:12:11 +0300 Subject: [PATCH 2/9] MAGETWO-49942: [CMS Page] Custom Design Update fields From and To cannot be overridden as empty --- .../Controller/Page/PostDataProcessorTest.php | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php b/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php index 16ba00c1c3492..c582067d1b783 100644 --- a/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php +++ b/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php @@ -6,41 +6,54 @@ namespace Magento\Cms\Test\Unit\Controller\Page; use Magento\Cms\Controller\Adminhtml\Page\PostDataProcessor; +use Magento\Framework\Stdlib\DateTime\Filter\Date; +use Magento\Framework\Message\ManagerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\View\Model\Layout\Update\ValidatorFactory; +/** + * Class PostDataProcessorTest + * @package Magento\Cms\Test\Unit\Controller\Page + */ class PostDataProcessorTest extends \PHPUnit_Framework_TestCase { - /** @var \Magento\Framework\Stdlib\DateTime\Filter\Date|\PHPUnit_Framework_MockObject_MockObject */ - protected $dateFilter; + /** + * @var Date|\PHPUnit_Framework_MockObject_MockObject + */ + protected $dateFilterMock; - /** @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $messageManager; + /** + * @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $messageManagerMock; - /** @var \Magento\Framework\View\Model\Layout\Update\ValidatorFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $validatorFactory; + /** + * @var ValidatorFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $validatorFactoryMock; - /** @var PostDataProcessor */ + /** + * @var PostDataProcessor + */ protected $postDataProcessor; protected function setUp() { - $this->dateFilter = $this->getMock('Magento\Framework\Stdlib\DateTime\Filter\Date', [], [], '', false); - $this->messageManager = $this->getMockForAbstractClass( - 'Magento\Framework\Message\ManagerInterface', - [], - '', - false - ); - $this->validatorFactory = $this->getMock( - 'Magento\Framework\View\Model\Layout\Update\ValidatorFactory', - ['create'], - [], - '', - false - ); - $this->postDataProcessor = new PostDataProcessor( - $this->dateFilter, - $this->messageManager, - $this->validatorFactory + $this->dateFilterMock = $this->getMockBuilder(Date::class) + ->disableOriginalConstructor() + ->getMock(); + $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class) + ->getMockForAbstractClass(); + $this->validatorFactoryMock = $this->getMockBuilder(ValidatorFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->postDataProcessor = (new ObjectManager($this))->getObject(PostDataProcessor::class, [ + 'dateFilter' => $this->dateFilterMock, + 'messageManager' => $this->messageManagerMock, + 'validatorFactory' => $this->validatorFactoryMock + ] ); } @@ -49,10 +62,15 @@ public function testValidateRequireEntry() $postData = [ 'title' => '' ]; - $this->messageManager->expects($this->once()) + $this->messageManagerMock->expects($this->once()) ->method('addError') ->with(__('To apply changes you should fill in hidden required "%1" field', 'Page Title')); $this->assertFalse($this->postDataProcessor->validateRequireEntry($postData)); } + + public function testFilter() + { + $this->assertSame(['key' => 'value'], $this->postDataProcessor->filter(['key' => 'value'])); + } } From 9e195b91f1458cb5f1394eddc550ae39e0ef6125 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Wed, 20 Apr 2016 17:27:05 +0300 Subject: [PATCH 3/9] MAGETWO-49942: [CMS Page] Custom Design Update fields From and To cannot be overridden as empty --- .../Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php b/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php index c582067d1b783..12376a296be35 100644 --- a/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php +++ b/app/code/Magento/Cms/Test/Unit/Controller/Page/PostDataProcessorTest.php @@ -49,7 +49,9 @@ protected function setUp() ->setMethods(['create']) ->getMock(); - $this->postDataProcessor = (new ObjectManager($this))->getObject(PostDataProcessor::class, [ + $this->postDataProcessor = (new ObjectManager($this))->getObject( + PostDataProcessor::class, + [ 'dateFilter' => $this->dateFilterMock, 'messageManager' => $this->messageManagerMock, 'validatorFactory' => $this->validatorFactoryMock From 622741cf3af1dd101995fcf04112948ee9ab51f1 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Wed, 20 Apr 2016 17:43:21 +0300 Subject: [PATCH 4/9] MAGETWO-49942: [CMS Page] Custom Design Update fields From and To cannot be overridden as empty --- .../Controller/Adminhtml/Page/PostDataProcessor.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php index 36e033f8a96fe..544e4a52e7756 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php @@ -46,7 +46,15 @@ public function __construct( */ public function filter($data) { - return (new \Zend_Filter_Input([], [], $data))->getUnescaped(); + $filterRules = []; + + foreach (['custom_theme_from', 'custom_theme_to'] as $dateField) { + if (!empty($data[$dateField])) { + $filterRules[$dateField] = $this->dateFilter; + } + } + + return (new \Zend_Filter_Input($filterRules, [], $data))->getUnescaped(); } /** From 51b1738f1376e474065d6d631362a6e94764ed14 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Fri, 22 Apr 2016 11:16:59 +0300 Subject: [PATCH 5/9] MAGETWO-49942: [CMS Page] Custom Design Update fields From and To cannot be overridden as empty --- .../Unit/Model/ResourceModel/PageTest.php | 132 ++++++++++++++++++ .../EntityManager/Test/Db/UpdateRowTest.php | 121 ++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php create mode 100644 lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php diff --git a/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php b/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php new file mode 100644 index 0000000000000..2f64b96f39e00 --- /dev/null +++ b/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php @@ -0,0 +1,132 @@ +contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->dateTimeMock = $this->getMockBuilder(DateTime::class) + ->disableOriginalConstructor() + ->getMock(); + $this->entityManagerMock = $this->getMockBuilder(EntityManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class) + ->disableOriginalConstructor() + ->getMock(); + $this->pageMock = $this->getMockBuilder(Page::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resourcesMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->contextMock->expects($this->once()) + ->method('getResources') + ->willReturn($this->resourcesMock); + + $this->model = (new ObjectManager($this))->getObject(PageResourceModel::class, [ + 'context' => $this->contextMock, + 'storeManager' => $this->storeManagerMock, + 'dateTime' => $this->dateTimeMock, + 'entityManager' => $this->entityManagerMock, + 'metadataPool' => $this->metadataPoolMock, + ]); + } + + public function testSave() + { + $this->entityManagerMock->expects($this->once()) + ->method('save') + ->with($this->pageMock, PageInterface::class, []) + ->willReturn(true); + + $this->assertInstanceOf(PageResourceModel::class, $this->model->save($this->pageMock)); + } + + public function testBeforeSave() + { + $this->pageMock->expects($this->any()) + ->method('getData') + ->willReturnMap([ + ['identifier', null, 'test'], + ['custom_theme_from', null, null], + ['custom_theme_to', null, '10/02/2016'], + ]); + $this->dateTimeMock->expects($this->once()) + ->method('formatDate') + ->with('10/02/2016') + ->willReturn('10 Feb 2016'); + $this->pageMock->expects($this->any()) + ->method('setData') + ->withConsecutive( + ['custom_theme_from', null], + ['custom_theme_to', '10 Feb 2016'] + ); + + $this->model->beforeSave($this->pageMock); + } +} diff --git a/lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php b/lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php new file mode 100644 index 0000000000000..2b8ad451315f3 --- /dev/null +++ b/lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php @@ -0,0 +1,121 @@ +metadataPoolMock = $this->getMockBuilder(MetadataPool::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->metadataMock = $this->getMockBuilder(EntityMetadataInterface::class) + ->getMockForAbstractClass(); + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->getMockForAbstractClass(); + $this->metadataMock = $this->getMockBuilder(EntityMetadataInterface::class) + ->getMockForAbstractClass(); + + $this->model = (new ObjectManager($this))->getObject(UpdateRow::class, [ + 'metadataPool' => $this->metadataPoolMock, + 'resourceConnection' => $this->resourceConnectionMock, + ]); + } + + public function testExecute() + { + $data = [ + 'test_link_field' => 1, + 'identified_field' => 'test_identified_field', + 'test_simple' => 'test_value', + ]; + $columns = [ + 'test_nullable' => [ + 'NULLABLE' => true, + 'DEFAULT' => false, + 'IDENTITY' => false, + 'COLUMN_NAME' => 'test_nullable', + ], + 'test_simple' => [ + 'NULLABLE' => true, + 'DEFAULT' => false, + 'IDENTITY' => false, + 'COLUMN_NAME' => 'test_simple', + ], + ]; + $preparedColumns = [ + 'test_identified_field' => null, + 'test_nullable' => null, + 'test_simple' => 'test_value', + ]; + + $this->metadataPoolMock->expects($this->once()) + ->method('getMetadata') + ->with('test') + ->willReturn($this->metadataMock); + $this->resourceConnectionMock->expects($this->once()) + ->method('getConnectionByName') + ->willReturn($this->connectionMock); + $this->metadataMock->expects($this->once()) + ->method('getEntityConnectionName') + ->willReturn('test_connection_name'); + $this->metadataMock->expects($this->exactly(2)) + ->method('getEntityTable') + ->willReturn('test_entity_table'); + $this->connectionMock->expects($this->once()) + ->method('update') + ->with('test_entity_table', $preparedColumns, ['test_link_field' . ' = ?' => $data['test_link_field']]); + $this->metadataMock->expects($this->exactly(2)) + ->method('getLinkField') + ->willReturn('test_link_field'); + $this->connectionMock->expects($this->once()) + ->method('describeTable') + ->willReturn($columns); + $this->metadataMock->expects($this->exactly(2)) + ->method('getIdentifierField') + ->willReturn('test_identified_field'); + + $this->assertSame($data, $this->model->execute('test', $data)); + } +} From 306c9efbb8c4d9c591f45824059664e601a0e2cf Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Fri, 22 Apr 2016 11:44:21 +0300 Subject: [PATCH 6/9] MAGETWO-49942: [CMS Page] Custom Design Update fields From and To cannot be overridden as empty --- app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php | 1 + .../EntityManager/Test/{ => Unit}/Db/UpdateRowTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename lib/internal/Magento/Framework/EntityManager/Test/{ => Unit}/Db/UpdateRowTest.php (98%) diff --git a/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php b/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php index 2f64b96f39e00..6732b36f65575 100644 --- a/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php +++ b/app/code/Magento/Cms/Test/Unit/Model/ResourceModel/PageTest.php @@ -18,6 +18,7 @@ /** * Class PageTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PageTest extends \PHPUnit_Framework_TestCase { diff --git a/lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php b/lib/internal/Magento/Framework/EntityManager/Test/Unit/Db/UpdateRowTest.php similarity index 98% rename from lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php rename to lib/internal/Magento/Framework/EntityManager/Test/Unit/Db/UpdateRowTest.php index 2b8ad451315f3..b22334f4402b1 100644 --- a/lib/internal/Magento/Framework/EntityManager/Test/Db/UpdateRowTest.php +++ b/lib/internal/Magento/Framework/EntityManager/Test/Unit/Db/UpdateRowTest.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\EntityManager\Test\Db; +namespace Magento\Framework\EntityManager\Test\Unit\Db; use Magento\Framework\EntityManager\Db\UpdateRow; use Magento\Framework\EntityManager\MetadataPool; From 25579749f83f653f841264d8b4993a27f1dd0545 Mon Sep 17 00:00:00 2001 From: Yuri Kovsher Date: Mon, 25 Apr 2016 14:25:32 +0300 Subject: [PATCH 7/9] MAGETWO-50936: 500 Internal server error on the page with specific widget --- .../Category/Collection/Factory.php | 4 + .../Model/ResourceModel/Category/Flat.php | 25 ++- .../Model/ResourceModel/Category/FlatTest.php | 212 ++++++++++++++++++ 3 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/FlatTest.php diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php index 4698800d07f33..e31ea5bbd119e 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php @@ -5,6 +5,10 @@ */ namespace Magento\Catalog\Model\ResourceModel\Category\Collection; +/** + * Class Factory + * @deprecated + */ class Factory { /** diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php b/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php index 5c2108189da17..6740f6bc407a2 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php @@ -6,6 +6,8 @@ namespace Magento\Catalog\Model\ResourceModel\Category; use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; +use Magento\Catalog\Model\ResourceModel\Category\Flat\CollectionFactory as CategoryFlatCollectionFactory; +use Magento\Framework\App\ObjectManager; /** * Category flat model @@ -68,6 +70,7 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource * Category collection factory * * @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory + * @deprecated */ protected $_categoryCollectionFactory; @@ -78,6 +81,11 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource */ protected $_categoryFactory; + /** + * @var CategoryFlatCollectionFactory + */ + private $categoryFlatCollectionFactory; + /** * Class constructor * @@ -399,7 +407,7 @@ public function getCategories($parent, $recursionLevel = 0, $sorted = false, $as ); $parentPath = $this->getConnection()->fetchOne($select); - $collection = $this->_categoryCollectionFactory + $collection = $this->getCategoryFlatCollectionFactory() ->create() ->addNameToResult() ->addUrlRewriteToResult() @@ -690,4 +698,19 @@ public function getProductsPosition($category) return $this->getConnection()->fetchPairs($select, $bind); } + + /** + * Get instance of CategoryFlatCollectionFactory + * + * @return CategoryFlatCollectionFactory + */ + private function getCategoryFlatCollectionFactory() + { + if (!$this->categoryFlatCollectionFactory instanceof CategoryFlatCollectionFactory) { + $this->categoryFlatCollectionFactory = ObjectManager::getInstance() + ->get(CategoryFlatCollectionFactory::class); + } + + return $this->categoryFlatCollectionFactory; + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/FlatTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/FlatTest.php new file mode 100644 index 0000000000000..c93a1f868680d --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/FlatTest.php @@ -0,0 +1,212 @@ +objectManager = new ObjectManager($this); + + $this->selectMock = $this->getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->setMethods(['where', 'from']) + ->getMock(); + $this->selectMock->expects($this->once()) + ->method('where') + ->willReturn($this->selectMock); + $this->selectMock->expects($this->once()) + ->method('from') + ->willReturn($this->selectMock); + $this->connectionMock = $this->getMockBuilder(Adapter::class) + ->getMockForAbstractClass(); + $this->connectionMock->expects($this->once()) + ->method('select') + ->willReturn($this->selectMock); + $this->connectionMock->expects($this->once()) + ->method('fetchOne') + ->with($this->selectMock) + ->willReturn(self::PARENT_PATH); + $this->resourceMock = $this->getMockBuilder(ResourceConnection::class) + ->disableOriginalConstructor() + ->setMethods(['getConnection', 'getTableName']) + ->getMock(); + $this->resourceMock->expects($this->any()) + ->method('getConnection') + ->willReturn($this->connectionMock); + $this->resourceMock->expects($this->any()) + ->method('getTableName') + ->willReturn(self::TABLE_NAME); + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->setMethods(['getResources']) + ->getMock(); + $this->contextMock->expects($this->any()) + ->method('getResources') + ->willReturn($this->resourceMock); + + $this->storeMock = $this->getMockBuilder(Store::class) + ->disableOriginalConstructor() + ->setMethods(['getId']) + ->getMock(); + $this->storeMock->expects($this->any()) + ->method('getId') + ->willReturn(self::STORE_ID); + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->getMockForAbstractClass(); + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->willReturn($this->storeMock); + } + + public function testGetCategories() + { + $this->categoryCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->categoryCollectionMock = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->setMethods( + [ + 'addNameToResult', + 'addUrlRewriteToResult', + 'addParentPathFilter', + 'addStoreFilter', + 'addIsActiveFilter', + 'addAttributeToFilter', + 'addSortedField', + 'load' + ] + ) + ->getMock(); + $this->categoryCollectionMock->expects($this->once()) + ->method('addNameToResult') + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('addUrlRewriteToResult') + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('addParentPathFilter') + ->with(self::PARENT_PATH) + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('addStoreFilter') + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('addIsActiveFilter') + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('addSortedField') + ->with(self::SORTED) + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('addAttributeToFilter') + ->with('include_in_menu', 1) + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionMock->expects($this->once()) + ->method('load') + ->willReturn($this->categoryCollectionMock); + $this->categoryCollectionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->categoryCollectionMock); + + $this->model = $this->objectManager->getObject( + Flat::class, + [ + 'context' => $this->contextMock, + 'storeManager' => $this->storeManagerMock, + ] + ); + + $reflection = new \ReflectionClass(get_class($this->model)); + $reflectionProperty = $reflection->getProperty('categoryFlatCollectionFactory'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $this->categoryCollectionFactoryMock); + + $this->assertEquals( + $this->model->getCategories(self::PARENT, self::RECURSION_LEVEL, self::SORTED, true), + $this->categoryCollectionMock + ); + } +} From bc740a0350f5a144db051d26f89da8e99759154b Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Mon, 25 Apr 2016 18:59:07 +0300 Subject: [PATCH 8/9] MAGETWO-51185: Product image cannot be loaded from product page if minification enabled --- .../Fallback/Resolver/Minification.php | 36 +------ .../Fallback/Resolver/MinificationTest.php | 97 ++----------------- 2 files changed, 11 insertions(+), 122 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php index 650a97061cda3..307da0d2f7499 100644 --- a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php +++ b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php @@ -53,40 +53,6 @@ public function __construct(ResolverInterface $fallback, AssetMinification $mini public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null) { $fileExtension = pathinfo($file, PATHINFO_EXTENSION); - - if ($fileExtension === 'js') { - return $this->resolveJsMinification($type, $file, $area, $theme, $locale, $module); - } - - // Leave BC way of resolving - $path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module); - - if (!$path && $file != ($newFile = $this->minification->removeMinifiedSign($file))) { - $path = $this->fallback->resolve($type, $newFile, $area, $theme, $locale, $module); - } - - return $path; - } - - /** - * Get path of file after using fallback rules - * - * @param string $type - * @param string $file - * @param string|null $area - * @param ThemeInterface|null $theme - * @param string|null $locale - * @param string|null $module - * @return string|false - */ - private function resolveJsMinification( - $type, - $file, - $area = null, - ThemeInterface $theme = null, - $locale = null, - $module = null - ) { $path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module); /** @@ -99,7 +65,7 @@ private function resolveJsMinification( /** * If minification is disabled - return already found path */ - if (!$this->minification->isEnabled('js')) { + if (!$this->minification->isEnabled($fileExtension)) { return $path; } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/Resolver/MinificationTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/Resolver/MinificationTest.php index b0d8357e372ed..663976302a281 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/Resolver/MinificationTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/Resolver/MinificationTest.php @@ -70,21 +70,20 @@ public function testResolve( $this->assetMinificationMock ->expects($this->any()) ->method('isEnabled') - ->willReturnMap([['css', $isEnabled]]); + ->willReturn($isEnabled); $this->assetMinificationMock ->expects($this->any()) - ->method('removeMinifiedSign') + ->method('addMinifiedSign') ->with($requested) ->willReturn($alternative); $this->resolverMock ->expects($this->any()) ->method('resolve') - ->withConsecutive( - ['', $requested, null, null, null, null], - ['', $alternative, null, null, null, null] - ) - ->willReturnOnConsecutiveCalls($resolvedOriginal, $resolvedAlternative); + ->willReturnMap([ + ['', $requested, null, null, null, null, $resolvedOriginal], + ['', $alternative, null, null, null, null, $resolvedAlternative] + ]); $this->assertEquals($expected, $this->minification->resolve('', $requested)); } @@ -95,86 +94,10 @@ public function testResolve( public function resolveDataProvider() { return [ - [true, 'file.min.css', 'file.css', 'found.css', false, 'found.css'], - [false, 'file.min.css', 'file.min.css', false, false, 'found.css'] + [true, 'file.css', 'file.min.css', 'found.min.css', false, 'found.min.css'], + [false, 'file.min.css', 'file.min.css', false, false, 'found.css'], + [true, 'file.js', 'file.min.js', 'found.min.js', false, 'found.min.js'], + [false, 'file.min.js', 'file.min.js', false, false, 'found.js'], ]; } - - public function testResolveJs() - { - $this->resolverMock - ->expects($this->once()) - ->method('resolve') - ->willReturn('/var/test.min.js'); - $this->assetMinificationMock->expects($this->once()) - ->method('isMinifiedFilename') - ->willReturn(true); - - $this->assertEquals('/var/test.min.js', $this->minification->resolve('', 'test.min.js')); - } - - public function testResolveJsWithDisabledMinification() - { - $this->resolverMock - ->expects($this->once()) - ->method('resolve') - ->willReturn('/var/test.js'); - $this->assetMinificationMock->expects($this->once()) - ->method('isMinifiedFilename') - ->willReturn(false); - - $this->assertEquals('/var/test.js', $this->minification->resolve('', 'test.js')); - } - - public function testResolveJsToFindMinifiedVersion() - { - $this->resolverMock - ->expects($this->exactly(2)) - ->method('resolve') - ->willReturnMap( - [ - ['', 'test.js', null, null, null, null, '/var/test.js'], - ['', 'test.min.js', null, null, null, null, '/var/test.min.js'] - ] - ); - $this->assetMinificationMock->expects($this->once()) - ->method('isMinifiedFilename') - ->willReturn(false); - $this->assetMinificationMock->expects($this->once()) - ->method('isEnabled') - ->with('js') - ->willReturn(true); - $this->assetMinificationMock->expects($this->once()) - ->method('addMinifiedSign') - ->with('test.js') - ->willReturn('test.min.js'); - - $this->assertEquals('/var/test.min.js', $this->minification->resolve('', 'test.js')); - } - - public function testResolveJsToNotFindMinifiedVersion() - { - $this->resolverMock - ->expects($this->exactly(2)) - ->method('resolve') - ->willReturnMap( - [ - ['', 'test.js', null, null, null, null, '/var/test.js'], - ['', 'test.min.js', null, null, null, null, false] - ] - ); - $this->assetMinificationMock->expects($this->once()) - ->method('isMinifiedFilename') - ->willReturn(false); - $this->assetMinificationMock->expects($this->once()) - ->method('isEnabled') - ->with('js') - ->willReturn(true); - $this->assetMinificationMock->expects($this->once()) - ->method('addMinifiedSign') - ->with('test.js') - ->willReturn('test.min.js'); - - $this->assertEquals('/var/test.js', $this->minification->resolve('', 'test.js')); - } } From ea68a1cb30e44fbb3a764f46b7fbc40c5b6f396f Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Tue, 26 Apr 2016 14:12:37 +0300 Subject: [PATCH 9/9] MAGETWO-51185: Product image cannot be loaded from product page if minification enabled --- .../Fallback/Resolver/Minification.php | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php index 307da0d2f7499..aef2270c0957f 100644 --- a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php +++ b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Minification.php @@ -52,34 +52,11 @@ public function __construct(ResolverInterface $fallback, AssetMinification $mini */ public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null) { - $fileExtension = pathinfo($file, PATHINFO_EXTENSION); + $file = $this->minification->addMinifiedSign($file); $path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module); - - /** - * Minified version as priority one - */ - if ($path && $this->minification->isMinifiedFilename($path)) { - return $path; - } - - /** - * If minification is disabled - return already found path - */ - if (!$this->minification->isEnabled($fileExtension)) { - return $path; + if (!$path && ($newFile = $this->minification->removeMinifiedSign($file))) { + $path = $this->fallback->resolve($type, $newFile, $area, $theme, $locale, $module); } - - /** - * Try to find minified version of file, - * or return already found path - */ - return $this->fallback->resolve( - $type, - $this->minification->addMinifiedSign($file), - $area, - $theme, - $locale, - $module - ) ?: $path; + return $path; } }