diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php index a8901e896ad32..e829801d60e1a 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/CategoryRepositoryTest.php @@ -9,15 +9,10 @@ use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Api\Data\CategoryInterface; -use Magento\Catalog\Model\Category\Attribute\LayoutUpdateManager; -use Magento\Catalog\Model\Indexer\Category\Product\Processor; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; use Magento\Cms\Api\GetBlockByIdentifierInterface; use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Indexer\IndexerRegistry; -use Magento\Framework\Indexer\StateInterface; -use Magento\Framework\Indexer\StateInterfaceFactory; use Magento\Framework\ObjectManagerInterface; use Magento\Store\Api\StoreManagementInterface; use Magento\Store\Model\StoreManagerInterface; @@ -33,46 +28,27 @@ */ class CategoryRepositoryTest extends TestCase { - /** - * @var ObjectManagerInterface - */ + /** @var ObjectManagerInterface */ private $objectManager; - /** - * @var CategoryLayoutUpdateManager - */ + /** @var CategoryLayoutUpdateManager */ private $layoutManager; - /** - * @var CategoryRepositoryInterface - */ + /** @var CategoryRepositoryInterface */ private $categoryRepository; - /** - * @var CollectionFactory - */ + /** @var CollectionFactory */ private $productCollectionFactory; - /** - * @var CategoryCollectionFactory - */ + /** @var CategoryCollectionFactory */ private $categoryCollectionFactory; - /** - * @var StoreManagementInterface - */ + /** @var StoreManagementInterface */ private $storeManager; - /** - * @var GetBlockByIdentifierInterface - */ + /** @var GetBlockByIdentifierInterface */ private $getBlockByIdentifier; - /** - * @var IndexerRegistry - */ - private $indexerRegistry; - /** * @inheritdoc */ @@ -80,7 +56,10 @@ protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->objectManager->configure([ - 'preferences' => [LayoutUpdateManager::class => CategoryLayoutUpdateManager::class] + 'preferences' => [ + \Magento\Catalog\Model\Category\Attribute\LayoutUpdateManager::class + => \Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager::class + ] ]); $this->layoutManager = $this->objectManager->get(CategoryLayoutUpdateManager::class); $this->productCollectionFactory = $this->objectManager->get(CollectionFactory::class); @@ -88,7 +67,6 @@ protected function setUp(): void $this->categoryRepository = $this->objectManager->get(CategoryRepositoryInterface::class); $this->storeManager = $this->objectManager->get(StoreManagerInterface::class); $this->getBlockByIdentifier = $this->objectManager->get(GetBlockByIdentifierInterface::class); - $this->indexerRegistry = $this->objectManager->get(IndexerRegistry::class); } /** @@ -226,51 +204,4 @@ private function assertCategoryData(array $expectedData, CategoryInterface $cate $this->assertEquals($value, $category->getData($key)); } } - - /** - * Verify that indexer still valid after deleting inactive category - * - * @magentoAppArea adminhtml - * @magentoDataFixture Magento/Catalog/_files/categories_disabled.php - * @magentoDbIsolation disabled - * - * @return void - */ - public function testDeleteInactiveCategory(): void - { - $indexerProcessor = $this->indexerRegistry->get(Processor::INDEXER_ID); - $indexerProcessor->reindexAll(); - $indexerProcessor->setScheduled(true); - - /** @var CategoryRepositoryInterface $categoryRepository */ - $categoryRepository = $this->objectManager->get(CategoryRepositoryInterface::class); - $category = $categoryRepository->get(4); - $categoryRepository->delete($category); - - $state = $this->getIndexerState(Processor::INDEXER_ID); - $this->assertEquals(StateInterface::STATUS_VALID, $state->getStatus()); - } - - /** - * Get Indexer state - * - * @param string $indexerId - * @return StateInterface - */ - private function getIndexerState(string $indexerId): StateInterface - { - $state = $this->objectManager->get(StateInterfaceFactory::class) - ->create(); - - return $state->loadByIndexer($indexerId); - } - - /** - * Return indexer to previous state - */ - protected function tearDown(): void - { - $indexerProcessor = $this->indexerRegistry->get(Processor::INDEXER_ID); - $indexerProcessor->setScheduled(false); - } } 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 5cfa07cf5d402..4a431dd368c69 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 @@ -184,7 +184,36 @@ public function testCategoryDelete() } } - public function testCategoryCreate() + + /** + * Verify that indexer still valid after deleting inactive category + * + * @magentoAppArea adminhtml + * @magentoDataFixture Magento/Catalog/_files/categories_disabled.php + * + * @return void + */ + public function testDeleteInactiveCategory(): void + { + $this->indexer->reindexAll(); + $indexerShouldBeValid = $this->indexer->isInvalid(); + + $this->categoryRepository->deleteByIdentifier(4); + + $state = $this->indexer->getState(); + $state->loadByIndexer($this->indexer->getId()); + $status = $state->getStatus(); + + $this->assertFalse($indexerShouldBeValid); + $this->assertEquals(StateInterface::STATUS_VALID, $status); + } + + /** + * Create category + * + * @return void + */ + public function testCategoryCreate(): void { $this->testReindexAll(); $categories = $this->getCategories(4); 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 b3a8a067d877b..85916cd172cda 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 @@ -9,10 +9,16 @@ use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Model\Category; +use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor; +use Magento\Framework\Indexer\StateInterface; use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; -class CategoryTest extends \PHPUnit\Framework\TestCase +/** + * Test for category repository plugin + */ +class CategoryTest extends TestCase { /** * @var Processor @@ -24,10 +30,19 @@ class CategoryTest extends \PHPUnit\Framework\TestCase */ private $categoryRepository; + /** + * @var CategoryCollectionFactory + */ + private $categoryCollectionFactory; + + /** + * @inheritDoc + */ protected function setUp(): void { $this->indexerProcessor = Bootstrap::getObjectManager()->create(Processor::class); $this->categoryRepository = Bootstrap::getObjectManager()->create(CategoryRepositoryInterface::class); + $this->categoryCollectionFactory = Bootstrap::getObjectManager()->create(CategoryCollectionFactory::class); } /** @@ -47,22 +62,22 @@ public function testIndexerInvalidatedAfterCategoryDelete() $status = $state->getStatus(); $this->assertTrue($isIndexerValid); - $this->assertEquals(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID, $status); + $this->assertEquals(StateInterface::STATUS_INVALID, $status); } /** + * Returns categories + * * @param int $count * @return Category[] */ - private function getCategories($count) + private function getCategories(int $count): array { - /** @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); + $collection = $this->categoryCollectionFactory->create() + ->addAttributeToSelect('name') + ->addAttributeToSelect('is_active') + ->getItems(); + $result = array_slice($collection, 2); return array_slice($result, 0, $count); }