60 $this->objectManager =
new ObjectManagerHelper($this);
61 $this->eventManager = $this->createPartialMock(\
Magento\Framework\Event\Manager::class, [
'dispatch']);
62 $this->scopeConfig = $this->createMock(\
Magento\Framework\
App\Config::class);
63 $this->cacheState = $this->createPartialMock(\
Magento\Framework\
App\
Cache\State::class, [
'isEnabled']);
64 $this->localDate = $this->createMock(\
Magento\Framework\Stdlib\DateTime\Timezone::class);
65 $this->catalogConfig = $this->getMockBuilder(\
Magento\Catalog\Model\Config::class)
66 ->setMethods([
'getProductAttributes'])
67 ->disableOriginalConstructor()
69 $this->layout = $this->createMock(\
Magento\Framework\
View\Layout::class);
70 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
71 ->disableOriginalConstructor()
74 $this->context = $this->getMockBuilder(\
Magento\Catalog\Block\
Product\Context::class)
77 'getEventManager',
'getScopeConfig',
'getLayout',
78 'getRequest',
'getCacheState',
'getCatalogConfig',
82 ->disableOriginalConstructor()
83 ->disableArgumentCloning()
86 $this->context->expects($this->any())
88 ->willReturn($this->layout);
89 $this->context->expects($this->any())
90 ->method(
'getRequest')
91 ->willReturn($this->requestMock);
93 $this->block = $this->objectManager->getObject(
96 'context' => $this->context
113 <div class="price-box price-final_price"> 114 <span class="regular-price" id="product-price-' .
$id .
'"> 115 <span class="price">$0.00</span> 118 $type =
'widget-new-list';
119 $productMock = $this->createPartialMock(\
Magento\Catalog\Model\Product::class, [
'getId']);
120 $productMock->expects($this->once())
124 'price_id' =>
'old-price-' .
$id .
'-' .
$type,
125 'display_minimal_price' =>
true,
126 'include_container' =>
true,
130 $priceBoxMock = $this->createPartialMock(\
Magento\Framework\Pricing\Render::class, [
'render']);
132 $this->layout->expects($this->once())
134 ->with($this->equalTo(
'product.price.render.default'))
135 ->willReturn($priceBoxMock);
137 $priceBoxMock->expects($this->once())
139 ->with($this->equalTo(
'final_price'), $this->equalTo($productMock), $this->equalTo(
$arguments))
140 ->willReturn($expectedHtml);
142 $result = $this->block->getProductPriceHtml($productMock,
$type);
143 $this->assertEquals($expectedHtml,
$result);
153 $this->block->setData(
'page_var_name',
'page_number');
155 $this->requestMock->expects($this->any())
157 ->with(
'page_number')
158 ->willReturn($pageNumber);
160 $this->assertEquals($expectedResult, $this->block->getCurrentPage());
177 $this->assertEquals(10, $this->block->getProductsCount());
178 $this->block->setProductsCount(2);
179 $this->assertEquals(2, $this->block->getProductsCount());
187 $this->eventManager->expects($this->exactly(2))->method(
'dispatch')
188 ->will($this->returnValue(
true));
189 $this->scopeConfig->expects($this->once())->method(
'getValue')->withAnyParameters()
191 $this->cacheState->expects($this->atLeastOnce())->method(
'isEnabled')->withAnyParameters()
193 $this->catalogConfig->expects($this->once())->method(
'getProductAttributes')
195 $this->localDate->expects($this->any())->method(
'date')
196 ->willReturn(
new \DateTime(
'now',
new \DateTimeZone(
'UTC')));
198 $this->context->expects($this->once())->method(
'getEventManager')->willReturn($this->eventManager);
199 $this->context->expects($this->once())->method(
'getScopeConfig')->willReturn($this->scopeConfig);
200 $this->context->expects($this->once())->method(
'getCacheState')->willReturn($this->cacheState);
201 $this->context->expects($this->once())->method(
'getCatalogConfig')->willReturn($this->catalogConfig);
202 $this->context->expects($this->once())->method(
'getLocaleDate')->willReturn($this->localDate);
207 'setVisibility',
'addMinimalPrice',
'addFinalPrice',
208 'addTaxPercents',
'addAttributeToSelect',
'addUrlRewrite',
209 'addStoreFilter',
'addAttributeToSort',
'setPageSize',
210 'setCurPage',
'addAttributeToFilter' 213 ->disableOriginalConstructor()
215 $this->productCollection->expects($this->once())->method(
'setVisibility')
217 $this->productCollection->expects($this->once())->method(
'addMinimalPrice')
219 $this->productCollection->expects($this->once())->method(
'addFinalPrice')
221 $this->productCollection->expects($this->once())->method(
'addTaxPercents')
223 $this->productCollection->expects($this->once())->method(
'addAttributeToSelect')
225 $this->productCollection->expects($this->once())->method(
'addUrlRewrite')
227 $this->productCollection->expects($this->once())->method(
'addStoreFilter')
229 $this->productCollection->expects($this->once())->method(
'addAttributeToSort')
231 $this->productCollection->expects($this->atLeastOnce())->method(
'setCurPage')
233 $this->productCollection->expects($this->any())->method(
'addAttributeToFilter')
245 $productCollectionFactory = $this->createPartialMock(
249 $productCollectionFactory->expects($this->atLeastOnce())->method(
'create')
250 ->willReturn($this->productCollection);
252 $this->block = $this->objectManager->getObject(
255 'context' => $this->context,
256 'productCollectionFactory' => $productCollectionFactory
260 if (
null === $productsPerPage) {
261 $this->block->unsetData(
'products_per_page');
263 $this->block->setData(
'products_per_page', $productsPerPage);
266 $this->block->setData(
'show_pager', $pagerEnable);
267 $this->block->setData(
'display_type', $displayType);
268 $this->block->setProductsCount($productsCount);
269 $this->block->toHtml();
286 $this->productCollection->expects($this->exactly(2))->method(
'setPageSize')
315 $this->productCollection->expects($this->atLeastOnce())->method(
'setPageSize')->with($expectedPageSize)