48 private $storeManager;
57 $this->collection = $this->createPartialMock(
60 'addAttributeToSelect',
69 $this->resource = $this->createPartialMock(
71 [
'prepareCondition',
'__wakeup',
'getIdFieldName']
74 $this->resourceProvider = $this->getMockBuilder(
77 ->setMethods([
'getResource',
'getResourceCollection',
'getAdvancedResultCollection'])
78 ->disableOriginalConstructor()
81 $this->dataCollection = $this->createPartialMock(\
Magento\Framework\Data\Collection::class, [
'getIterator']);
83 $this->currency = $this->getMockBuilder(\
Magento\Directory\Model\Currency::class)
84 ->setMethods([
'getRate'])
85 ->disableOriginalConstructor()
87 $this->store = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
88 ->setMethods([
'getCurrentCurrencyCode',
'getBaseCurrencyCode',
'getBaseCurrency'])
89 ->disableOriginalConstructor()
91 $this->store->expects($this->any())
92 ->method(
'getBaseCurrency')
93 ->willReturn($this->currency);
94 $this->storeManager = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
95 ->setMethods([
'getStore'])
96 ->getMockForAbstractClass();
97 $this->storeManager->expects($this->any())
99 ->willReturn($this->store);
111 $this->createAttribute(
112 $this->createBackend(
'catalog_product_entity'),
113 $this->createSource(),
120 'values' => [
'sku' =>
'simple']
122 'color_multiselect' => [
124 $this->createAttribute(
125 $this->createBackend(
'color_multiselect'),
126 $this->createSource([
'label' =>
'Color']),
133 'values' => [
'color' => [100 =>
'red', 200 =>
'blue']],
134 'currentCurrencyCode' =>
'GBP',
135 'baseCurrencyCode' =>
'USD' 139 $this->createAttribute(
140 $this->createBackend(
'color_select'),
141 $this->createSource([
'label' =>
'Color']),
148 'values' => [
'color' =>
'red'],
149 'currentCurrencyCode' =>
'GBP',
150 'baseCurrencyCode' =>
'USD' 154 $this->createAttribute(
155 $this->createBackend(
'boolean'),
156 $this->createSource([
'label' =>
'Color']),
163 'values' => [
'is_active' => 0],
164 'currentCurrencyCode' =>
'GBP',
165 'baseCurrencyCode' =>
'USD' 168 $this->addFiltersPriceDataProvider()
179 public function testAddFiltersVerifyAddConditionsToRegistry(
183 $baseCurrencyCode =
'USD' 185 $registry = new \Magento\Framework\Registry();
187 $this->collection->expects($this->any())->method(
'addAttributeToSelect')->will($this->returnSelf());
188 $this->collection->expects($this->any())->method(
'setStore')->will($this->returnSelf());
189 $this->collection->expects($this->any())->method(
'addMinimalPrice')->will($this->returnSelf());
190 $this->collection->expects($this->any())->method(
'addTaxPercents')->will($this->returnSelf());
191 $this->collection->expects($this->any())->method(
'addStoreFilter')->will($this->returnSelf());
192 $this->collection->expects($this->any())->method(
'setVisibility')->will($this->returnSelf());
193 $this->resource->expects($this->any())->method(
'prepareCondition')
194 ->will($this->returnValue([
'like' =>
'%simple%']));
195 $this->resource->expects($this->any())->method(
'getIdFieldName')->will($this->returnValue(
'entity_id'));
196 $this->dataCollection->expects($this->any())->method(
'getIterator')
197 ->will($this->returnValue(
new \ArrayIterator(
$attributes)));
198 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
200 $advancedFactory = $this->getMockBuilder(\
Magento\CatalogSearch\Model\
ResourceModel\AdvancedFactory::class)
201 ->setMethods([
'create'])
202 ->disableOriginalConstructor()
204 $advancedFactory->expects($this->once())->method(
'create')->willReturn($this->resource);
206 $productCollectionFactory =
208 ->setMethods([
'create'])
209 ->disableOriginalConstructor()
211 $productCollectionFactory->expects($this->any())->method(
'create')->willReturn($this->collection);
213 $this->store->expects($this->any())
214 ->method(
'getCurrentCurrencyCode')
216 $this->store->expects($this->any())
217 ->method(
'getBaseCurrencyCode')
218 ->willReturn($baseCurrencyCode);
219 $this->currency->expects($this->any())
224 $currency = $this->getMockBuilder(\
Magento\Directory\Model\Currency::class)
225 ->setMethods([
'load',
'format'])
226 ->disableOriginalConstructor()
228 $currency->expects($this->any())
231 $currency->expects($this->any())
233 ->willReturnArgument(0);
234 $currencyFactory = $this->getMockBuilder(\
Magento\Directory\Model\CurrencyFactory::class)
235 ->setMethods([
'create'])
236 ->disableOriginalConstructor()
238 $currencyFactory->expects($this->any())
240 ->willReturn($currency);
244 \
Magento\CatalogSearch\Model\Advanced::class,
247 'resourceProvider' => $this->resourceProvider,
248 'data' => [
'attributes' => $this->dataCollection],
249 'advancedFactory' => $advancedFactory,
250 'productCollectionFactory' => $productCollectionFactory,
251 'storeManager' => $this->storeManager,
252 'currencyFactory' => $currencyFactory,
255 $instance->addFilters(
$values);
256 $this->assertNotNull(
$registry->registry(
'advanced_search_conditions'));
263 private function createBackend(
$table)
265 $backend = $this->createPartialMock(
266 \
Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend::class,
269 $backend->expects($this->once())
279 private function createSource($optionText =
'optionText')
281 $source = $this->getMockBuilder(\
Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class)
282 ->setMethods([
'getOptionText'])
283 ->disableOriginalConstructor()
284 ->getMockForAbstractClass();
286 ->method(
'getOptionText')
287 ->willReturn($optionText);
294 private function addFiltersPriceDataProvider()
297 'price_without_currency' => [
299 $this->createAttribute(
300 $this->createBackend(
'table_price_without_currency'),
301 $this->createSource(),
308 'values' => [
'price' => [
'from' => 10,
'to' => 40]],
309 'currentCurrencyCode' =>
'GBP',
310 'baseCurrencyCode' =>
'USD' 312 'price_without_to' => [
314 $this->createAttribute(
315 $this->createBackend(
'price_without_to'),
316 $this->createSource(),
323 'values' => [
'price' => [
'from' => 10,
'to' =>
'']],
324 'currentCurrencyCode' =>
'GBP',
325 'baseCurrencyCode' =>
'USD' 327 'price_without_from' => [
329 $this->createAttribute(
330 $this->createBackend(
'price_without_from'),
331 $this->createSource(),
338 'values' => [
'price' => [
'from' =>
'',
'to' => 30]],
339 'currentCurrencyCode' =>
'GBP',
340 'baseCurrencyCode' =>
'USD' 344 $this->createAttribute(
345 $this->createBackend(
'price_empty'),
346 $this->createSource(),
353 'values' => [
'price' => [
'from' =>
'',
'to' =>
'']],
354 'currentCurrencyCode' =>
'GBP',
355 'baseCurrencyCode' =>
'USD' 357 'price_with_currency' => [
359 $this->createAttribute(
360 $this->createBackend(
'price_with_currency'),
361 $this->createSource(),
368 'values' => [
'price' => [
'from' => 10,
'to' => 40,
'currency' =>
'ASD']],
369 'currentCurrencyCode' =>
'GBP',
370 'baseCurrencyCode' =>
'USD' 384 private function createAttribute(
389 $frontendInput =
null,
401 $attribute->expects($this->any())->method(
'getBackend')->willReturn($backend);
404 $attribute->expects($this->any())->method(
'getStoreLabel')->will($this->returnValue($storeLabel));
405 $attribute->expects($this->any())->method(
'getFrontendInput')->will($this->returnValue($frontendInput));
406 $attribute->expects($this->any())->method(
'getBackendType')->will($this->returnValue($backendType));