Skip to content

Commit

Permalink
Merge pull request #46 from magento-firedrakes/bugfixes
Browse files Browse the repository at this point in the history
[Firedrakes] Bugfixes. Sprint 35
  • Loading branch information
Michael Logvin committed Jan 21, 2015
2 parents ae383b5 + 47a1704 commit 1bba5fe
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 10 deletions.
13 changes: 7 additions & 6 deletions app/code/Magento/Checkout/Controller/Cart/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ public function execute()
{
// Extract item and product to configure
$id = (int)$this->getRequest()->getParam('id');
$productId = (int)$this->getRequest()->getParam('product_id');
$quoteItem = null;
if ($id) {
$quoteItem = $this->cart->getQuote()->getItemById($id);
}

if (!$quoteItem) {
$this->messageManager->addError(__("We can't find the quote item."));
$this->_redirect('checkout/cart');
return;
}

try {
if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) {
$this->messageManager->addError(__("We can't find the quote item."));
$this->_redirect('checkout/cart');
return;
}

$params = new \Magento\Framework\Object();
$params->setCategoryId(false);
$params->setConfigureMode(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<head>
<title>Success Page</title>
</head>
<body>
<referenceBlock name="page.main.title">
<block class="Magento\Checkout\Block\Onepage\Success" name="checkout.success.print.button" template="button.phtml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="multishipping_checkout"/>
<head>
<title>Success Page</title>
</head>
<body>
<referenceBlock name="page.main.title">
<action method="setPageTitle">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ protected function _calculate($rule, $item, $qty, $rulePercent)
$discountData->setAmount(($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct);
$discountData->setBaseAmount(($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct);
$discountData->setOriginalAmount(($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct);
$discountData->setBaseOriginalAmount(($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct);
$discountData->setBaseOriginalAmount(
($qty * $baseItemOriginalPrice - $item->getBaseDiscountAmount()) * $_rulePct
);

if (!$rule->getDiscountQty() || $rule->getDiscountQty() > $qty) {
$discountPercent = min(100, $item->getDiscountPercent() + $rulePercent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Checkout\Controller\Cart;

/**
* Shopping cart edit tests
*/
class ConfigureTest extends \PHPUnit_Framework_TestCase
{

/**
* @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $objectManagerMock;

/**
* @var \Magento\Framework\View\Result\PageFactory | \PHPUnit_Framework_MockObject_MockObject
*/
protected $resultPageFactoryMock;

/**
* @var \Magento\Framework\App\ResponseInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $responseMock;

/**
* @var \Magento\Framework\App\RequestInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $requestMock;

/**
* @var \Magento\Framework\Message\ManagerInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $messageManagerMock;

/**
* @var \Magento\Framework\App\Response\RedirectInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $redirectMock;

/**
* @var \Magento\Checkout\Controller\Cart\Configure | \PHPUnit_Framework_MockObject_MockObject
*/
protected $configureController;

/**
* @var \Magento\Framework\App\Action\Context | \PHPUnit_Framework_MockObject_MockObject
*/
protected $contextMock;

/**
* @var \Magento\Checkout\Model\Cart | \PHPUnit_Framework_MockObject_MockObject
*/
protected $cartMock;

public function setUp()
{
$eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$urlMock = $this->getMockBuilder('Magento\Framework\UrlInterface')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$viewMock = $this->getMockBuilder('Magento\Framework\App\ViewInterface')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->disableOriginalConstructor()
->setMethods(['getParam'])
->getMockForAbstractClass();
$this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface')
->disableOriginalConstructor()
->setMethods([])
->getMockForAbstractClass();
$this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface')
->disableOriginalConstructor()
->setMethods([])
->getMock();

$this->contextMock = $this->getMockBuilder('Magento\Framework\App\Action\Context')
->setConstructorArgs(
[
$this->requestMock,
$this->responseMock,
$this->objectManagerMock,
$eventManagerMock,
$urlMock,
$this->redirectMock,
$actionFlagMock,
$viewMock,
$this->messageManagerMock
]
)
->setMethods([])
->getMock();
$this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
$this->contextMock->expects($this->any())->method('getResponse')->willReturn($this->responseMock);
$this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock);
$this->contextMock->expects($this->any())->method('getRedirect')->willReturn($this->redirectMock);
$scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
->disableOriginalConstructor()
->getMock();
$session = $this->getMockBuilder('Magento\Checkout\Model\Session')
->disableOriginalConstructor()
->getMock();
$storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
->disableOriginalConstructor()
->getMockForAbstractClass();
$formKeyValidator = $this->getMockBuilder('Magento\Core\App\Action\FormKeyValidator')
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->cartMock = $this->getMockBuilder('Magento\Checkout\Model\Cart')
->disableOriginalConstructor()
->getMock();
$this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
->disableOriginalConstructor()
->getMock();

$this->configureController = new \Magento\Checkout\Controller\Cart\Configure(
$this->contextMock,
$scopeConfig,
$session,
$storeManager,
$formKeyValidator,
$this->cartMock,
$this->resultPageFactoryMock
);
}

/**
* Test checks controller call product view and send parameter to it
*
* @return void
*/
public function testPrepareAndRenderCall()
{
$quoteId = 1;
$actualProductId = 1;
$quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote')
->disableOriginalConstructor()
->getMock();
$quoteItemMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Item')
->disableOriginalConstructor()
->getMock();
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();
$viewMock = $this->getMockBuilder('Magento\Catalog\Helper\Product\View')
->disableOriginalConstructor()
->getMock();
$pageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
->disableOriginalConstructor()
->getMock();
$buyRequestMock = $this->getMockBuilder('Magento\Framework\Object')
->disableOriginalConstructor()
->getMock();
//expects
$this->requestMock->expects($this->at(0))
->method('getParam')
->with('id')
->willReturn($quoteId);
$this->requestMock->expects($this->at(1))
->method('getParam')
->with('product_id')
->willReturn($actualProductId);
$this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);

$quoteItemMock->expects($this->exactly(1))->method('getBuyRequest')->willReturn($buyRequestMock);

$this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($pageMock);
$this->objectManagerMock->expects($this->at(0))
->method('get')
->with('Magento\Catalog\Helper\Product\View')
->willReturn($viewMock);

$viewMock->expects($this->once())->method('prepareAndRender')->with(
$pageMock,
$actualProductId,
$this->configureController,
$this->callback(
function ($subject) use ($buyRequestMock) {
return $subject->getBuyRequest() === $buyRequestMock;
}
)
)->willReturn($pageMock);

$quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock);
$quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($productMock);

$productMock->expects($this->exactly(2))->method('getId')->willReturn($actualProductId);

$this->assertSame($pageMock, $this->configureController->execute());
}

/**
* Test checks controller redirect user to cart
* if user request product id in cart edit page is not same as quota product id
*
* @return void
*/
public function testRedirectWithWrongProductId()
{
$quotaId = 1;
$productIdInQuota = 1;
$productIdInRequest = null;
$quoteItemMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Item')
->disableOriginalConstructor()
->getMock();
$quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote')
->disableOriginalConstructor()
->getMock();
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();
$this->requestMock->expects($this->at(0))
->method('getParam')
->with('id')
->willReturn($quotaId);
$this->requestMock->expects($this->at(1))
->method('getParam')
->with('product_id')
->willReturn($productIdInRequest);
$this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
$quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock);
$quoteItemMock->expects($this->exactly(1))->method('getProduct')->willReturn($productMock);
$productMock->expects($this->exactly(1))->method('getId')->willReturn($productIdInQuota);
$this->messageManagerMock->expects($this->once())->method('addError');
$this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'checkout/cart', []);
$this->configureController->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function calculateDataProvider()
'amount' => 42,
'baseAmount' => 25.5,
'originalAmount' => 51,
'baseOriginalAmount' => 46.5,
'baseOriginalAmount' => 34.5,
],
]
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function calculateDataProvider()
'amount' => 98,
'baseAmount' => 59.5,
'originalAmount' => 119,
'baseOriginalAmount' => 108.5,
'baseOriginalAmount' => 80.5,
],
]
];
Expand Down
2 changes: 1 addition & 1 deletion lib/web/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ FormElementDependenceController.prototype = {
}
} else {
$(idTo).show();
if (isAnInputOrSelect) {
if (isAnInputOrSelect && !isInheritCheckboxChecked) {
$(idTo).disabled = false;
jQuery('#' + idTo).removeClass('ignore-validate');
}
Expand Down

0 comments on commit 1bba5fe

Please sign in to comment.