|
16 | 16 | use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
|
17 | 17 | use Magento\Eav\Model\Entity\Attribute;
|
18 | 18 | use Magento\Framework\App\RequestInterface;
|
| 19 | +use Magento\Framework\Pricing\PriceCurrencyInterface; |
19 | 20 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
|
20 | 21 | use PHPUnit\Framework\MockObject\MockObject;
|
21 | 22 | use PHPUnit\Framework\TestCase;
|
@@ -82,7 +83,15 @@ protected function setUp(): void
|
82 | 83 | ->method($this->anything())->willReturnSelf();
|
83 | 84 | $this->filterItemFactory->expects($this->any())
|
84 | 85 | ->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 | + ); |
86 | 95 |
|
87 | 96 | $this->fulltextCollection = $this->getMockBuilder(
|
88 | 97 | Collection::class
|
@@ -121,12 +130,20 @@ protected function setUp(): void
|
121 | 130 | ->willReturn($this->state);
|
122 | 131 |
|
123 | 132 | $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 | + ); |
124 | 140 | $this->target = $objectManagerHelper->getObject(
|
125 | 141 | Decimal::class,
|
126 | 142 | [
|
127 | 143 | 'filterItemFactory' => $this->filterItemFactory,
|
128 | 144 | 'layer' => $this->layer,
|
129 | 145 | 'filterDecimalFactory' => $filterDecimalFactory,
|
| 146 | + 'priceCurrency' => $priceFormatter, |
130 | 147 | ]
|
131 | 148 | );
|
132 | 149 |
|
@@ -212,23 +229,54 @@ function ($field) use ($requestVar, $filter) {
|
212 | 229 | $this->target->apply($this->request);
|
213 | 230 | }
|
214 | 231 |
|
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 |
216 | 238 | {
|
217 | 239 | $this->fulltextCollection->expects($this->any())
|
218 | 240 | ->method('getSize')
|
219 | 241 | ->willReturn(5);
|
220 | 242 |
|
221 | 243 | $this->fulltextCollection->expects($this->any())
|
222 | 244 | ->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 [ |
228 | 259 | [
|
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 | + ] |
230 | 269 | ],
|
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 | + ]; |
233 | 281 | }
|
234 | 282 | }
|
0 commit comments