Skip to content

Commit 30967b7

Browse files
author
Sergey Semenov
committed
MAGETWO-47017: [Github] Add Configurable Product To Cart from Category Page #2574 #5850 #5882 #6572 #5558 #4184
1 parent ff460af commit 30967b7

File tree

2 files changed

+61
-29
lines changed

2 files changed

+61
-29
lines changed

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
7777
* @param ConfigurableAttributeData $configurableAttributeData
7878
* @param array $data
7979
* @param Format|null $localeFormat
80+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8081
*/
8182
public function __construct(
8283
\Magento\Catalog\Block\Product\Context $context,

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type;
77

8+
/**
9+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10+
*/
811
class ConfigurableTestTest extends \PHPUnit_Framework_TestCase
912
{
1013
/**
@@ -128,18 +131,7 @@ public function testGetJsonConfig()
128131
$priceQty = 1;
129132
$percentage = 10;
130133

131-
$amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class)
132-
->setMethods([
133-
'getValue',
134-
'getBaseAmount',
135-
])
136-
->getMockForAbstractClass();
137-
$amountMock->expects($this->any())
138-
->method('getValue')
139-
->willReturn($amount);
140-
$amountMock->expects($this->any())
141-
->method('getBaseAmount')
142-
->willReturn($amount);
134+
$amountMock = $this->getAmountMock($amount);
143135

144136
$priceMock = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
145137
->setMethods([
@@ -150,23 +142,7 @@ public function testGetJsonConfig()
150142
->method('getAmount')
151143
->willReturn($amountMock);
152144

153-
$tierPrice = [
154-
'price_qty' => $priceQty,
155-
'price' => $amountMock,
156-
];
157-
158-
$tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class)
159-
->setMethods([
160-
'getTierPriceList',
161-
'getSavePercent',
162-
])
163-
->getMockForAbstractClass();
164-
$tierPriceMock->expects($this->any())
165-
->method('getTierPriceList')
166-
->willReturn([$tierPrice]);
167-
$tierPriceMock->expects($this->any())
168-
->method('getSavePercent')
169-
->willReturn($percentage);
145+
$tierPriceMock = $this->getTierPriceMock($amountMock, $priceQty, $percentage);
170146

171147
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
172148
->disableOriginalConstructor()
@@ -368,4 +344,59 @@ protected function mockContextObject()
368344
->method('getRegistry')
369345
->willReturn($this->registry);
370346
}
347+
348+
/**
349+
* Retrieve mock of \Magento\Framework\Pricing\Amount\AmountInterface object
350+
*
351+
* @param float $amount
352+
* @return \PHPUnit_Framework_MockObject_MockObject
353+
*/
354+
protected function getAmountMock($amount): \PHPUnit_Framework_MockObject_MockObject
355+
{
356+
$amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class)
357+
->setMethods([
358+
'getValue',
359+
'getBaseAmount',
360+
])
361+
->getMockForAbstractClass();
362+
$amountMock->expects($this->any())
363+
->method('getValue')
364+
->willReturn($amount);
365+
$amountMock->expects($this->any())
366+
->method('getBaseAmount')
367+
->willReturn($amount);
368+
369+
return $amountMock;
370+
}
371+
372+
/**
373+
* Retrieve mock of \Magento\Catalog\Pricing\Price\TierPriceInterface object
374+
*
375+
* @param \PHPUnit_Framework_MockObject_MockObject $amountMock
376+
* @param float $priceQty
377+
* @param int $percentage
378+
* @return \PHPUnit_Framework_MockObject_MockObject
379+
*/
380+
protected function getTierPriceMock(\PHPUnit_Framework_MockObject_MockObject $amountMock, $priceQty, $percentage)
381+
{
382+
$tierPrice = [
383+
'price_qty' => $priceQty,
384+
'price' => $amountMock,
385+
];
386+
387+
$tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class)
388+
->setMethods([
389+
'getTierPriceList',
390+
'getSavePercent',
391+
])
392+
->getMockForAbstractClass();
393+
$tierPriceMock->expects($this->any())
394+
->method('getTierPriceList')
395+
->willReturn([$tierPrice]);
396+
$tierPriceMock->expects($this->any())
397+
->method('getSavePercent')
398+
->willReturn($percentage);
399+
400+
return $tierPriceMock;
401+
}
371402
}

0 commit comments

Comments
 (0)