From 2c9cc60762316176a924de211da017f25376fb5b Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Tue, 5 Jun 2018 14:21:22 -0500 Subject: [PATCH 1/4] MAGETWO-91437: Invalidate indexer after category is deleted - Write plugin to invalidate fulltext - Invalidate category_product on after delete for Category resource model - Write integration tests --- .../Catalog/Model/ResourceModel/Category.php | 23 ++ .../Fulltext/Model/Plugin/Category.php | 45 ++++ .../CatalogSearch/etc/adminhtml/di.xml | 3 + .../CatalogSearch/etc/webapi_rest/di.xml | 12 + .../CatalogSearch/etc/webapi_soap/di.xml | 12 + .../Model/Indexer/Category/ProductTest.php | 248 ++++++++++-------- .../Fulltext/Model/Plugin/CategoryTest.php | 69 +++++ 7 files changed, 302 insertions(+), 110 deletions(-) create mode 100644 app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/Category.php create mode 100644 app/code/Magento/CatalogSearch/etc/webapi_rest/di.xml create mode 100644 app/code/Magento/CatalogSearch/etc/webapi_soap/di.xml create mode 100644 dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index 6c9867359d40..4b050e00c1b1 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -11,6 +11,8 @@ */ namespace Magento\Catalog\Model\ResourceModel; +use Magento\Catalog\Model\Indexer\Category\Product\Processor; +use Magento\Framework\DataObject; use Magento\Framework\EntityManager\EntityManager; /** @@ -82,6 +84,11 @@ class Category extends AbstractResource */ protected $aggregateCount; + /** + * @var Processor + */ + private $indexerProcessor; + /** * Category constructor. * @param \Magento\Eav\Model\Entity\Context $context @@ -90,6 +97,7 @@ class Category extends AbstractResource * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param Category\TreeFactory $categoryTreeFactory * @param Category\CollectionFactory $categoryCollectionFactory + * @param Processor $indexerProcessor * @param array $data * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ @@ -100,6 +108,7 @@ public function __construct( \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Catalog\Model\ResourceModel\Category\TreeFactory $categoryTreeFactory, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, + Processor $indexerProcessor, $data = [], \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { @@ -113,6 +122,7 @@ public function __construct( $this->_categoryCollectionFactory = $categoryCollectionFactory; $this->_eventManager = $eventManager; $this->connectionName = 'catalog'; + $this->indexerProcessor = $indexerProcessor; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Serialize\Serializer\Json::class); } @@ -197,6 +207,19 @@ protected function _beforeDelete(\Magento\Framework\DataObject $object) $this->deleteChildren($object); } + /** + * Mark Category indexer as invalid to be picked up by cron. + * + * @param DataObject $object + * @return $this + */ + protected function _afterDelete(DataObject $object) + { + $this->indexerProcessor->markIndexerAsInvalid(); + return parent::_afterDelete($object); + } + + /** * Delete children categories of specific category * diff --git a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/Category.php b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/Category.php new file mode 100644 index 000000000000..ed841996ea07 --- /dev/null +++ b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/Category.php @@ -0,0 +1,45 @@ +fulltextIndexerProcessor = $fulltextIndexerProcessor; + } + + /** + * Mark fulltext indexer as invalid post-deletion of category. + * + * @param Resource $subjectCategory + * @param Resource $resultCategory + * @return Resource + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterDelete(Resource $subjectCategory, Resource $resultCategory) : Resource + { + $this->fulltextIndexerProcessor->markIndexerAsInvalid(); + + return $resultCategory; + } +} diff --git a/app/code/Magento/CatalogSearch/etc/adminhtml/di.xml b/app/code/Magento/CatalogSearch/etc/adminhtml/di.xml index d6c72d883fed..2d41d17889e4 100644 --- a/app/code/Magento/CatalogSearch/etc/adminhtml/di.xml +++ b/app/code/Magento/CatalogSearch/etc/adminhtml/di.xml @@ -31,4 +31,7 @@ Magento\CatalogSearch\Ui\DataProvider\Product\AddFulltextFilterToCollection + + + diff --git a/app/code/Magento/CatalogSearch/etc/webapi_rest/di.xml b/app/code/Magento/CatalogSearch/etc/webapi_rest/di.xml new file mode 100644 index 000000000000..c7293783dc60 --- /dev/null +++ b/app/code/Magento/CatalogSearch/etc/webapi_rest/di.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/code/Magento/CatalogSearch/etc/webapi_soap/di.xml b/app/code/Magento/CatalogSearch/etc/webapi_soap/di.xml new file mode 100644 index 000000000000..c7293783dc60 --- /dev/null +++ b/app/code/Magento/CatalogSearch/etc/webapi_soap/di.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php index 6efd2638c0d5..59f7b34e777d 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php @@ -27,6 +27,11 @@ class ProductTest extends \PHPUnit\Framework\TestCase */ protected $productResource; + /** + * @var \Magento\Catalog\Api\CategoryRepositoryInterface + */ + private $categoryRepository; + protected function setUp() { /** @var \Magento\Framework\Indexer\IndexerInterface indexer */ @@ -39,6 +44,10 @@ protected function setUp() $this->productResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( \Magento\Catalog\Model\ResourceModel\Product::class ); + + $this->categoryRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Catalog\Api\CategoryRepositoryInterface::class + ); } /** @@ -79,125 +88,144 @@ public function testReindexAll() } } - /** - * @magentoAppArea adminhtml - */ - public function testCategoryMove() - { - $categories = $this->getCategories(4); - $products = $this->getProducts(2); - - /** @var Category $categoryFourth */ - $categoryFourth = end($categories); - foreach ($products as $product) { - /** @var \Magento\Catalog\Model\Product $product */ - $product->setCategoryIds([$categoryFourth->getId()]); - $product->save(); - } - - /** @var Category $categorySecond */ - $categorySecond = $categories[1]; - $categorySecond->setIsAnchor(true); - $categorySecond->save(); - - /** @var Category $categoryThird */ - $categoryThird = $categories[2]; - $categoryThird->setIsAnchor(true); - $categoryThird->save(); - - $this->clearIndex(); - $this->indexer->reindexAll(); - - /** - * Move $categoryFourth from $categoryThird to $categorySecond - */ - $categoryFourth->move($categorySecond->getId(), null); - - $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySecond->getId(), $categoryFourth->getId()]; - - foreach ($products as $product) { - /** @var \Magento\Catalog\Model\Product $product */ - foreach ($categories as $categoryId) { - $this->assertTrue((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); - } - - $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryThird->getId())); - } - } +// /** +// * @magentoAppArea adminhtml +// */ +// public function testCategoryMove() +// { +// $categories = $this->getCategories(4); +// $products = $this->getProducts(2); +// +// /** @var Category $categoryFourth */ +// $categoryFourth = end($categories); +// foreach ($products as $product) { +// /** @var \Magento\Catalog\Model\Product $product */ +// $product->setCategoryIds([$categoryFourth->getId()]); +// $product->save(); +// } +// +// /** @var Category $categorySecond */ +// $categorySecond = $categories[1]; +// $categorySecond->setIsAnchor(true); +// $categorySecond->save(); +// +// /** @var Category $categoryThird */ +// $categoryThird = $categories[2]; +// $categoryThird->setIsAnchor(true); +// $categoryThird->save(); +// +// $this->clearIndex(); +// $this->indexer->reindexAll(); +// +// /** +// * Move $categoryFourth from $categoryThird to $categorySecond +// */ +// $categoryFourth->move($categorySecond->getId(), null); +// +// $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySecond->getId(), $categoryFourth->getId()]; +// +// foreach ($products as $product) { +// /** @var \Magento\Catalog\Model\Product $product */ +// foreach ($categories as $categoryId) { +// $this->assertTrue((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); +// } +// +// $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryThird->getId())); +// } +// } +// +// /** +// * @magentoAppArea adminhtml +// * @depends testReindexAll +// */ +// public function testCategoryDelete() +// { +// $categories = $this->getCategories(4); +// $products = $this->getProducts(2); +// +// /** @var Category $categoryFourth */ +// $categoryFourth = end($categories); +// $categoryFourth->delete(); +// +// /** @var Category $categorySecond */ +// $categorySecond = $categories[1]; +// +// $categories = [$categorySecond->getId(), $categoryFourth->getId()]; +// +// foreach ($products as $product) { +// /** @var \Magento\Catalog\Model\Product $product */ +// foreach ($categories as $categoryId) { +// $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); +// } +// $this->assertTrue( +// (bool)$this->productResource->canBeShowInCategory($product, self::DEFAULT_ROOT_CATEGORY) +// ); +// } +// } +// +// public function testCategoryCreate() +// { +// $this->testReindexAll(); +// $categories = $this->getCategories(4); +// $products = $this->getProducts(3); +// +// /** @var Category $categorySecond */ +// $categorySecond = $categories[1]; +// $categorySecond->setIsAnchor(0); +// $categorySecond->save(); +// +// /** @var Category $categoryFourth */ +// $categoryFourth = end($categories); +// +// /** @var Category $categorySixth */ +// $categorySixth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( +// \Magento\Catalog\Model\Category::class +// ); +// $categorySixth->setName( +// 'Category 6' +// )->setPath( +// $categoryFourth->getPath() +// )->setAvailableSortBy( +// 'name' +// )->setDefaultSortBy( +// 'name' +// )->setIsActive( +// true +// )->save(); +// +// /** @var \Magento\Catalog\Model\Product $productThird */ +// $productThird = end($products); +// $productThird->setCategoryIds([$categorySixth->getId()]); +// $productThird->save(); +// +// $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySixth->getId(), $categoryFourth->getId()]; +// foreach ($categories as $categoryId) { +// $this->assertTrue((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); +// } +// +// $categories = [$categorySecond->getId()]; +// foreach ($categories as $categoryId) { +// $this->assertFalse((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); +// } +// } /** * @magentoAppArea adminhtml * @depends testReindexAll */ - public function testCategoryDelete() - { - $categories = $this->getCategories(4); - $products = $this->getProducts(2); - - /** @var Category $categoryFourth */ - $categoryFourth = end($categories); - $categoryFourth->delete(); - - /** @var Category $categorySecond */ - $categorySecond = $categories[1]; - - $categories = [$categorySecond->getId(), $categoryFourth->getId()]; - - foreach ($products as $product) { - /** @var \Magento\Catalog\Model\Product $product */ - foreach ($categories as $categoryId) { - $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); - } - $this->assertTrue( - (bool)$this->productResource->canBeShowInCategory($product, self::DEFAULT_ROOT_CATEGORY) - ); - } - } - - public function testCategoryCreate() + public function testCatalogCategoryProductIndexInvalidateAfterDelete() { - $this->testReindexAll(); - $categories = $this->getCategories(4); - $products = $this->getProducts(3); - - /** @var Category $categorySecond */ - $categorySecond = $categories[1]; - $categorySecond->setIsAnchor(0); - $categorySecond->save(); + $indexerShouldBeValid = (bool)$this->indexer->isInvalid(); - /** @var Category $categoryFourth */ - $categoryFourth = end($categories); + $categories = $this->getCategories(1); + $this->categoryRepository->delete(array_pop($categories)); - /** @var Category $categorySixth */ - $categorySixth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Catalog\Model\Category::class - ); - $categorySixth->setName( - 'Category 6' - )->setPath( - $categoryFourth->getPath() - )->setAvailableSortBy( - 'name' - )->setDefaultSortBy( - 'name' - )->setIsActive( - true - )->save(); - - /** @var \Magento\Catalog\Model\Product $productThird */ - $productThird = end($products); - $productThird->setCategoryIds([$categorySixth->getId()]); - $productThird->save(); - - $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySixth->getId(), $categoryFourth->getId()]; - foreach ($categories as $categoryId) { - $this->assertTrue((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); - } + $state = $this->indexer->getState(); + $state->loadByIndexer($this->indexer->getId()); + $status = $state->getStatus(); - $categories = [$categorySecond->getId()]; - foreach ($categories as $categoryId) { - $this->assertFalse((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); - } + $this->assertFalse($indexerShouldBeValid); + $this->assertEquals(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID, $status); } /** diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php new file mode 100644 index 000000000000..4795a43bfc77 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php @@ -0,0 +1,69 @@ +indexerProcessor = Bootstrap::getObjectManager()->create(Processor::class); + $this->categoryRepository = Bootstrap::getObjectManager()->create(CategoryRepositoryInterface::class); + } + + /** + * @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php + * @magentoAppArea adminhtml + */ + public function testIndexerInvalidatedAfterCategoryDelete() + { + $this->indexerProcessor->reindexAll(); + $isIndexerValid = (bool)$this->indexerProcessor->getIndexer()->isValid(); + + $category = $this->getCategories(1); + $this->categoryRepository->delete(array_pop($category)); + + $state = $this->indexerProcessor->getIndexer()->getState(); + $state->loadByIndexer($this->indexerProcessor->getIndexerId()); + $status = $state->getStatus(); + + $this->assertTrue($isIndexerValid); + $this->assertEquals(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID, $status); + } + + /** + * @param int $count + * @return Category[] + */ + private function getCategories($count) + { + /** @var Category $category */ + $category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Catalog\Model\Category::class + ); + + $result = $category->getCollection()->addAttributeToSelect('name')->getItems(); + $result = array_slice($result, 2); + + return array_slice($result, 0, $count); + } +} From eeef0be757ed527bb451166140bf2be9683dfe08 Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Tue, 5 Jun 2018 14:55:18 -0500 Subject: [PATCH 2/4] MAGETWO-91437: Fix tests --- .../Model/Indexer/Category/ProductTest.php | 240 +++++++++--------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php index 59f7b34e777d..dab47c818ece 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Category/ProductTest.php @@ -88,126 +88,126 @@ public function testReindexAll() } } -// /** -// * @magentoAppArea adminhtml -// */ -// public function testCategoryMove() -// { -// $categories = $this->getCategories(4); -// $products = $this->getProducts(2); -// -// /** @var Category $categoryFourth */ -// $categoryFourth = end($categories); -// foreach ($products as $product) { -// /** @var \Magento\Catalog\Model\Product $product */ -// $product->setCategoryIds([$categoryFourth->getId()]); -// $product->save(); -// } -// -// /** @var Category $categorySecond */ -// $categorySecond = $categories[1]; -// $categorySecond->setIsAnchor(true); -// $categorySecond->save(); -// -// /** @var Category $categoryThird */ -// $categoryThird = $categories[2]; -// $categoryThird->setIsAnchor(true); -// $categoryThird->save(); -// -// $this->clearIndex(); -// $this->indexer->reindexAll(); -// -// /** -// * Move $categoryFourth from $categoryThird to $categorySecond -// */ -// $categoryFourth->move($categorySecond->getId(), null); -// -// $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySecond->getId(), $categoryFourth->getId()]; -// -// foreach ($products as $product) { -// /** @var \Magento\Catalog\Model\Product $product */ -// foreach ($categories as $categoryId) { -// $this->assertTrue((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); -// } -// -// $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryThird->getId())); -// } -// } -// -// /** -// * @magentoAppArea adminhtml -// * @depends testReindexAll -// */ -// public function testCategoryDelete() -// { -// $categories = $this->getCategories(4); -// $products = $this->getProducts(2); -// -// /** @var Category $categoryFourth */ -// $categoryFourth = end($categories); -// $categoryFourth->delete(); -// -// /** @var Category $categorySecond */ -// $categorySecond = $categories[1]; -// -// $categories = [$categorySecond->getId(), $categoryFourth->getId()]; -// -// foreach ($products as $product) { -// /** @var \Magento\Catalog\Model\Product $product */ -// foreach ($categories as $categoryId) { -// $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); -// } -// $this->assertTrue( -// (bool)$this->productResource->canBeShowInCategory($product, self::DEFAULT_ROOT_CATEGORY) -// ); -// } -// } -// -// public function testCategoryCreate() -// { -// $this->testReindexAll(); -// $categories = $this->getCategories(4); -// $products = $this->getProducts(3); -// -// /** @var Category $categorySecond */ -// $categorySecond = $categories[1]; -// $categorySecond->setIsAnchor(0); -// $categorySecond->save(); -// -// /** @var Category $categoryFourth */ -// $categoryFourth = end($categories); -// -// /** @var Category $categorySixth */ -// $categorySixth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( -// \Magento\Catalog\Model\Category::class -// ); -// $categorySixth->setName( -// 'Category 6' -// )->setPath( -// $categoryFourth->getPath() -// )->setAvailableSortBy( -// 'name' -// )->setDefaultSortBy( -// 'name' -// )->setIsActive( -// true -// )->save(); -// -// /** @var \Magento\Catalog\Model\Product $productThird */ -// $productThird = end($products); -// $productThird->setCategoryIds([$categorySixth->getId()]); -// $productThird->save(); -// -// $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySixth->getId(), $categoryFourth->getId()]; -// foreach ($categories as $categoryId) { -// $this->assertTrue((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); -// } -// -// $categories = [$categorySecond->getId()]; -// foreach ($categories as $categoryId) { -// $this->assertFalse((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); -// } -// } + /** + * @magentoAppArea adminhtml + */ + public function testCategoryMove() + { + $categories = $this->getCategories(4); + $products = $this->getProducts(2); + + /** @var Category $categoryFourth */ + $categoryFourth = end($categories); + foreach ($products as $product) { + /** @var \Magento\Catalog\Model\Product $product */ + $product->setCategoryIds([$categoryFourth->getId()]); + $product->save(); + } + + /** @var Category $categorySecond */ + $categorySecond = $categories[1]; + $categorySecond->setIsAnchor(true); + $categorySecond->save(); + + /** @var Category $categoryThird */ + $categoryThird = $categories[2]; + $categoryThird->setIsAnchor(true); + $categoryThird->save(); + + $this->clearIndex(); + $this->indexer->reindexAll(); + + /** + * Move $categoryFourth from $categoryThird to $categorySecond + */ + $categoryFourth->move($categorySecond->getId(), null); + + $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySecond->getId(), $categoryFourth->getId()]; + + foreach ($products as $product) { + /** @var \Magento\Catalog\Model\Product $product */ + foreach ($categories as $categoryId) { + $this->assertTrue((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); + } + + $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryThird->getId())); + } + } + + /** + * @magentoAppArea adminhtml + * @depends testReindexAll + */ + public function testCategoryDelete() + { + $categories = $this->getCategories(4); + $products = $this->getProducts(2); + + /** @var Category $categoryFourth */ + $categoryFourth = end($categories); + $categoryFourth->delete(); + + /** @var Category $categorySecond */ + $categorySecond = $categories[1]; + + $categories = [$categorySecond->getId(), $categoryFourth->getId()]; + + foreach ($products as $product) { + /** @var \Magento\Catalog\Model\Product $product */ + foreach ($categories as $categoryId) { + $this->assertFalse((bool)$this->productResource->canBeShowInCategory($product, $categoryId)); + } + $this->assertTrue( + (bool)$this->productResource->canBeShowInCategory($product, self::DEFAULT_ROOT_CATEGORY) + ); + } + } + + public function testCategoryCreate() + { + $this->testReindexAll(); + $categories = $this->getCategories(4); + $products = $this->getProducts(3); + + /** @var Category $categorySecond */ + $categorySecond = $categories[1]; + $categorySecond->setIsAnchor(0); + $categorySecond->save(); + + /** @var Category $categoryFourth */ + $categoryFourth = end($categories); + + /** @var Category $categorySixth */ + $categorySixth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Catalog\Model\Category::class + ); + $categorySixth->setName( + 'Category 6' + )->setPath( + $categoryFourth->getPath() + )->setAvailableSortBy( + 'name' + )->setDefaultSortBy( + 'name' + )->setIsActive( + true + )->save(); + + /** @var \Magento\Catalog\Model\Product $productThird */ + $productThird = end($products); + $productThird->setCategoryIds([$categorySixth->getId()]); + $productThird->save(); + + $categories = [self::DEFAULT_ROOT_CATEGORY, $categorySixth->getId(), $categoryFourth->getId()]; + foreach ($categories as $categoryId) { + $this->assertTrue((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); + } + + $categories = [$categorySecond->getId()]; + foreach ($categories as $categoryId) { + $this->assertFalse((bool)$this->productResource->canBeShowInCategory($productThird, $categoryId)); + } + } /** * @magentoAppArea adminhtml From ffa75c9864f56b88e8f9067efab2404603c81aa8 Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Wed, 6 Jun 2018 16:53:59 -0500 Subject: [PATCH 3/4] MAGETWO-91437: Fix unit and static failures --- .../Test/Unit/Model/ResourceModel/CategoryTest.php | 10 ++++++++++ .../Indexer/Fulltext/Model/Plugin/CategoryTest.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/CategoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/CategoryTest.php index 4812751792f1..b7d05fd2b70e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/CategoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/CategoryTest.php @@ -7,6 +7,7 @@ namespace Magento\Catalog\Test\Unit\Model\ResourceModel; use Magento\Catalog\Model\Factory; +use Magento\Catalog\Model\Indexer\Category\Product\Processor; use Magento\Catalog\Model\ResourceModel\Category; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; use Magento\Eav\Model\Config; @@ -91,6 +92,11 @@ class CategoryTest extends \PHPUnit\Framework\TestCase */ private $serializerMock; + /** + * @var Processor|\PHPUnit_Framework_MockObject_MockObject + */ + private $indexerProcessorMock; + /** * {@inheritDoc} */ @@ -121,6 +127,9 @@ protected function setUp() $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class) ->disableOriginalConstructor() ->getMock(); + $this->indexerProcessorMock = $this->getMockBuilder(Processor::class) + ->disableOriginalConstructor() + ->getMock(); $this->serializerMock = $this->getMockBuilder(Json::class)->getMock(); @@ -131,6 +140,7 @@ protected function setUp() $this->managerMock, $this->treeFactoryMock, $this->collectionFactoryMock, + $this->indexerProcessorMock, [], $this->serializerMock ); diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php index 4795a43bfc77..ec2a14abafc1 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace integration\testsuite\Magento\CatalogSearch\Model\Indexer\Fulltext\Model\Plugin; +namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Model\Plugin; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Model\Category; From f64e7fabb151fc5947633bf869a2623b40757055 Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 7 Jun 2018 11:09:08 -0500 Subject: [PATCH 4/4] MAGETWO-91437: Formatting change --- app/code/Magento/Catalog/Model/ResourceModel/Category.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index 4b050e00c1b1..fa68ae3f865e 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -219,7 +219,6 @@ protected function _afterDelete(DataObject $object) return parent::_afterDelete($object); } - /** * Delete children categories of specific category *