Skip to content

Commit

Permalink
MAGETWO-47017: [Github] Add Configurable Product To Cart from Categor…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Semenov committed May 3, 2017
1 parent ff460af commit 30967b7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
* @param ConfigurableAttributeData $configurableAttributeData
* @param array $data
* @param Format|null $localeFormat
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ConfigurableTestTest extends \PHPUnit_Framework_TestCase
{
/**
Expand Down Expand Up @@ -128,18 +131,7 @@ public function testGetJsonConfig()
$priceQty = 1;
$percentage = 10;

$amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class)
->setMethods([
'getValue',
'getBaseAmount',
])
->getMockForAbstractClass();
$amountMock->expects($this->any())
->method('getValue')
->willReturn($amount);
$amountMock->expects($this->any())
->method('getBaseAmount')
->willReturn($amount);
$amountMock = $this->getAmountMock($amount);

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

$tierPrice = [
'price_qty' => $priceQty,
'price' => $amountMock,
];

$tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class)
->setMethods([
'getTierPriceList',
'getSavePercent',
])
->getMockForAbstractClass();
$tierPriceMock->expects($this->any())
->method('getTierPriceList')
->willReturn([$tierPrice]);
$tierPriceMock->expects($this->any())
->method('getSavePercent')
->willReturn($percentage);
$tierPriceMock = $this->getTierPriceMock($amountMock, $priceQty, $percentage);

$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -368,4 +344,59 @@ protected function mockContextObject()
->method('getRegistry')
->willReturn($this->registry);
}

/**
* Retrieve mock of \Magento\Framework\Pricing\Amount\AmountInterface object
*
* @param float $amount
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getAmountMock($amount): \PHPUnit_Framework_MockObject_MockObject
{
$amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class)
->setMethods([
'getValue',
'getBaseAmount',
])
->getMockForAbstractClass();
$amountMock->expects($this->any())
->method('getValue')
->willReturn($amount);
$amountMock->expects($this->any())
->method('getBaseAmount')
->willReturn($amount);

return $amountMock;
}

/**
* Retrieve mock of \Magento\Catalog\Pricing\Price\TierPriceInterface object
*
* @param \PHPUnit_Framework_MockObject_MockObject $amountMock
* @param float $priceQty
* @param int $percentage
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getTierPriceMock(\PHPUnit_Framework_MockObject_MockObject $amountMock, $priceQty, $percentage)
{
$tierPrice = [
'price_qty' => $priceQty,
'price' => $amountMock,
];

$tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class)
->setMethods([
'getTierPriceList',
'getSavePercent',
])
->getMockForAbstractClass();
$tierPriceMock->expects($this->any())
->method('getTierPriceList')
->willReturn([$tierPrice]);
$tierPriceMock->expects($this->any())
->method('getSavePercent')
->willReturn($percentage);

return $tierPriceMock;
}
}

0 comments on commit 30967b7

Please sign in to comment.