Skip to content

Commit d5feb5a

Browse files
committed
ACP2E-2885: Products graphql returned disabled categories in the category aggregations
1 parent 7fcf9e4 commit d5feb5a

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function reindexRow($id, $forceReindex = false)
3434
return;
3535
}
3636

37-
parent::reindexList($id, $forceReindex);
37+
parent::reindexRow($id, $forceReindex);
3838
}
3939

4040
/**
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Category\Flat;
9+
10+
use Magento\Catalog\Model\Indexer\Category\Flat\Processor;
11+
use Magento\Catalog\Model\Indexer\Category\Flat\State;
12+
use Magento\Framework\Indexer\IndexerInterface;
13+
use Magento\Framework\Indexer\IndexerRegistry;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class ProcessorTest extends TestCase
18+
{
19+
/**
20+
* @var State|MockObject
21+
*/
22+
private $stateMock;
23+
24+
/**
25+
* @var Processor
26+
*/
27+
private $processor;
28+
29+
/**
30+
* @var IndexerInterface|MockObject
31+
*/
32+
private $indexerMock;
33+
34+
protected function setUp(): void
35+
{
36+
$indexerRegistryMock = $this->createMock(IndexerRegistry::class);
37+
$this->stateMock = $this->createMock(State::class);
38+
$this->processor = new Processor($indexerRegistryMock, $this->stateMock);
39+
40+
$this->indexerMock = $this->createMock(IndexerInterface::class);
41+
$indexerRegistryMock->method('get')
42+
->with(State::INDEXER_ID)
43+
->willReturn($this->indexerMock);
44+
$this->indexerMock->method('isScheduled')
45+
->willReturn(false);
46+
}
47+
48+
/**
49+
* @dataProvider stateDataProvider
50+
* @param bool $isFlatEnabled
51+
* @param int $numMethodCalled
52+
* @return void
53+
*/
54+
public function testReindexRow(bool $isFlatEnabled, int $numMethodCalled): void
55+
{
56+
$id = 123;
57+
58+
$this->stateMock->expects($this->once())
59+
->method('isFlatEnabled')
60+
->willReturn($isFlatEnabled);
61+
$this->indexerMock->expects($this->exactly($numMethodCalled))
62+
->method('reindexRow')
63+
->with($id);
64+
65+
$this->processor->reindexRow($id);
66+
}
67+
68+
/**
69+
* @dataProvider stateDataProvider
70+
* @param bool $isFlatEnabled
71+
* @param int $numMethodCalled
72+
* @return void
73+
*/
74+
public function testReindexList(bool $isFlatEnabled, int $numMethodCalled): void
75+
{
76+
$ids = [123];
77+
78+
$this->stateMock->expects($this->once())
79+
->method('isFlatEnabled')
80+
->willReturn($isFlatEnabled);
81+
$this->indexerMock->expects($this->exactly($numMethodCalled))
82+
->method('reindexList')
83+
->with($ids);
84+
85+
$this->processor->reindexList($ids);
86+
}
87+
88+
/**
89+
* @dataProvider stateDataProvider
90+
* @param bool $isFlatEnabled
91+
* @param int $numMethodCalled
92+
* @return void
93+
*/
94+
public function testReindexAll(bool $isFlatEnabled, int $numMethodCalled): void
95+
{
96+
$this->stateMock->expects($this->once())
97+
->method('isFlatEnabled')
98+
->willReturn($isFlatEnabled);
99+
$this->indexerMock->expects($this->exactly($numMethodCalled))
100+
->method('reindexAll');
101+
102+
$this->processor->reindexAll();
103+
}
104+
105+
/**
106+
* @dataProvider stateDataProvider
107+
* @param bool $isFlatEnabled
108+
* @param int $numMethodCalled
109+
* @return void
110+
*/
111+
public function testMarkIndexerAsInvalid(bool $isFlatEnabled, int $numMethodCalled): void
112+
{
113+
$this->stateMock->expects($this->once())
114+
->method('isFlatEnabled')
115+
->willReturn($isFlatEnabled);
116+
$this->indexerMock->expects($this->exactly($numMethodCalled))
117+
->method('invalidate');
118+
119+
$this->processor->markIndexerAsInvalid();
120+
}
121+
122+
/**
123+
* @return array[]
124+
*/
125+
public static function stateDataProvider(): array
126+
{
127+
return [
128+
[true, 1],
129+
[false, 0],
130+
];
131+
}
132+
}

0 commit comments

Comments
 (0)