|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
6 | 9 | namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;
|
7 | 10 |
|
| 11 | +use Magento\Catalog\Api\ProductRepositoryInterface; |
| 12 | +use Magento\Catalog\Block\Product\ListProduct; |
| 13 | +use Magento\Catalog\Model\Indexer\Product\Flat\Processor; |
| 14 | +use Magento\Catalog\Model\Product; |
| 15 | +use Magento\Catalog\Model\Product\Attribute\Source\Status; |
| 16 | +use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; |
| 17 | +use Magento\Catalog\Api\CategoryRepositoryInterface; |
| 18 | +use Magento\Framework\View\LayoutInterface; |
| 19 | +use Magento\TestFramework\Helper\Bootstrap; |
| 20 | +use Magento\TestFramework\Indexer\TestCase; |
| 21 | + |
8 | 22 | /**
|
9 |
| - * Class RowsTest |
| 23 | + * Test for \Magento\Catalog\Model\Indexer\Product\Flat\Action\Rows. |
10 | 24 | */
|
11 |
| -class RowsTest extends \Magento\TestFramework\Indexer\TestCase |
| 25 | +class RowsTest extends TestCase |
12 | 26 | {
|
13 | 27 | /**
|
14 |
| - * @var \Magento\Catalog\Model\Product |
| 28 | + * @var Processor |
15 | 29 | */
|
16 |
| - protected $_product; |
| 30 | + private $processor; |
17 | 31 |
|
18 | 32 | /**
|
19 |
| - * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor |
| 33 | + * @var ProductRepositoryInterface |
20 | 34 | */
|
21 |
| - protected $_processor; |
| 35 | + private $productRepository; |
22 | 36 |
|
| 37 | + /** |
| 38 | + * @var CategoryRepositoryInterface |
| 39 | + */ |
| 40 | + private $categoryRepository; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var CollectionFactory |
| 44 | + */ |
| 45 | + private $productCollectionFactory; |
| 46 | + |
| 47 | + /** |
| 48 | + * @var LayoutInterface |
| 49 | + */ |
| 50 | + private $layout; |
| 51 | + |
| 52 | + /** |
| 53 | + * @inheritdoc |
| 54 | + */ |
23 | 55 | protected function setUp()
|
24 | 56 | {
|
25 |
| - $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
26 |
| - \Magento\Catalog\Model\Product::class |
27 |
| - ); |
28 |
| - $this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( |
29 |
| - \Magento\Catalog\Model\Indexer\Product\Flat\Processor::class |
30 |
| - ); |
| 57 | + $objectManager = Bootstrap::getObjectManager(); |
| 58 | + $this->processor = $objectManager->get(Processor::class); |
| 59 | + $this->productRepository = $objectManager->get(ProductRepositoryInterface::class); |
| 60 | + $this->categoryRepository = $objectManager->get(CategoryRepositoryInterface::class); |
| 61 | + $this->productCollectionFactory = $objectManager->get(CollectionFactory::class); |
| 62 | + $this->layout = $objectManager->get(LayoutInterface::class); |
31 | 63 | }
|
32 | 64 |
|
33 | 65 | /**
|
| 66 | + * Test update category products |
| 67 | + * |
34 | 68 | * @magentoDbIsolation disabled
|
35 | 69 | * @magentoAppIsolation enabled
|
36 | 70 | * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
|
37 | 71 | * @magentoDataFixture Magento/Catalog/_files/product_simple.php
|
| 72 | + * |
| 73 | + * @return void |
38 | 74 | */
|
39 |
| - public function testProductsUpdate() |
| 75 | + public function testProductsUpdate(): void |
40 | 76 | {
|
41 |
| - $this->_product->load(1); |
42 |
| - |
43 |
| - $this->_processor->reindexList([$this->_product->getId()]); |
44 |
| - |
45 |
| - $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( |
46 |
| - \Magento\Catalog\Model\CategoryFactory::class |
47 |
| - ); |
48 |
| - $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( |
49 |
| - \Magento\Catalog\Block\Product\ListProduct::class |
50 |
| - ); |
| 77 | + $product = $this->productRepository->getById(1); |
| 78 | + $this->processor->reindexList([$product->getId()]); |
51 | 79 |
|
52 |
| - $category = $categoryFactory->create()->load(2); |
| 80 | + $category = $this->categoryRepository->get(2); |
| 81 | + $listProduct = $this->layout->createBlock(ListProduct::class); |
53 | 82 | $layer = $listProduct->getLayer();
|
54 | 83 | $layer->setCurrentCategory($category);
|
55 | 84 | $productCollection = $layer->getProductCollection();
|
56 | 85 |
|
57 | 86 | $this->assertCount(1, $productCollection);
|
58 | 87 |
|
59 |
| - /** @var $product \Magento\Catalog\Model\Product */ |
60 |
| - foreach ($productCollection as $product) { |
61 |
| - $this->assertEquals($this->_product->getName(), $product->getName()); |
62 |
| - $this->assertEquals($this->_product->getShortDescription(), $product->getShortDescription()); |
| 88 | + /** @var $productItem Product */ |
| 89 | + foreach ($productCollection as $productItem) { |
| 90 | + $this->assertEquals($product->getName(), $productItem->getName()); |
| 91 | + $this->assertEquals($product->getShortDescription(), $productItem->getShortDescription()); |
63 | 92 | }
|
64 | 93 | }
|
| 94 | + |
| 95 | + /** |
| 96 | + * Products update with different statuses |
| 97 | + * |
| 98 | + * @magentoDbIsolation disabled |
| 99 | + * @magentoAppArea frontend |
| 100 | + * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1 |
| 101 | + * @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_attribute_in_flat.php |
| 102 | + * @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php |
| 103 | + * |
| 104 | + * @return void |
| 105 | + */ |
| 106 | + public function testProductsDifferentStatusesUpdate(): void |
| 107 | + { |
| 108 | + $firstProduct = $this->productRepository->get('simple_with_custom_flat_attribute'); |
| 109 | + $secondProduct = $this->productRepository->get('simple-1'); |
| 110 | + |
| 111 | + $this->processor->getIndexer()->setScheduled(true); |
| 112 | + $this->productRepository->save($secondProduct->setStatus(Status::STATUS_DISABLED)); |
| 113 | + $this->processor->reindexList([$firstProduct->getId(), $secondProduct->getId()], true); |
| 114 | + $collection = $this->productCollectionFactory->create(); |
| 115 | + |
| 116 | + $this->assertCount(1, $collection); |
| 117 | + $this->assertEquals($firstProduct->getId(), $collection->getFirstItem()->getId()); |
| 118 | + } |
65 | 119 | }
|
0 commit comments