79 private $priceCurrency;
88 $this->collectionFactory =
90 ->setMethods([
'create'])
91 ->disableOriginalConstructor()->getMock();
92 $this->visibility = $this->getMockBuilder(\
Magento\Catalog\Model\Product\Visibility::class)
93 ->setMethods([
'getVisibleInCatalogIds'])
94 ->disableOriginalConstructor()
96 $this->httpContext = $this->createMock(\
Magento\Framework\
App\Http\Context::class);
97 $this->builder = $this->createMock(\
Magento\Rule\Model\Condition\Sql\Builder::class);
98 $this->rule = $this->createMock(\
Magento\CatalogWidget\Model\Rule::class);
99 $this->serializer = $this->createMock(\
Magento\Framework\Serialize\Serializer\Json::class);
100 $this->widgetConditionsHelper = $this->getMockBuilder(\
Magento\Widget\Helper\Conditions::class)
101 ->disableOriginalConstructor()
103 $this->storeManager = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
104 $this->design = $this->createMock(\
Magento\Framework\View\DesignInterface::class);
106 $objectManagerHelper =
new ObjectManagerHelper($this);
107 $arguments = $objectManagerHelper->getConstructArguments(
108 \
Magento\CatalogWidget\Block\Product\ProductsList::class,
110 'productCollectionFactory' => $this->collectionFactory,
111 'catalogProductVisibility' => $this->visibility,
112 'httpContext' => $this->httpContext,
113 'sqlBuilder' => $this->builder,
114 'rule' => $this->rule,
115 'conditionsHelper' => $this->widgetConditionsHelper,
116 'storeManager' => $this->storeManager,
117 'design' => $this->design,
118 'json' => $this->serializer
121 $this->request =
$arguments[
'context']->getRequest();
122 $this->layout =
$arguments[
'context']->getLayout();
123 $this->priceCurrency = $this->createMock(PriceCurrencyInterface::class);
125 $this->productsList = $objectManagerHelper->getObject(
126 \
Magento\CatalogWidget\Block\Product\ProductsList::class,
129 $objectManagerHelper->setBackwardCompatibleProperty($this->productsList,
'priceCurrency', $this->priceCurrency);
134 $store = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
135 ->disableOriginalConstructor()->setMethods([
'getId'])->getMock();
136 $store->expects($this->once())->method(
'getId')->willReturn(1);
137 $this->storeManager->expects($this->once())->method(
'getStore')->willReturn(
$store);
139 $theme = $this->createMock(\
Magento\Framework\View\Design\ThemeInterface::class);
140 $theme->expects($this->once())->method(
'getId')->willReturn(
'blank');
141 $this->design->expects($this->once())->method(
'getDesignTheme')->willReturn(
$theme);
143 $this->httpContext->expects($this->once())->method(
'getValue')->willReturn(
'context_group');
144 $this->productsList->setData(
'conditions',
'some_serialized_conditions');
146 $this->productsList->setData(
'page_var_name',
'page_number');
147 $this->productsList->setTemplate(
'test_template');
148 $this->productsList->setData(
'title',
'test_title');
149 $this->request->expects($this->once())->method(
'getParam')->with(
'page_number')->willReturn(1);
151 $this->request->expects($this->once())->method(
'getParams')->willReturn(
'request_params');
152 $currency = $this->createMock(\
Magento\Directory\Model\Currency::class);
153 $currency->expects($this->once())->method(
'getCode')->willReturn(
'USD');
154 $this->priceCurrency->expects($this->once())->method(
'getCurrency')->willReturn($currency);
156 $this->serializer->expects($this->any())
157 ->method(
'serialize')
158 ->willReturnCallback(
function (
$value) {
159 return json_encode(
$value);
163 'CATALOG_PRODUCTS_LIST_WIDGET',
170 'some_serialized_conditions',
171 json_encode(
'request_params'),
175 $this->assertEquals($cacheKey, $this->productsList->getCacheKeyInfo());
180 $product = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
181 ->setMethods([
'getId'])
182 ->disableOriginalConstructor()
184 $product->expects($this->once())->method(
'getId')->willReturn(1);
186 $priceRenderer = $this->getMockBuilder(\
Magento\Framework\Pricing\Render::class)
187 ->setMethods([
'render'])
188 ->disableOriginalConstructor()
190 $priceRenderer->expects($this->once())
193 'include_container' =>
false,
194 'display_minimal_price' =>
false,
195 'zone' =>
'item_list',
196 'price_id' =>
'old-price-1-some-price-type' 198 ->willReturn(
'<html>');
199 $this->layout->expects($this->once())->method(
'getBlock')->willReturn($priceRenderer);
201 $this->assertEquals(
'<html>', $this->productsList->getProductPriceHtml(
204 \
Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
206 'include_container' =>
false,
207 'display_minimal_price' =>
false 214 $this->assertEquals(
'', $this->productsList->getPagerHtml());
220 ->setMethods([
'getSize'])
221 ->disableOriginalConstructor()
223 $collection->expects($this->once())->method(
'getSize')->willReturn(3);
225 $this->productsList->setData(
'show_pager',
true);
226 $this->productsList->setData(
'products_per_page', 2);
227 $this->productsList->setData(
'product_collection',
$collection);
229 $pagerBlock = $this->getMockBuilder(\
Magento\Catalog\Block\Product\Widget\Html\Pager::class)
239 ])->disableOriginalConstructor()->getMock();
241 $pagerBlock->expects($this->once())->method(
'setUseContainer')->willReturnSelf();
242 $pagerBlock->expects($this->once())->method(
'setShowAmounts')->willReturnSelf();
243 $pagerBlock->expects($this->once())->method(
'setShowPerPage')->willReturnSelf();
244 $pagerBlock->expects($this->once())->method(
'setPageVarName')->willReturnSelf();
245 $pagerBlock->expects($this->once())->method(
'setLimit')->willReturnSelf();
246 $pagerBlock->expects($this->once())->method(
'setTotalLimit')->willReturnSelf();
247 $pagerBlock->expects($this->once())->method(
'setCollection')->with(
$collection)->willReturnSelf();
249 $pagerBlock->expects($this->once())->method(
'toHtml')->willReturn(
'<pager_html>');
250 $this->layout->expects($this->once())->method(
'createBlock')->willReturn($pagerBlock);
251 $this->assertEquals(
'<pager_html>', $this->productsList->getPagerHtml());
266 $this->visibility->expects($this->once())->method(
'getVisibleInCatalogIds')
274 'addAttributeToSelect',
280 ])->disableOriginalConstructor()
282 $collection->expects($this->once())->method(
'setVisibility')
285 $collection->expects($this->once())->method(
'addMinimalPrice')->willReturnSelf();
286 $collection->expects($this->once())->method(
'addFinalPrice')->willReturnSelf();
287 $collection->expects($this->once())->method(
'addTaxPercents')->willReturnSelf();
288 $collection->expects($this->once())->method(
'addAttributeToSelect')->willReturnSelf();
289 $collection->expects($this->once())->method(
'addUrlRewrite')->willReturnSelf();
290 $collection->expects($this->once())->method(
'addStoreFilter')->willReturnSelf();
291 $collection->expects($this->once())->method(
'setPageSize')->with($expectedPageSize)->willReturnSelf();
292 $collection->expects($this->once())->method(
'setCurPage')->willReturnSelf();
293 $collection->expects($this->once())->method(
'distinct')->willReturnSelf();
295 $this->collectionFactory->expects($this->once())->method(
'create')->willReturn(
$collection);
296 $this->productsList->setData(
'conditions_encoded',
'some_serialized_conditions');
298 $this->widgetConditionsHelper->expects($this->once())
300 ->with(
'some_serialized_conditions')
303 $this->builder->expects($this->once())->method(
'attachConditionToCollection')
307 if ($productsPerPage) {
308 $this->productsList->setData(
'products_per_page', $productsPerPage);
310 $this->productsList->unsetData(
'products_per_page');
313 $this->productsList->setData(
'show_pager', $pagerEnable);
314 $this->productsList->setData(
'products_count', $productsCount);
316 $this->assertSame(
$collection, $this->productsList->createCollection());
342 $this->assertEquals(10, $this->productsList->getProductsCount());
343 $this->productsList->setProductsCount(2);
344 $this->assertEquals(2, $this->productsList->getProductsCount());
349 $this->productsList->setData(
'products_per_page', 2);
350 $this->assertEquals(2, $this->productsList->getProductsPerPage());
360 $this->assertEquals(
false, $this->productsList->showPager());
361 $this->productsList->setData(
'show_pager',
true);
362 $this->assertEquals(
true, $this->productsList->showPager());
369 'addAttributeToSelect',
371 ])->disableOriginalConstructor()
374 $product = $this->createPartialMock(\
Magento\Framework\DataObject\IdentityInterface::class, [
'getIdentities']);
375 $notProduct = $this->getMockBuilder(
'NotProduct')
376 ->setMethods([
'getIdentities'])
377 ->disableOriginalConstructor()
379 $product->expects($this->once())->method(
'getIdentities')->willReturn([
'product_identity']);
380 $collection->expects($this->once())->method(
'getIterator')->willReturn(
381 new \ArrayIterator([
$product, $notProduct])
383 $this->productsList->setData(
'product_collection',
$collection);
386 [
'product_identity'],
387 $this->productsList->getIdentities()
396 private function getConditionsForCollection(
$collection)
398 $conditions = $this->getMockBuilder(\
Magento\Rule\Model\Condition\Combine::class)
399 ->setMethods([
'collectValidatedAttributes'])
400 ->disableOriginalConstructor()
402 $conditions->expects($this->once())->method(
'collectValidatedAttributes')
406 $this->rule->expects($this->once())->method(
'loadPost')->willReturnSelf();
407 $this->rule->expects($this->once())->method(
'getConditions')->willReturn($conditions);
413 $this->assertEmpty($this->productsList->getTitle());
418 $this->productsList->setTitle(
'Custom Title');
419 $this->assertEquals(
'Custom Title', $this->productsList->getTitle());
424 $this->assertFalse($this->productsList->isScopePrivate());
const VISIBILITY_IN_CATALOG