|
11 | 11 | use Magento\Framework\App\ResourceConnection;
|
12 | 12 | use Magento\Framework\DB\Adapter\AdapterInterface;
|
13 | 13 | use Magento\Store\Model\StoreManagerInterface;
|
14 |
| -use Magento\TestFramework\Catalog\Model\Indexer\Product\Flat\Action\Full as FlatIndexerFull; |
| 14 | +use Magento\Catalog\Model\Indexer\Product\Flat\Action\Full as FlatIndexerFull; |
| 15 | +use Magento\Catalog\Helper\Product\Flat\Indexer; |
| 16 | +use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder; |
| 17 | +use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder; |
| 18 | +use Magento\Framework\Exception\LocalizedException; |
| 19 | +use Magento\TestFramework\Helper\Bootstrap; |
15 | 20 |
|
16 | 21 | /**
|
17 | 22 | * Test relation customization
|
@@ -42,33 +47,79 @@ class RelationTest extends \Magento\TestFramework\Indexer\TestCase
|
42 | 47 | */
|
43 | 48 | private $flatUpdated = [];
|
44 | 49 |
|
| 50 | + /** |
| 51 | + * @var Indexer |
| 52 | + */ |
| 53 | + private $productIndexerHelper; |
| 54 | + |
45 | 55 | /**
|
46 | 56 | * @inheritdoc
|
47 | 57 | */
|
48 | 58 | protected function setUp(): void
|
49 | 59 | {
|
50 |
| - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 60 | + $objectManager = Bootstrap::getObjectManager(); |
51 | 61 |
|
52 |
| - $tableBuilderMock = $this->createMock(\Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder::class); |
53 |
| - $flatTableBuilderMock = $this->createMock(\Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder::class); |
| 62 | + $tableBuilderMock = $objectManager->get(TableBuilder::class); |
| 63 | + $flatTableBuilderMock = |
| 64 | + $objectManager->get(FlatTableBuilder::class); |
54 | 65 |
|
55 |
| - $productIndexerHelper = $objectManager->create( |
56 |
| - \Magento\Catalog\Helper\Product\Flat\Indexer::class, |
57 |
| - ['addChildData' => 1] |
| 66 | + $this->productIndexerHelper = $objectManager->create( |
| 67 | + Indexer::class, |
| 68 | + ['addChildData' => true] |
58 | 69 | );
|
59 | 70 | $this->indexer = $objectManager->create(
|
60 | 71 | FlatIndexerFull::class,
|
61 | 72 | [
|
62 |
| - 'productHelper' => $productIndexerHelper, |
| 73 | + 'productHelper' => $this->productIndexerHelper, |
63 | 74 | 'tableBuilder' => $tableBuilderMock,
|
64 | 75 | 'flatTableBuilder' => $flatTableBuilderMock
|
65 | 76 | ]
|
66 | 77 | );
|
67 |
| - $this->storeManager = $objectManager->create(StoreManagerInterface::class); |
| 78 | + $this->storeManager = $objectManager->get(StoreManagerInterface::class); |
68 | 79 | $this->connection = $objectManager->get(ResourceConnection::class)->getConnection();
|
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @inheritdoc |
| 84 | + */ |
| 85 | + protected function tearDown(): void |
| 86 | + { |
| 87 | + foreach ($this->flatUpdated as $flatTable) { |
| 88 | + $this->connection->dropColumn($flatTable, 'child_id'); |
| 89 | + $this->connection->dropColumn($flatTable, 'is_child'); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Test that SQL generated for relation customization is valid |
| 95 | + * |
| 96 | + * @return void |
| 97 | + * @throws LocalizedException |
| 98 | + * @throws \Exception |
| 99 | + */ |
| 100 | + public function testExecute() : void |
| 101 | + { |
| 102 | + $this->addChildColumns(); |
| 103 | + try { |
| 104 | + $result = $this->indexer->execute(); |
| 105 | + } catch (LocalizedException $e) { |
| 106 | + if ($e->getPrevious() instanceof \Zend_Db_Statement_Exception) { |
| 107 | + $this->fail($e->getMessage()); |
| 108 | + } |
| 109 | + throw $e; |
| 110 | + } |
| 111 | + $this->assertInstanceOf(FlatIndexerFull::class, $result); |
| 112 | + } |
69 | 113 |
|
| 114 | + /** |
| 115 | + * Add child columns to tables if needed |
| 116 | + * |
| 117 | + * @return void |
| 118 | + */ |
| 119 | + private function addChildColumns(): void |
| 120 | + { |
70 | 121 | foreach ($this->storeManager->getStores() as $store) {
|
71 |
| - $flatTable = $productIndexerHelper->getFlatTableName($store->getId()); |
| 122 | + $flatTable = $this->productIndexerHelper->getFlatTableName($store->getId()); |
72 | 123 | if ($this->connection->isTableExists($flatTable) &&
|
73 | 124 | !$this->connection->tableColumnExists($flatTable, 'child_id') &&
|
74 | 125 | !$this->connection->tableColumnExists($flatTable, 'is_child')
|
@@ -103,35 +154,4 @@ protected function setUp(): void
|
103 | 154 | }
|
104 | 155 | }
|
105 | 156 | }
|
106 |
| - |
107 |
| - /** |
108 |
| - * @inheritdoc |
109 |
| - */ |
110 |
| - protected function tearDown(): void |
111 |
| - { |
112 |
| - foreach ($this->flatUpdated as $flatTable) { |
113 |
| - $this->connection->dropColumn($flatTable, 'child_id'); |
114 |
| - $this->connection->dropColumn($flatTable, 'is_child'); |
115 |
| - } |
116 |
| - } |
117 |
| - |
118 |
| - /** |
119 |
| - * Test that SQL generated for relation customization is valid |
120 |
| - * |
121 |
| - * @return void |
122 |
| - * @throws \Magento\Framework\Exception\LocalizedException |
123 |
| - * @throws \Exception |
124 |
| - */ |
125 |
| - public function testExecute() : void |
126 |
| - { |
127 |
| - $this->markTestSkipped('MC-19675'); |
128 |
| - try { |
129 |
| - $this->indexer->execute(); |
130 |
| - } catch (\Magento\Framework\Exception\LocalizedException $e) { |
131 |
| - if ($e->getPrevious() instanceof \Zend_Db_Statement_Exception) { |
132 |
| - $this->fail($e->getMessage()); |
133 |
| - } |
134 |
| - throw $e; |
135 |
| - } |
136 |
| - } |
137 | 157 | }
|
0 commit comments