Skip to content

Commit a896122

Browse files
committed
Merge remote-tracking branch 'origin/MC-36830' into 2.4-develop-pr43
2 parents 729080d + 4a59b3e commit a896122

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/TableResolver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public function afterGetTableName(
5555
string $result,
5656
$modelEntity
5757
) {
58-
if (!is_array($modelEntity) && $modelEntity === AbstractAction::MAIN_INDEX_TABLE) {
58+
if (!is_array($modelEntity) &&
59+
$modelEntity === AbstractAction::MAIN_INDEX_TABLE &&
60+
$this->storeManager->getStore()->getId()
61+
) {
5962
$catalogCategoryProductDimension = new Dimension(
6063
\Magento\Store\Model\Store::ENTITY,
6164
$this->storeManager->getStore()->getId()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)