|
| 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\Category\Product\Plugin; |
| 9 | + |
| 10 | +use Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver; |
| 11 | +use Magento\Framework\App\ResourceConnection; |
| 12 | +use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver; |
| 13 | +use Magento\Store\Model\Store; |
| 14 | +use Magento\Store\Model\StoreManagerInterface; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +class TableResolverTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Tests replacing catalog_category_product_index table name |
| 21 | + * |
| 22 | + * @param int $storeId |
| 23 | + * @param string $tableName |
| 24 | + * @param string $expected |
| 25 | + * @dataProvider afterGetTableNameDataProvider |
| 26 | + */ |
| 27 | + public function testAfterGetTableName(int $storeId, string $tableName, string $expected): void |
| 28 | + { |
| 29 | + $storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class); |
| 30 | + |
| 31 | + $storeMock = $this->getMockBuilder(Store::class) |
| 32 | + ->onlyMethods(['getId']) |
| 33 | + ->disableOriginalConstructor() |
| 34 | + ->getMock(); |
| 35 | + $storeMock->method('getId') |
| 36 | + ->willReturn($storeId); |
| 37 | + |
| 38 | + $storeManagerMock->method('getStore')->willReturn($storeMock); |
| 39 | + |
| 40 | + $tableResolverMock = $this->getMockBuilder(IndexScopeResolver::class) |
| 41 | + ->disableOriginalConstructor() |
| 42 | + ->getMock(); |
| 43 | + $tableResolverMock->method('resolve')->willReturn('catalog_category_product_index_store1'); |
| 44 | + |
| 45 | + $subjectMock = $this->getMockBuilder(ResourceConnection::class) |
| 46 | + ->disableOriginalConstructor() |
| 47 | + ->getMock(); |
| 48 | + |
| 49 | + $model = new TableResolver($storeManagerMock, $tableResolverMock); |
| 50 | + |
| 51 | + $this->assertEquals( |
| 52 | + $expected, |
| 53 | + $model->afterGetTableName($subjectMock, $tableName, 'catalog_category_product_index') |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Data provider for testAfterGetTableName |
| 59 | + * |
| 60 | + * @return array |
| 61 | + */ |
| 62 | + public function afterGetTableNameDataProvider(): array |
| 63 | + { |
| 64 | + return [ |
| 65 | + [ |
| 66 | + 'storeId' => 1, |
| 67 | + 'tableName' => 'catalog_category_product_index', |
| 68 | + 'expected' => 'catalog_category_product_index_store1' |
| 69 | + ], |
| 70 | + [ |
| 71 | + 'storeId' => 0, |
| 72 | + 'tableName' => 'catalog_category_product_index', |
| 73 | + 'expected' => 'catalog_category_product_index' |
| 74 | + ], |
| 75 | + ]; |
| 76 | + } |
| 77 | +} |
0 commit comments