Skip to content

Commit 1be618c

Browse files
committed
MC-42799: [Magento Cloud] Premiere Support - Layered Navigation setting for price range is not working with our custom attributes
- Add unit test coverage
1 parent ab4b541 commit 1be618c

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/DecimalTest.php

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
1717
use Magento\Eav\Model\Entity\Attribute;
1818
use Magento\Framework\App\RequestInterface;
19+
use Magento\Framework\Pricing\PriceCurrencyInterface;
1920
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2021
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
@@ -82,7 +83,15 @@ protected function setUp(): void
8283
->method($this->anything())->willReturnSelf();
8384
$this->filterItemFactory->expects($this->any())
8485
->method('create')
85-
->willReturn($this->filterItem);
86+
->willReturnCallback(
87+
function (array $data) {
88+
return new Item(
89+
$this->createMock(\Magento\Framework\UrlInterface::class),
90+
$this->createMock(\Magento\Theme\Block\Html\Pager::class),
91+
$data
92+
);
93+
}
94+
);
8695

8796
$this->fulltextCollection = $this->getMockBuilder(
8897
Collection::class
@@ -121,12 +130,20 @@ protected function setUp(): void
121130
->willReturn($this->state);
122131

123132
$objectManagerHelper = new ObjectManagerHelper($this);
133+
$priceFormatter = $this->createMock(PriceCurrencyInterface::class);
134+
$priceFormatter->method('format')
135+
->willReturnCallback(
136+
function ($number) {
137+
return sprintf('$%01.2f', $number);
138+
}
139+
);
124140
$this->target = $objectManagerHelper->getObject(
125141
Decimal::class,
126142
[
127143
'filterItemFactory' => $this->filterItemFactory,
128144
'layer' => $this->layer,
129145
'filterDecimalFactory' => $filterDecimalFactory,
146+
'priceCurrency' => $priceFormatter,
130147
]
131148
);
132149

@@ -212,23 +229,54 @@ function ($field) use ($requestVar, $filter) {
212229
$this->target->apply($this->request);
213230
}
214231

215-
public function testItemData()
232+
/**
233+
* @param array $facets
234+
* @param array $expected
235+
* @dataProvider itemDataDataProvider
236+
*/
237+
public function testItemData(array $facets, array $expected): void
216238
{
217239
$this->fulltextCollection->expects($this->any())
218240
->method('getSize')
219241
->willReturn(5);
220242

221243
$this->fulltextCollection->expects($this->any())
222244
->method('getFacetedData')
223-
->willReturn([
224-
'2_10' => ['count' => 5],
225-
'*_*' => ['count' => 2]
226-
]);
227-
$this->assertEquals(
245+
->willReturn($facets);
246+
$actual = [];
247+
foreach ($this->target->getItems() as $item) {
248+
$actual[] = ['label' => $item->getLabel(), 'value' => $item->getValue(), 'count' => $item->getCount()];
249+
}
250+
$this->assertEquals($expected, $actual);
251+
}
252+
253+
/**
254+
* @return array
255+
*/
256+
public function itemDataDataProvider(): array
257+
{
258+
return [
228259
[
229-
$this->filterItem
260+
[
261+
'0_10' => ['count' => 5],
262+
'10_20' => ['count' => 2],
263+
'30_' => ['count' => 1]
264+
],
265+
[
266+
['label' => '$10.00 - $19.99', 'value' => '10-20', 'count' => '2'],
267+
['label' => '$30.00 and above', 'value' => '30-', 'count' => '1'],
268+
]
230269
],
231-
$this->target->getItems()
232-
);
270+
[
271+
[
272+
'*_100' => ['count' => 3],
273+
'200_*' => ['count' => 1],
274+
],
275+
[
276+
['label' => '$0.00 - $99.99', 'value' => '-100', 'count' => '3'],
277+
['label' => '$200.00 and above', 'value' => '200-', 'count' => '1'],
278+
]
279+
]
280+
];
233281
}
234282
}

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Aggregation/DataProviderFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testCreateQueryAwareDataProvider()
9191
->getMock();
9292
$this->objectManager->expects($this->once())
9393
->method('create')
94-
->with($this->isType('string'), ['queryContainer' => $queryContainer])
94+
->with($this->isType('string'), ['queryContainer' => $queryContainer, 'aggregationFieldName' => null])
9595
->willReturn($recreatedDataProvider);
9696
$result = $this->factory->create($dataProvider, $queryContainer);
9797
$this->assertNotSame($dataProvider, $result);

0 commit comments

Comments
 (0)