|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Action; |
| 9 | + |
| 10 | +use Magento\Framework\Exception\InputException; |
| 11 | +use Magento\Framework\Exception\LocalizedException; |
| 12 | +use Magento\Framework\Search\Request\Dimension; |
| 13 | +use Magento\Store\Model\StoreManagerInterface; |
| 14 | +use Magento\Directory\Model\CurrencyFactory; |
| 15 | +use Magento\Catalog\Model\Product\Type; |
| 16 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory; |
| 17 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice; |
| 18 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\TierPrice; |
| 19 | +use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory; |
| 20 | +use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer; |
| 21 | +use Magento\Catalog\Model\Indexer\Product\Price\Action\Row; |
| 22 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 23 | +use Magento\Framework\Stdlib\DateTime; |
| 24 | +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; |
| 25 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 26 | +use Magento\Framework\DB\Select; |
| 27 | +use Magento\Framework\Indexer\MultiDimensionProvider; |
| 28 | +use PHPUnit\Framework\TestCase; |
| 29 | +use PHPUnit\Framework\MockObject\MockObject; |
| 30 | + |
| 31 | +/** |
| 32 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 33 | + */ |
| 34 | +class RowDefaultPriceIndexerTest extends TestCase |
| 35 | +{ |
| 36 | + /** |
| 37 | + * @var Row |
| 38 | + */ |
| 39 | + private $actionRow; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var ScopeConfigInterface|MockObject |
| 43 | + */ |
| 44 | + private $config; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var StoreManagerInterface|MockObject |
| 48 | + */ |
| 49 | + private $storeManager; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var CurrencyFactory|MockObject |
| 53 | + */ |
| 54 | + private $currencyFactory; |
| 55 | + |
| 56 | + /** |
| 57 | + * @var TimezoneInterface|MockObject |
| 58 | + */ |
| 59 | + private $localeDate; |
| 60 | + |
| 61 | + /** |
| 62 | + * @var DateTime|MockObject |
| 63 | + */ |
| 64 | + private $dateTime; |
| 65 | + |
| 66 | + /** |
| 67 | + * @var Type|MockObject |
| 68 | + */ |
| 69 | + private $catalogProductType; |
| 70 | + |
| 71 | + /** |
| 72 | + * @var Factory|MockObject |
| 73 | + */ |
| 74 | + private $indexerPriceFactory; |
| 75 | + |
| 76 | + /** |
| 77 | + * @var DefaultPrice|MockObject |
| 78 | + */ |
| 79 | + private $defaultIndexerResource; |
| 80 | + |
| 81 | + /** |
| 82 | + * @var TierPrice|MockObject |
| 83 | + */ |
| 84 | + private $tierPriceIndexResource; |
| 85 | + |
| 86 | + /** |
| 87 | + * @var DimensionCollectionFactory|MockObject |
| 88 | + */ |
| 89 | + private $dimensionCollectionFactory; |
| 90 | + |
| 91 | + /** |
| 92 | + * @var TableMaintainer|MockObject |
| 93 | + */ |
| 94 | + private $tableMaintainer; |
| 95 | + |
| 96 | + protected function setUp(): void |
| 97 | + { |
| 98 | + $this->config = $this->createMock(ScopeConfigInterface::class); |
| 99 | + $this->storeManager = $this->createMock(StoreManagerInterface::class); |
| 100 | + $this->currencyFactory = $this->createMock(CurrencyFactory::class); |
| 101 | + $this->localeDate = $this->createMock(TimezoneInterface::class); |
| 102 | + $this->dateTime = $this->createMock(DateTime::class); |
| 103 | + $this->catalogProductType = $this->createMock(Type::class); |
| 104 | + $this->indexerPriceFactory = $this->createMock(Factory::class); |
| 105 | + $this->defaultIndexerResource = $this->createMock(DefaultPrice::class); |
| 106 | + $this->tierPriceIndexResource = $this->createMock(TierPrice::class); |
| 107 | + $this->dimensionCollectionFactory = $this->createMock(DimensionCollectionFactory::class); |
| 108 | + $this->tableMaintainer = $this->createMock(TableMaintainer::class); |
| 109 | + |
| 110 | + $this->actionRow = new Row( |
| 111 | + $this->config, |
| 112 | + $this->storeManager, |
| 113 | + $this->currencyFactory, |
| 114 | + $this->localeDate, |
| 115 | + $this->dateTime, |
| 116 | + $this->catalogProductType, |
| 117 | + $this->indexerPriceFactory, |
| 118 | + $this->defaultIndexerResource, |
| 119 | + $this->tierPriceIndexResource, |
| 120 | + $this->dimensionCollectionFactory, |
| 121 | + $this->tableMaintainer |
| 122 | + ); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Test that the price indexer will be able to perform the indexation with DefaultPrice indexer |
| 127 | + * |
| 128 | + * @return void |
| 129 | + * @throws InputException |
| 130 | + * @throws LocalizedException |
| 131 | + */ |
| 132 | + public function testRowDefaultPriceIndexer() |
| 133 | + { |
| 134 | + $select = $this->createMock(Select::class); |
| 135 | + $select->method('from')->willReturnSelf(); |
| 136 | + $select->method('joinLeft')->willReturnSelf(); |
| 137 | + $select->method('where')->willReturnSelf(); |
| 138 | + $select->method('join')->willReturnSelf(); |
| 139 | + |
| 140 | + $adapter = $this->createMock(AdapterInterface::class); |
| 141 | + $adapter->method('select')->willReturn($select); |
| 142 | + $adapter->method('describeTable')->willReturn([]); |
| 143 | + |
| 144 | + $adapter->expects($this->exactly(1)) |
| 145 | + ->method('describeTable'); |
| 146 | + |
| 147 | + $this->tableMaintainer->expects($this->exactly(3))->method('getMainTableByDimensions'); |
| 148 | + |
| 149 | + $this->defaultIndexerResource->method('getConnection')->willReturn($adapter); |
| 150 | + $adapter->method('fetchAll')->with($select)->willReturn([]); |
| 151 | + |
| 152 | + $adapter->expects($this->any()) |
| 153 | + ->method('fetchPairs') |
| 154 | + ->with($select) |
| 155 | + ->willReturn( |
| 156 | + [1 => 'simple'], |
| 157 | + [] |
| 158 | + ); |
| 159 | + |
| 160 | + $multiDimensionProvider = $this->createMock(MultiDimensionProvider::class); |
| 161 | + $this->dimensionCollectionFactory->expects($this->exactly(2)) |
| 162 | + ->method('create') |
| 163 | + ->willReturn($multiDimensionProvider); |
| 164 | + $dimension = $this->createMock(Dimension::class); |
| 165 | + $dimension->method('getName')->willReturn('default'); |
| 166 | + $dimension->method('getValue')->willReturn('0'); |
| 167 | + $iterator = new \ArrayIterator([[$dimension]]); |
| 168 | + $multiDimensionProvider->expects($this->exactly(2)) |
| 169 | + ->method('getIterator') |
| 170 | + ->willReturn($iterator); |
| 171 | + $this->catalogProductType->expects($this->once()) |
| 172 | + ->method('getTypesByPriority') |
| 173 | + ->willReturn( |
| 174 | + [ |
| 175 | + 'simple' => ['price_indexer' => '\Price\Indexer'] |
| 176 | + ] |
| 177 | + ); |
| 178 | + $this->indexerPriceFactory->expects($this->exactly(1)) |
| 179 | + ->method('create') |
| 180 | + ->with('\Price\Indexer', ['fullReindexAction' => false]) |
| 181 | + ->willReturn($this->defaultIndexerResource); |
| 182 | + $this->defaultIndexerResource->expects($this->exactly(1)) |
| 183 | + ->method('reindexEntity'); |
| 184 | + $this->defaultIndexerResource->expects($this->any())->method('setTypeId')->willReturnSelf(); |
| 185 | + $this->defaultIndexerResource->expects($this->any())->method('setIsComposite'); |
| 186 | + $select->expects($this->exactly(1)) |
| 187 | + ->method('deleteFromSelect') |
| 188 | + ->with('index_price') |
| 189 | + ->willReturn(''); |
| 190 | + $adapter->expects($this->exactly(2)) |
| 191 | + ->method('getIndexList') |
| 192 | + ->willReturn(['entity_id'=>['COLUMNS_LIST'=>['test']]]); |
| 193 | + $adapter->expects($this->exactly(2)) |
| 194 | + ->method('getPrimaryKeyName') |
| 195 | + ->willReturn('entity_id'); |
| 196 | + |
| 197 | + $this->actionRow->execute(1); |
| 198 | + } |
| 199 | +} |
0 commit comments