From bebb391c661b468c2d4f1d6dfd842732c958ba36 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Tue, 17 Jan 2017 22:02:01 +0200 Subject: [PATCH 01/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Category/Collection/Factory.php | 4 + .../Model/ResourceModel/Category/Flat.php | 25 ++- .../Model/ResourceModel/Category/FlatTest.php | 212 ++++++++++++++++++ .../Constraint/AssertCategoryOnFrontend.php | 76 +++++++ .../AssertCategoryWithFlatOnFrontend.php | 70 ++++++ .../Catalog/Test/Repository/ConfigData.xml | 16 ++ 6 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/FlatTest.php create mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php create mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.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 + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php new file mode 100644 index 0000000000000..916b75fa0e978 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php @@ -0,0 +1,76 @@ +open(); + $cmsIndex->getLinksBlock()->waitWelcomeMessage(); + + $name = $category && $category->getName() ?: $initialCategory->getName(); + $isMenuCategory = $category && $category->getIncludeInMenu() ?: $initialCategory->getIncludeInMenu(); + $categoryUrl = $_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'; + + if ($isMenuCategory) { + \PHPUnit_Framework_Assert::assertTrue( + $cmsIndex->getTopmenu()->isCategoryVisible($name), + 'Category is not displayed in top menu.' + ); + $cmsIndex->getTopmenu()->selectCategoryByName($name); + } else { + $browser->open($categoryUrl); + } + + \PHPUnit_Framework_Assert::assertEquals( + $categoryUrl, + $browser->getUrl(), + 'Wrong category is displayed.' + ); + + \PHPUnit_Framework_Assert::assertEquals( + $name, + $categoryView->getTitleBlock()->getTitle(), + 'Wrong category name is displayed.' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Category is present on frontend.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.php new file mode 100644 index 0000000000000..110a55269cabc --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.php @@ -0,0 +1,70 @@ +objectManager->get(TestStepFactory::class); + + /** @var SetupConfigurationStep $configurationStep */ + $configurationStep = $testStepFactory->create( + SetupConfigurationStep::class, + ['configData' => 'category_flat'] + ); + $configurationStep->run(); + + /** @var AdminCache $adminCache */ + $adminCache = $this->objectManager->get(AdminCache::class); + // Flush cache + $adminCache->open(); + $adminCache->getActionsBlock()->flushMagentoCache(); + $adminCache->getMessagesBlock()->waitSuccessMessage(); + + parent::processAssert($browser, $categoryView, $category, $initialCategory, $cmsIndex); + + $configurationStep->cleanup(); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Category with flat enabled is present on frontend.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml index 0b3452cc14782..924d3ee4c1c3e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml @@ -23,5 +23,21 @@ 0 + + + default + 0 + Yes + 1 + + + + + default + 0 + No + 0 + + From 8e9569080e042d94c66bf4be66692abd528a5942 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Tue, 17 Jan 2017 22:32:16 +0200 Subject: [PATCH 02/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../TestSuite/InjectableTests/MAGETWO-63209.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml new file mode 100644 index 0000000000000..219900a18d347 --- /dev/null +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml @@ -0,0 +1,15 @@ + + + + + + + + + From 8558382b5162ac451c27991d93ef263456639ae4 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Wed, 18 Jan 2017 09:16:23 +0200 Subject: [PATCH 03/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on - Fix UpdateCategoryEntityTestVariation4 --- .../Test/Block/Adminhtml/Category/Edit/CategoryForm.xml | 4 ++++ .../tests/app/Magento/Catalog/Test/Fixture/Category.xml | 1 + .../Test/TestCase/Category/UpdateCategoryEntityTest.xml | 1 + 3 files changed, 6 insertions(+) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml index ac5ff2733a48f..0558d957f8c70 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml @@ -12,6 +12,10 @@ css selector general + + #group_4name_default + checkbox + select diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml index 5085b016f684e..70cb3581b7ca6 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml @@ -34,6 +34,7 @@ + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml index da30a102ecbac..616d5755dc7ea 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml @@ -47,6 +47,7 @@ + No custom Category %isolation% From 7d2cc299740d40ef1b4a959d444420d05c035bfa Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Wed, 18 Jan 2017 12:47:39 +0200 Subject: [PATCH 04/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Category/Collection/Factory.php | 2 +- .../Model/ResourceModel/Category/Flat.php | 2 +- .../Model/ResourceModel/Category/FlatTest.php | 2 +- .../Adminhtml/Category/Edit/CategoryForm.xml | 2 +- .../Constraint/AssertCategoryOnFrontend.php | 76 ------------------- .../AssertCategoryWithFlatOnFrontend.php | 70 ----------------- .../Magento/Catalog/Test/Fixture/Category.xml | 2 +- .../Catalog/Test/Repository/ConfigData.xml | 2 +- .../Category/UpdateCategoryEntityTest.php | 55 ++++++++++++-- .../Category/UpdateCategoryEntityTest.xml | 2 +- .../InjectableTests/MAGETWO-63209.xml | 2 +- 11 files changed, 56 insertions(+), 161 deletions(-) delete mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php delete mode 100644 dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.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 e31ea5bbd119e..127c8fe378ea5 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php @@ -1,6 +1,6 @@ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php deleted file mode 100644 index 916b75fa0e978..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryOnFrontend.php +++ /dev/null @@ -1,76 +0,0 @@ -open(); - $cmsIndex->getLinksBlock()->waitWelcomeMessage(); - - $name = $category && $category->getName() ?: $initialCategory->getName(); - $isMenuCategory = $category && $category->getIncludeInMenu() ?: $initialCategory->getIncludeInMenu(); - $categoryUrl = $_ENV['app_frontend_url'] . $initialCategory->getUrlKey() . '.html'; - - if ($isMenuCategory) { - \PHPUnit_Framework_Assert::assertTrue( - $cmsIndex->getTopmenu()->isCategoryVisible($name), - 'Category is not displayed in top menu.' - ); - $cmsIndex->getTopmenu()->selectCategoryByName($name); - } else { - $browser->open($categoryUrl); - } - - \PHPUnit_Framework_Assert::assertEquals( - $categoryUrl, - $browser->getUrl(), - 'Wrong category is displayed.' - ); - - \PHPUnit_Framework_Assert::assertEquals( - $name, - $categoryView->getTitleBlock()->getTitle(), - 'Wrong category name is displayed.' - ); - } - - /** - * Returns a string representation of the object. - * - * @return string - */ - public function toString() - { - return 'Category is present on frontend.'; - } -} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.php deleted file mode 100644 index 110a55269cabc..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryWithFlatOnFrontend.php +++ /dev/null @@ -1,70 +0,0 @@ -objectManager->get(TestStepFactory::class); - - /** @var SetupConfigurationStep $configurationStep */ - $configurationStep = $testStepFactory->create( - SetupConfigurationStep::class, - ['configData' => 'category_flat'] - ); - $configurationStep->run(); - - /** @var AdminCache $adminCache */ - $adminCache = $this->objectManager->get(AdminCache::class); - // Flush cache - $adminCache->open(); - $adminCache->getActionsBlock()->flushMagentoCache(); - $adminCache->getMessagesBlock()->waitSuccessMessage(); - - parent::processAssert($browser, $categoryView, $category, $initialCategory, $cmsIndex); - - $configurationStep->cleanup(); - } - - /** - * Returns a string representation of the object. - * - * @return string - */ - public function toString() - { - return 'Category with flat enabled is present on frontend.'; - } -} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml index 70cb3581b7ca6..0f3405578401b 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml @@ -1,7 +1,7 @@ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml index 924d3ee4c1c3e..68c36c16fba40 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml @@ -1,7 +1,7 @@ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php index aa68e601a70ad..f8eff140140ff 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php @@ -1,6 +1,6 @@ catalogCategoryIndex = $catalogCategoryIndex; $this->catalogCategoryEdit = $catalogCategoryEdit; + $this->testStepFactory = $testStepFactory; $initialCategory->persist(); return ['initialCategory' => $initialCategory]; } /** - * Test for update category + * Test for update category. * * @param Category $category * @param Category $initialCategory + * @param string $configData * @return void */ - public function test(Category $category, Category $initialCategory) + public function test(Category $category, Category $initialCategory, $configData = null) { + $this->configData = $configData; + + // Preconditions + $this->testStepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => $this->configData] + )->run(); + + // Process steps $this->catalogCategoryIndex->open(); $this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory); $this->catalogCategoryEdit->getEditForm()->fill($category); $this->catalogCategoryEdit->getFormPageActions()->save(); } + + /** + * Clean data after running test. + * + * @return void + */ + public function tearDown() + { + $this->testStepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => $this->configData, 'rollback' => true] + )->run(); + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml index 616d5755dc7ea..c039cb2158798 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml @@ -1,7 +1,7 @@ diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml index 219900a18d347..0e0dd3c94b491 100644 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml @@ -1,7 +1,7 @@ From 9b1d14bfdedad89c213931ad600b5a494b35e3f9 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Wed, 18 Jan 2017 18:37:23 +0200 Subject: [PATCH 05/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Adminhtml/Category/Edit/CategoryForm.xml | 4 +- .../Test/Constraint/AssertCategoryPage.php | 40 ++++++++++++++++--- .../Magento/Catalog/Test/Fixture/Category.xml | 2 +- .../Test/Fixture/Category/LandingPage.php | 5 ++- .../Test/Fixture/Category/ParentId.php | 5 ++- .../Category/UpdateCategoryEntityTest.xml | 2 +- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml index c6aa8bc4c2083..969cc6f6a4918 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml @@ -12,10 +12,10 @@ css selector general - + #group_4name_default checkbox - + select diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php index 75a48c86501b0..236ffc3c211b1 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php @@ -1,6 +1,6 @@ browser = $browser; $this->categoryViewPage = $categoryView; $categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory); - $this->browser->open($this->getCategoryUrl($category)); - $this->assertGeneralInformation($category, $categoryData); - $this->assertDisplaySetting($category, $categoryData); + $this->browser->open($this->getCategoryUrl($this->finalCategory)); + $this->assertGeneralInformation($this->finalCategory, $categoryData); + $this->assertDisplaySetting($this->finalCategory, $categoryData); } /** @@ -90,6 +97,29 @@ protected function prepareData(FixtureFactory $fixtureFactory, Category $categor ); $product->persist(); + $parentCategory = null; + $cmsBlock = null; + foreach ([$initialCategory, $category] as $item) { + $parentSource = $item->getDataFieldConfig('parent_id')['source']; + if (is_a($parentSource, Category\ParentId::class) && $parentSource->getParentCategory()) { + $parentCategory = $parentSource->getParentCategory(); + } + + $cmsBlockSource = $category->getDataFieldConfig('landing_page')['source']; + if (is_a($cmsBlockSource, Category\LandingPage::class) && $cmsBlockSource->getCmsBlock()) { + $cmsBlock = $cmsBlockSource->getCmsBlock(); + } + } + + $data = array_merge( + $initialCategory->getData(), + $category->getData(), + ['parent_id' => ['source' => $parentCategory]], + ['landing_page' => ['source' => $cmsBlock]] + ); + + $this->finalCategory = $fixtureFactory->create(Category::class, ['data' => $data]); + return array_merge($initialCategory->getData(), $category->getData()); } @@ -108,7 +138,7 @@ protected function getCategoryUrl(Category $category) : trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-'); $category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory(); - if (1 == $category->getParentId()) { + if ($category !== null && 1 == $category->getParentId()) { $category = null; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml index 0f3405578401b..e2e7441586604 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml @@ -34,7 +34,7 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php index 5c50278d16297..a4fbb8eed2798 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php @@ -1,6 +1,6 @@ data = $cmsBlock->getTitle(); $this->cmsBlock = $cmsBlock; + } else if (isset($data['source']) && $data['source'] instanceof CmsBlock ) { + $this->cmsBlock = $data['source']; + $this->data = $data['source']->getTitle(); } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/ParentId.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/ParentId.php index 4e768a422dba8..75dd19b51b68f 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/ParentId.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/ParentId.php @@ -1,6 +1,6 @@ parentCategory->persist(); } $this->data = $this->parentCategory->getId(); + } else if (isset($data['source']) && $data['source'] instanceof Category) { + $this->parentCategory = $data['source']; + $this->data = $data['source']->getId(); } else { $this->data = $data; } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml index c039cb2158798..ac292b67e01c7 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml @@ -47,7 +47,7 @@ - No + No custom Category %isolation% From d54837d0383e535df86e62295fb81bb1dc1908e3 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Wed, 18 Jan 2017 19:30:27 +0200 Subject: [PATCH 06/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../TestSuite/InjectableTests/MAGETWO-63209.xml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml deleted file mode 100644 index 0e0dd3c94b491..0000000000000 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - From 4f9fd3b1237c562b52a08359aad1e461d89f8d1e Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Wed, 18 Jan 2017 21:05:30 +0200 Subject: [PATCH 07/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Test/Constraint/AssertCategoryForm.php | 5 +- .../Test/Constraint/AssertCategoryPage.php | 38 ++---------- .../Catalog/Test/Fixture/Category/StoreId.php | 5 +- .../Category/UpdateCategoryEntityTest.php | 59 ++++++++++++++++++- .../InjectableTests/MAGETWO-63209.xml | 15 +++++ 5 files changed, 83 insertions(+), 39 deletions(-) create mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php index f382d51b7a8e1..30942cbcbde01 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php @@ -1,6 +1,6 @@ browser = $browser; $this->categoryViewPage = $categoryView; $categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory); - $this->browser->open($this->getCategoryUrl($this->finalCategory)); - $this->assertGeneralInformation($this->finalCategory, $categoryData); - $this->assertDisplaySetting($this->finalCategory, $categoryData); + $this->browser->open($this->getCategoryUrl($category)); + $this->assertGeneralInformation($category, $categoryData); + $this->assertDisplaySetting($category, $categoryData); } /** @@ -97,30 +90,7 @@ protected function prepareData(FixtureFactory $fixtureFactory, Category $categor ); $product->persist(); - $parentCategory = null; - $cmsBlock = null; - foreach ([$initialCategory, $category] as $item) { - $parentSource = $item->getDataFieldConfig('parent_id')['source']; - if (is_a($parentSource, Category\ParentId::class) && $parentSource->getParentCategory()) { - $parentCategory = $parentSource->getParentCategory(); - } - - $cmsBlockSource = $category->getDataFieldConfig('landing_page')['source']; - if (is_a($cmsBlockSource, Category\LandingPage::class) && $cmsBlockSource->getCmsBlock()) { - $cmsBlock = $cmsBlockSource->getCmsBlock(); - } - } - - $data = array_merge( - $initialCategory->getData(), - $category->getData(), - ['parent_id' => ['source' => $parentCategory]], - ['landing_page' => ['source' => $cmsBlock]] - ); - - $this->finalCategory = $fixtureFactory->create(Category::class, ['data' => $data]); - - return array_merge($initialCategory->getData(), $category->getData()); + return $category->getData(); } /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/StoreId.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/StoreId.php index 81c1d2a1b657a..4244a67c0e656 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/StoreId.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/StoreId.php @@ -1,6 +1,6 @@ store = $store; $this->data = $store->getGroupId() . '/' . $store->getName(); + } else if (isset($data['source']) && $data['source'] instanceof Store) { + $this->store = $data['source']; + $this->data = $this->store->getGroupId() . '/' . $this->store->getName(); } else { $this->data = $data; } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php index f8eff140140ff..cd0799a97b009 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php @@ -9,6 +9,7 @@ use Magento\Catalog\Test\Fixture\Category; use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit; use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex; +use Magento\Mtf\Fixture\FixtureFactory; use Magento\Mtf\TestCase\Injectable; use Magento\Mtf\TestStep\TestStepFactory; @@ -65,6 +66,13 @@ class UpdateCategoryEntityTest extends Injectable */ protected $testStepFactory; + /** + * Fixture create factory. + * + * @var FixtureFactory + */ + protected $fixtureFactory; + /** * Inject page end prepare default category. * @@ -72,18 +80,22 @@ class UpdateCategoryEntityTest extends Injectable * @param CatalogCategoryIndex $catalogCategoryIndex * @param CatalogCategoryEdit $catalogCategoryEdit * @param TestStepFactory $testStepFactory + * @param FixtureFactory $fixtureFactory * @return array */ public function __inject( Category $initialCategory, CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit, - TestStepFactory $testStepFactory + TestStepFactory $testStepFactory, + FixtureFactory $fixtureFactory ) { $this->catalogCategoryIndex = $catalogCategoryIndex; $this->catalogCategoryEdit = $catalogCategoryEdit; $this->testStepFactory = $testStepFactory; + $this->fixtureFactory = $fixtureFactory; $initialCategory->persist(); + return ['initialCategory' => $initialCategory]; } @@ -93,7 +105,7 @@ public function __inject( * @param Category $category * @param Category $initialCategory * @param string $configData - * @return void + * @return array */ public function test(Category $category, Category $initialCategory, $configData = null) { @@ -110,6 +122,49 @@ public function test(Category $category, Category $initialCategory, $configData $this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory); $this->catalogCategoryEdit->getEditForm()->fill($category); $this->catalogCategoryEdit->getFormPageActions()->save(); + + return ['category' => $this->prepareCategory($category, $initialCategory)]; + } + + /** + * Prepare category fixture with updated data. + * + * @param Category $category + * @param Category $initialCategory + * @return Category + */ + private function prepareCategory(Category $category, Category $initialCategory) + { + $parentCategory = null; + $cmsBlock = null; + $store = null; + + foreach ([$initialCategory, $category] as $item) { + $parentSource = $item->getDataFieldConfig('parent_id')['source']; + if (is_a($parentSource, Category\ParentId::class) && $parentSource->getParentCategory()) { + $parentCategory = $parentSource->getParentCategory(); + } + + $cmsBlockSource = $category->getDataFieldConfig('landing_page')['source']; + if (is_a($cmsBlockSource, Category\LandingPage::class) && $cmsBlockSource->getCmsBlock()) { + $cmsBlock = $cmsBlockSource->getCmsBlock(); + } + + $storeSource = $category->getDataFieldConfig('store_id')['source']; + if (is_a($storeSource, Category\StoreId::class) && $storeSource->getStore()) { + $store = $storeSource->getStore(); + } + } + + $data = array_merge( + $initialCategory->getData(), + $category->getData(), + ['parent_id' => ['source' => $parentCategory]], + ['landing_page' => ['source' => $cmsBlock]], + ['store_id' => ['source' => $store]] + ); + + return $this->fixtureFactory->create(Category::class, ['data' => $data]); } /** diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml new file mode 100644 index 0000000000000..0e0dd3c94b491 --- /dev/null +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml @@ -0,0 +1,15 @@ + + + + + + + + + From 68a406845edd8d76eee826bd7a35538efa23a1ab Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Wed, 18 Jan 2017 21:19:48 +0200 Subject: [PATCH 08/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../TestSuite/InjectableTests/MAGETWO-63209.xml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml deleted file mode 100644 index 0e0dd3c94b491..0000000000000 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - From 1a0c885b66bb0c7bbdc7b2d7cda94cb40c3016fd Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Thu, 19 Jan 2017 11:10:39 +0200 Subject: [PATCH 09/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Test/Constraint/AssertCategoryPage.php | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php index b70a847ec52b8..65aa17e0d9000 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php @@ -46,7 +46,6 @@ class AssertCategoryPage extends AbstractConstraint * Assert that displayed category data on category page equals to passed from fixture. * * @param Category $category - * @param Category $initialCategory * @param FixtureFactory $fixtureFactory * @param CatalogCategoryView $categoryView * @param BrowserInterface $browser @@ -54,17 +53,16 @@ class AssertCategoryPage extends AbstractConstraint */ public function processAssert( Category $category, - Category $initialCategory, FixtureFactory $fixtureFactory, CatalogCategoryView $categoryView, BrowserInterface $browser ) { $this->browser = $browser; $this->categoryViewPage = $categoryView; - $categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory); + $this->prepareData($fixtureFactory, $category); $this->browser->open($this->getCategoryUrl($category)); - $this->assertGeneralInformation($category, $categoryData); - $this->assertDisplaySetting($category, $categoryData); + $this->assertGeneralInformation($category); + $this->assertDisplaySetting($category); } /** @@ -72,10 +70,9 @@ public function processAssert( * * @param FixtureFactory $fixtureFactory * @param Category $category - * @param Category $initialCategory - * @return array + * @return void */ - protected function prepareData(FixtureFactory $fixtureFactory, Category $category, Category $initialCategory) + protected function prepareData(FixtureFactory $fixtureFactory, Category $category) { $product = $fixtureFactory->createByCode( 'catalogProductSimple', @@ -83,14 +80,12 @@ protected function prepareData(FixtureFactory $fixtureFactory, Category $categor 'dataset' => 'default', 'data' => [ 'category_ids' => [ - 'category' => $initialCategory, + 'category' => $category, ], ] ] ); $product->persist(); - - return $category->getData(); } /** @@ -120,10 +115,9 @@ protected function getCategoryUrl(Category $category) * Assert category general information. * * @param Category $category - * @param array $categoryData * @return void */ - protected function assertGeneralInformation(Category $category, array $categoryData) + protected function assertGeneralInformation(Category $category) { $categoryUrl = $this->getCategoryUrl($category); \PHPUnit_Framework_Assert::assertEquals( @@ -134,24 +128,24 @@ protected function assertGeneralInformation(Category $category, array $categoryD . "\nActual: " . $this->browser->getUrl() ); - if (isset($categoryData['name'])) { + if ($category->getName()) { $title = $this->categoryViewPage->getTitleBlock()->getTitle(); \PHPUnit_Framework_Assert::assertEquals( - $categoryData['name'], + $category->getName(), $title, 'Wrong page title.' - . "\nExpected: " . $categoryData['name'] + . "\nExpected: " . $category->getName() . "\nActual: " . $title ); } - if (isset($categoryData['description'])) { + if ($category->getDescription()) { $description = $this->categoryViewPage->getViewBlock()->getDescription(); \PHPUnit_Framework_Assert::assertEquals( - $categoryData['description'], + $category->getDescription(), $description, 'Wrong category description.' - . "\nExpected: " . $categoryData['description'] + . "\nExpected: " . $category->getDescription() . "\nActual: " . $description ); } @@ -161,15 +155,14 @@ protected function assertGeneralInformation(Category $category, array $categoryD * Assert category display settings. * * @param Category $category - * @param array $categoryData * @return void */ - protected function assertDisplaySetting(Category $category, array $categoryData) + protected function assertDisplaySetting(Category $category) { if ( - isset($categoryData['landing_page']) - && isset($categoryData['display_mode']) - && in_array($categoryData['display_mode'], $this->visibleCmsBlockMode) + $category->getLandingPage() + && $category->getDisplayMode() + && in_array($category->getDisplayMode(), $this->visibleCmsBlockMode) ) { /** @var LandingPage $sourceLandingPage */ $sourceLandingPage = $category->getDataFieldConfig('landing_page')['source']; @@ -184,8 +177,8 @@ protected function assertDisplaySetting(Category $category, array $categoryData) . "\nActual: " . $pageContent ); } - if (isset($categoryData['default_sort_by'])) { - $sortBy = strtolower($categoryData['default_sort_by']); + if ($category->getDefaultSortBy()) { + $sortBy = strtolower($category->getDefaultSortBy()); $sortType = $this->categoryViewPage->getTopToolbar()->getSelectSortType(); \PHPUnit_Framework_Assert::assertEquals( $sortBy, @@ -196,9 +189,9 @@ protected function assertDisplaySetting(Category $category, array $categoryData) ); } - if (isset($categoryData['available_sort_by'])) { + if ($category->getAvailableSortBy()) { $availableSortType = array_filter( - $categoryData['available_sort_by'], + $category->getAvailableSortBy(), function (&$value) { return $value !== '-' && ucfirst($value); } From 5a516791b64f2f602b7d00b7576cea1f360af87c Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Thu, 19 Jan 2017 11:35:40 +0200 Subject: [PATCH 10/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../TestSuite/InjectableTests/MAGETWO-63209.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml new file mode 100644 index 0000000000000..6d4ba67c23b20 --- /dev/null +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + From c252ae1b715dafacef261c1690bc3f31fb850a0c Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Thu, 19 Jan 2017 12:51:39 +0200 Subject: [PATCH 11/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Test/Constraint/AssertCategoryPage.php | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php index 65aa17e0d9000..6c3f746b92f51 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php @@ -11,7 +11,6 @@ use Magento\Catalog\Test\Page\Category\CatalogCategoryView; use Magento\Mtf\Client\BrowserInterface; use Magento\Mtf\Constraint\AbstractConstraint; -use Magento\Mtf\Fixture\FixtureFactory; /** * Assert that displayed category data on category page equals to passed from fixture. @@ -46,48 +45,23 @@ class AssertCategoryPage extends AbstractConstraint * Assert that displayed category data on category page equals to passed from fixture. * * @param Category $category - * @param FixtureFactory $fixtureFactory * @param CatalogCategoryView $categoryView * @param BrowserInterface $browser * @return void */ public function processAssert( Category $category, - FixtureFactory $fixtureFactory, CatalogCategoryView $categoryView, BrowserInterface $browser ) { $this->browser = $browser; $this->categoryViewPage = $categoryView; - $this->prepareData($fixtureFactory, $category); $this->browser->open($this->getCategoryUrl($category)); + $this->assertGeneralInformation($category); $this->assertDisplaySetting($category); } - /** - * Prepare comparison data. - * - * @param FixtureFactory $fixtureFactory - * @param Category $category - * @return void - */ - protected function prepareData(FixtureFactory $fixtureFactory, Category $category) - { - $product = $fixtureFactory->createByCode( - 'catalogProductSimple', - [ - 'dataset' => 'default', - 'data' => [ - 'category_ids' => [ - 'category' => $category, - ], - ] - ] - ); - $product->persist(); - } - /** * Get category url to open. * From 003b6b14ac1675651cd764dff4da848af62de732 Mon Sep 17 00:00:00 2001 From: Myroslav Dobra Date: Thu, 19 Jan 2017 15:32:26 +0200 Subject: [PATCH 12/16] MAGETWO-63243: The extension installed via Composer can not be uninstalled via Extension Manager. --- .../Magento/Test/Legacy/CopyrightTest.php | 2 +- .../Setup/Model/UninstallDependencyCheck.php | 24 +++++++++++++++++++ .../Model/UninstallDependencyCheckTest.php | 22 ++++++++++++----- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php index 582a63ceb19ed..af9a4cffee3d4 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/CopyrightTest.php @@ -17,7 +17,7 @@ public function testCopyright() $invoker( function ($filename) { $fileText = file_get_contents($filename); - if (strpos($fileText, 'Copyright © ' . date('Y')) === false) { + if (strpos($fileText, 'Copyright © 2016') === false) { $this->fail('Copyright is missing or has wrong year in ' . $filename); } }, diff --git a/setup/src/Magento/Setup/Model/UninstallDependencyCheck.php b/setup/src/Magento/Setup/Model/UninstallDependencyCheck.php index e09cee267ded3..5d3db58708918 100644 --- a/setup/src/Magento/Setup/Model/UninstallDependencyCheck.php +++ b/setup/src/Magento/Setup/Model/UninstallDependencyCheck.php @@ -15,6 +15,13 @@ */ class UninstallDependencyCheck { + /** + * Need to exclude these packages from dependencies because of changes in composer/composer package + * It consider now that all packages are depends on root package + * @var array + */ + private $rootDependencies = ['magento/magento2ce', 'magento/magento2ee']; + /** * @var ComposerInformation */ @@ -61,6 +68,7 @@ public function runUninstallReadinessCheck(array $packages) try { $packagesAndTypes = $this->composerInfo->getRootRequiredPackageTypesByName(); $dependencies = $this->packageDependencyChecker->checkDependencies($packages, true); + $dependencies = $this->excludeRootDependencies($dependencies); $messages = []; $themes = []; @@ -101,4 +109,20 @@ public function runUninstallReadinessCheck(array $packages) return ['success' => false, 'error' => $message]; } } + + /** + * Exclude root dependencies like 'magento/magento2ce' or 'magento/magento2ee' + * + * @param array $dependencies + * @return array + */ + private function excludeRootDependencies($dependencies) + { + $result = []; + foreach ($dependencies as $packageName => $packageDependencies) { + $result[$packageName] = array_values(array_diff($packageDependencies, $this->rootDependencies)); + } + + return $result; + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/UninstallDependencyCheckTest.php b/setup/src/Magento/Setup/Test/Unit/Model/UninstallDependencyCheckTest.php index 2b643bd4eb2ca..633184abaeb98 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/UninstallDependencyCheckTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/UninstallDependencyCheckTest.php @@ -37,23 +37,23 @@ class UninstallDependencyCheckTest extends \PHPUnit_Framework_TestCase public function setup() { - $this->composerInfo = $this->getMock('Magento\Framework\Composer\ComposerInformation', [], [], '', false); + $this->composerInfo = $this->getMock(\Magento\Framework\Composer\ComposerInformation::class, [], [], '', false); $this->packageDependencyChecker = $this->getMock( - 'Magento\Framework\Composer\DependencyChecker', + \Magento\Framework\Composer\DependencyChecker::class, [], [], '', false ); $this->themeDependencyChecker = $this->getMock( - 'Magento\Theme\Model\Theme\ThemeDependencyChecker', + \Magento\Theme\Model\Theme\ThemeDependencyChecker::class, [], [], '', false ); $this->themeDependencyCheckerFactory = $this->getMock( - 'Magento\Setup\Model\ThemeDependencyCheckerFactory', + \Magento\Setup\Model\ThemeDependencyCheckerFactory::class, [], [], '', @@ -81,7 +81,12 @@ public function testRunUninstallReadinessCheck() $this->packageDependencyChecker->expects($this->once()) ->method('checkDependencies') ->with(array_keys($packages)) - ->willReturn([]); + ->willReturn([ + 'verndor/module' => ['magento/magento2ce'], + 'verndor/theme' => ['magento/magento2ee'], + 'verndor/metapackage' => ['magento/magento2ce'], + 'verndor/language' => ['magento/magento2ce'], + ]); $this->themeDependencyChecker->expects($this->once()) ->method('checkChildThemeByPackagesName') @@ -105,7 +110,12 @@ public function testRunUninstallReadinessCheckWithError() $this->packageDependencyChecker->expects($this->once()) ->method('checkDependencies') ->with(array_keys($packages)) - ->willReturn([]); + ->willReturn([ + 'verndor/module' => ['magento/magento2ce'], + 'verndor/theme' => ['magento/magento2ee'], + 'verndor/metapackage' => ['magento/magento2ce'], + 'verndor/language' => ['magento/magento2ce'], + ]); $this->themeDependencyChecker->expects($this->once()) ->method('checkChildThemeByPackagesName') From 35951f833fcb5a6e721b9fbc35008825815e69fa Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Thu, 19 Jan 2017 22:35:41 +0200 Subject: [PATCH 13/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Category/Collection/Factory.php | 2 +- .../Model/ResourceModel/Category/Flat.php | 2 +- .../Model/ResourceModel/Category/FlatTest.php | 2 +- .../Adminhtml/Category/Edit/CategoryForm.php | 28 +++++++ .../Adminhtml/Category/Edit/CategoryForm.xml | 2 +- .../Test/Constraint/AssertCategoryForm.php | 2 +- .../Test/Constraint/AssertCategoryPage.php | 29 ++++++- .../Magento/Catalog/Test/Fixture/Category.xml | 2 +- .../Fixture/Category/CategoryProducts.php | 5 ++ .../Test/Fixture/Category/LandingPage.php | 2 +- .../Test/Fixture/Category/ParentId.php | 2 +- .../Catalog/Test/Fixture/Category/StoreId.php | 2 +- .../Catalog/Test/Handler/Category/Webapi.php | 2 +- .../Catalog/Test/Repository/ConfigData.xml | 2 +- .../Category/CreateCategoryEntityTest.php | 78 +++++++++++++++++-- .../Category/UpdateCategoryEntityTest.php | 2 +- .../Category/UpdateCategoryEntityTest.xml | 2 +- 17 files changed, 144 insertions(+), 22 deletions(-) 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 127c8fe378ea5..e31ea5bbd119e 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php @@ -1,6 +1,6 @@ fillTabs($tabs, $element); } + + /** + * Return category Id. + * + * @return string + */ + public function getCategoryId() + { + $titleElement = $this->_rootElement->find($this->categoryTitle); + $title = ''; + if ($titleElement->isVisible()) { + $title = $titleElement->getText(); + } + + $categoryId = ''; + if (preg_match('/ID:\s*(?\d+)/', $title, $matches)) { + $categoryId = $matches['id']; + } + + return $categoryId; + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml index 969cc6f6a4918..bfe8d0e5c06a9 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml @@ -1,7 +1,7 @@ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php index 30942cbcbde01..9cde40a83ce5b 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php @@ -1,6 +1,6 @@ browser = $browser; $this->categoryViewPage = $categoryView; + $this->prepareData($fixtureFactory, $category); $this->browser->open($this->getCategoryUrl($category)); $this->assertGeneralInformation($category); $this->assertDisplaySetting($category); } + /** + * Prepare comparison data. + * + * @param FixtureFactory $fixtureFactory + * @param Category $category + * @return void + */ + protected function prepareData(FixtureFactory $fixtureFactory, Category $category) + { + $product = $fixtureFactory->createByCode( + 'catalogProductSimple', + [ + 'dataset' => 'default', + 'data' => [ + 'category_ids' => [ + 'category' => $category, + ], + ] + ] + ); + $product->persist(); + } + /** * Get category url to open. * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml index e2e7441586604..d9e51f533bc42 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml @@ -1,7 +1,7 @@ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/CategoryProducts.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/CategoryProducts.php index aa3f2138fbe41..c28d62d3e4ca3 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/CategoryProducts.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/CategoryProducts.php @@ -41,6 +41,11 @@ public function __construct(FixtureFactory $fixtureFactory, array $params, $data $this->data[] = $product->getName(); $this->products[] = $product; } + } else if (isset($data['products']) && is_array($data['products'])) { + foreach ($data['products'] as $product) { + $this->data[] = $product->getName(); + $this->products[] = $product; + } } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php index a4fbb8eed2798..510389632aac7 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/LandingPage.php @@ -1,6 +1,6 @@ prepareData($fixture); - $url = $_ENV['app_frontend_url'] . 'rest/V1/categories'; + $url = $_ENV['app_frontend_url'] . 'rest/all/V1/categories'; $this->webapiTransport->write($url, $data); $response = json_decode($this->webapiTransport->read(), true); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml index 68c36c16fba40..924d3ee4c1c3e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml @@ -1,7 +1,7 @@ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.php index fe4e491aa4b04..61185c43a30c3 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.php @@ -9,10 +9,11 @@ use Magento\Catalog\Test\Fixture\Category; use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit; use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex; +use Magento\Mtf\Fixture\FixtureFactory; use Magento\Mtf\TestCase\Injectable; /** - * Test Creation for CreateCategoryEntity + * Test Creation for CreateCategoryEntity. * * Test Flow: * 1. Login as admin @@ -34,38 +35,50 @@ class CreateCategoryEntityTest extends Injectable /* end tags */ /** - * Catalog category index page + * Catalog category index page. * * @var CatalogCategoryIndex */ protected $catalogCategoryIndex; /** - * Catalog category edit page + * Catalog category edit page. * * @var CatalogCategoryEdit */ protected $catalogCategoryEdit; /** - * Inject pages + * Fixture create factory. + * + * @var FixtureFactory + */ + protected $fixtureFactory; + + /** + * Inject pages. * * @param CatalogCategoryIndex $catalogCategoryIndex * @param CatalogCategoryEdit $catalogCategoryEdit + * @param FixtureFactory $fixtureFactory * @return void */ - public function __inject(CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit) - { + public function __inject( + CatalogCategoryIndex $catalogCategoryIndex, + CatalogCategoryEdit $catalogCategoryEdit, + FixtureFactory $fixtureFactory + ) { $this->catalogCategoryIndex = $catalogCategoryIndex; $this->catalogCategoryEdit = $catalogCategoryEdit; + $this->fixtureFactory = $fixtureFactory; } /** - * Create category + * Create category. * * @param Category $category * @param string $addCategory - * @return void + * @return array */ public function test(Category $category, $addCategory) { @@ -74,5 +87,54 @@ public function test(Category $category, $addCategory) $this->catalogCategoryIndex->getTreeCategories()->$addCategory(); $this->catalogCategoryEdit->getEditForm()->fill($category); $this->catalogCategoryEdit->getFormPageActions()->save(); + $categoryId = $this->catalogCategoryEdit->getEditForm()->getCategoryId(); + + return ['category' => $this->prepareCategory($category, $categoryId)]; + } + + /** + * Prepare category fixture data. + * + * @param Category $category + * @param string $categoryId + * @return Category + */ + private function prepareCategory(Category $category, $categoryId) + { + $parentCategory = null; + $cmsBlock = null; + $store = null; + $products = null; + + $parentSource = $category->getDataFieldConfig('parent_id')['source']; + if (is_a($parentSource, Category\ParentId::class) && $parentSource->getParentCategory()) { + $parentCategory = $parentSource->getParentCategory(); + } + + $cmsBlockSource = $category->getDataFieldConfig('landing_page')['source']; + if (is_a($cmsBlockSource, Category\LandingPage::class) && $cmsBlockSource->getCmsBlock()) { + $cmsBlock = $cmsBlockSource->getCmsBlock(); + } + + $storeSource = $category->getDataFieldConfig('store_id')['source']; + if (is_a($storeSource, Category\StoreId::class) && $storeSource->getStore()) { + $store = $storeSource->getStore(); + } + + $productSource = $category->getDataFieldConfig('category_products')['source']; + if (is_a($productSource, Category\CategoryProducts::class) && $productSource->getProducts()) { + $products = $productSource->getProducts(); + } + + $data = array_merge( + $category->getData(), + ['id' => $categoryId], + ['parent_id' => ['source' => $parentCategory]], + ['landing_page' => ['source' => $cmsBlock]], + ['store_id' => ['source' => $store]], + ['category_products' => ['products' => $products]] + ); + + return $this->fixtureFactory->create(Category::class, ['data' => $data]); } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php index cd0799a97b009..6741e8862da8c 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php @@ -1,6 +1,6 @@ From 448ed1e4407e7e39c02eed7fcf883f65398f3078 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Thu, 19 Jan 2017 22:54:45 +0200 Subject: [PATCH 14/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../TestSuite/InjectableTests/MAGETWO-63209.xml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml deleted file mode 100644 index 6d4ba67c23b20..0000000000000 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-63209.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - From 1b25f08ee8ddd4909d34c6e14a23a49e12f93bfa Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Fri, 20 Jan 2017 11:20:27 +0200 Subject: [PATCH 15/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Model/ResourceModel/Category/Collection/Factory.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 e31ea5bbd119e..2c5dde8afda53 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category/Collection/Factory.php @@ -6,8 +6,7 @@ namespace Magento\Catalog\Model\ResourceModel\Category\Collection; /** - * Class Factory - * @deprecated + * Category collection factory. */ class Factory { From 0219ace8f2e16c8e7babaaf85f37788d38749486 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Fri, 20 Jan 2017 11:56:03 +0200 Subject: [PATCH 16/16] MAGETWO-63209: Fatal error on category page when changing display mode with flat category on --- .../Adminhtml/Category/Edit/CategoryForm.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.php index ce8336618fadf..a275fd5e7b600 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.php @@ -37,13 +37,6 @@ class CategoryForm extends FormTabs */ protected $confirmModal = '.confirm._show[data-role=modal]'; - /** - * Category edit title. - * - * @var string - */ - protected $categoryTitle = '.category-edit-title h3.title'; - /** * Fill form with tabs. * @@ -74,14 +67,8 @@ public function fill(FixtureInterface $fixture, SimpleElement $element = null) */ public function getCategoryId() { - $titleElement = $this->_rootElement->find($this->categoryTitle); - $title = ''; - if ($titleElement->isVisible()) { - $title = $titleElement->getText(); - } - $categoryId = ''; - if (preg_match('/ID:\s*(?\d+)/', $title, $matches)) { + if (preg_match('/\/id\/(?\d+)(?:\/)?/', $this->browser->getUrl(), $matches)) { $categoryId = $matches['id']; }