|
5 | 5 | */
|
6 | 6 | namespace Magento\CatalogImportExport\Test\Unit\Model\Indexer\Product\Flat\Plugin;
|
7 | 7 |
|
| 8 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 9 | + |
8 | 10 | class ImportTest extends \PHPUnit_Framework_TestCase
|
9 | 11 | {
|
10 |
| - public function testAfterImportSource() |
| 12 | + /** |
| 13 | + * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor|\PHPUnit_Framework_MockObject_MockObject |
| 14 | + */ |
| 15 | + private $processorMock; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import |
| 19 | + */ |
| 20 | + private $model; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Catalog\Model\Indexer\Product\Flat\State|\PHPUnit_Framework_MockObject_MockObject |
| 24 | + */ |
| 25 | + private $flatStateMock; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var \Magento\ImportExport\Model\Import|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + private $subjectMock; |
| 31 | + |
| 32 | + protected function setUp() |
11 | 33 | {
|
12 |
| - /** |
13 |
| - * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor| |
14 |
| - * \PHPUnit_Framework_MockObject_MockObject $processorMock |
15 |
| - */ |
16 |
| - $processorMock = $this->getMock( |
| 34 | + $this->processorMock = $this->getMock( |
17 | 35 | 'Magento\Catalog\Model\Indexer\Product\Flat\Processor',
|
18 |
| - ['markIndexerAsInvalid'], |
| 36 | + ['markIndexerAsInvalid', 'isIndexerScheduled'], |
| 37 | + [], |
| 38 | + '', |
| 39 | + false |
| 40 | + ); |
| 41 | + |
| 42 | + $this->flatStateMock = $this->getMock( |
| 43 | + '\Magento\Catalog\Model\Indexer\Product\Flat\State', |
| 44 | + ['isFlatEnabled'], |
| 45 | + [], |
| 46 | + '', |
| 47 | + false |
| 48 | + ); |
| 49 | + |
| 50 | + $this->subjectMock = $this->getMock( |
| 51 | + 'Magento\ImportExport\Model\Import', |
| 52 | + [], |
19 | 53 | [],
|
20 | 54 | '',
|
21 | 55 | false
|
22 | 56 | );
|
23 | 57 |
|
24 |
| - $subjectMock = $this->getMock('Magento\ImportExport\Model\Import', [], [], '', false); |
25 |
| - $processorMock->expects($this->once())->method('markIndexerAsInvalid'); |
| 58 | + $this->model = (new ObjectManager($this))->getObject( |
| 59 | + 'Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import', |
| 60 | + [ |
| 61 | + 'productFlatIndexerProcessor' => $this->processorMock, |
| 62 | + 'flatState' => $this->flatStateMock |
| 63 | + ] |
| 64 | + ); |
| 65 | + } |
26 | 66 |
|
| 67 | + public function testAfterImportSourceWithFlatEnabledAndIndexerScheduledDisabled() |
| 68 | + { |
| 69 | + $this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true); |
| 70 | + $this->processorMock->expects($this->once())->method('isIndexerScheduled')->willReturn(false); |
| 71 | + $this->processorMock->expects($this->once())->method('markIndexerAsInvalid'); |
27 | 72 | $someData = [1, 2, 3];
|
| 73 | + $this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData)); |
| 74 | + } |
28 | 75 |
|
29 |
| - $model = new \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import($processorMock); |
30 |
| - $this->assertEquals($someData, $model->afterImportSource($subjectMock, $someData)); |
| 76 | + public function testAfterImportSourceWithFlatDisabledAndIndexerScheduledDisabled() |
| 77 | + { |
| 78 | + |
| 79 | + $this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(false); |
| 80 | + $this->processorMock->expects($this->never())->method('isIndexerScheduled')->willReturn(false); |
| 81 | + $this->processorMock->expects($this->never())->method('markIndexerAsInvalid'); |
| 82 | + $someData = [1, 2, 3]; |
| 83 | + $this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData)); |
| 84 | + } |
| 85 | + public function testAfterImportSourceWithFlatEnabledAndIndexerScheduledEnabled() |
| 86 | + { |
| 87 | + $this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true); |
| 88 | + $this->processorMock->expects($this->once())->method('isIndexerScheduled')->willReturn(true); |
| 89 | + $this->processorMock->expects($this->never())->method('markIndexerAsInvalid'); |
| 90 | + $someData = [1, 2, 3]; |
| 91 | + $this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData)); |
31 | 92 | }
|
32 | 93 | }
|
0 commit comments