Skip to content

Commit 1bba5fe

Browse files
author
Michael Logvin
committed
Merge pull request #46 from magento-firedrakes/bugfixes
[Firedrakes] Bugfixes. Sprint 35
2 parents ae383b5 + 47a1704 commit 1bba5fe

File tree

8 files changed

+269
-10
lines changed

8 files changed

+269
-10
lines changed

app/code/Magento/Checkout/Controller/Cart/Configure.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,19 @@ public function execute()
4444
{
4545
// Extract item and product to configure
4646
$id = (int)$this->getRequest()->getParam('id');
47+
$productId = (int)$this->getRequest()->getParam('product_id');
4748
$quoteItem = null;
4849
if ($id) {
4950
$quoteItem = $this->cart->getQuote()->getItemById($id);
5051
}
5152

52-
if (!$quoteItem) {
53-
$this->messageManager->addError(__("We can't find the quote item."));
54-
$this->_redirect('checkout/cart');
55-
return;
56-
}
57-
5853
try {
54+
if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) {
55+
$this->messageManager->addError(__("We can't find the quote item."));
56+
$this->_redirect('checkout/cart');
57+
return;
58+
}
59+
5960
$params = new \Magento\Framework\Object();
6061
$params->setCategoryId(false);
6162
$params->setConfigureMode(true);

app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_success.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
-->
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
9+
<head>
10+
<title>Success Page</title>
11+
</head>
912
<body>
1013
<referenceBlock name="page.main.title">
1114
<block class="Magento\Checkout\Block\Onepage\Success" name="checkout.success.print.button" template="button.phtml"/>

app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
-->
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
99
<update handle="multishipping_checkout"/>
10+
<head>
11+
<title>Success Page</title>
12+
</head>
1013
<body>
1114
<referenceBlock name="page.main.title">
1215
<action method="setPageTitle">

app/code/Magento/SalesRule/Model/Rule/Action/Discount/ByPercent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ protected function _calculate($rule, $item, $qty, $rulePercent)
5757
$discountData->setAmount(($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct);
5858
$discountData->setBaseAmount(($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct);
5959
$discountData->setOriginalAmount(($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct);
60-
$discountData->setBaseOriginalAmount(($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct);
60+
$discountData->setBaseOriginalAmount(
61+
($qty * $baseItemOriginalPrice - $item->getBaseDiscountAmount()) * $_rulePct
62+
);
6163

6264
if (!$rule->getDiscountQty() || $rule->getDiscountQty() > $qty) {
6365
$discountPercent = min(100, $item->getDiscountPercent() + $rulePercent);
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Controller\Cart;
7+
8+
/**
9+
* Shopping cart edit tests
10+
*/
11+
class ConfigureTest extends \PHPUnit_Framework_TestCase
12+
{
13+
14+
/**
15+
* @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
protected $objectManagerMock;
18+
19+
/**
20+
* @var \Magento\Framework\View\Result\PageFactory | \PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
protected $resultPageFactoryMock;
23+
24+
/**
25+
* @var \Magento\Framework\App\ResponseInterface | \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $responseMock;
28+
29+
/**
30+
* @var \Magento\Framework\App\RequestInterface | \PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $requestMock;
33+
34+
/**
35+
* @var \Magento\Framework\Message\ManagerInterface | \PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $messageManagerMock;
38+
39+
/**
40+
* @var \Magento\Framework\App\Response\RedirectInterface | \PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $redirectMock;
43+
44+
/**
45+
* @var \Magento\Checkout\Controller\Cart\Configure | \PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
protected $configureController;
48+
49+
/**
50+
* @var \Magento\Framework\App\Action\Context | \PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
protected $contextMock;
53+
54+
/**
55+
* @var \Magento\Checkout\Model\Cart | \PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
protected $cartMock;
58+
59+
public function setUp()
60+
{
61+
$eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
62+
->disableOriginalConstructor()
63+
->setMethods([])
64+
->getMockForAbstractClass();
65+
$urlMock = $this->getMockBuilder('Magento\Framework\UrlInterface')
66+
->disableOriginalConstructor()
67+
->setMethods([])
68+
->getMockForAbstractClass();
69+
$actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag')
70+
->disableOriginalConstructor()
71+
->setMethods([])
72+
->getMockForAbstractClass();
73+
$viewMock = $this->getMockBuilder('Magento\Framework\App\ViewInterface')
74+
->disableOriginalConstructor()
75+
->setMethods([])
76+
->getMockForAbstractClass();
77+
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
78+
->disableOriginalConstructor()
79+
->setMethods([])
80+
->getMockForAbstractClass();
81+
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface')
82+
->disableOriginalConstructor()
83+
->setMethods([])
84+
->getMockForAbstractClass();
85+
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
86+
->disableOriginalConstructor()
87+
->setMethods(['getParam'])
88+
->getMockForAbstractClass();
89+
$this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface')
90+
->disableOriginalConstructor()
91+
->setMethods([])
92+
->getMockForAbstractClass();
93+
$this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface')
94+
->disableOriginalConstructor()
95+
->setMethods([])
96+
->getMock();
97+
98+
$this->contextMock = $this->getMockBuilder('Magento\Framework\App\Action\Context')
99+
->setConstructorArgs(
100+
[
101+
$this->requestMock,
102+
$this->responseMock,
103+
$this->objectManagerMock,
104+
$eventManagerMock,
105+
$urlMock,
106+
$this->redirectMock,
107+
$actionFlagMock,
108+
$viewMock,
109+
$this->messageManagerMock
110+
]
111+
)
112+
->setMethods([])
113+
->getMock();
114+
$this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
115+
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
116+
$this->contextMock->expects($this->any())->method('getResponse')->willReturn($this->responseMock);
117+
$this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock);
118+
$this->contextMock->expects($this->any())->method('getRedirect')->willReturn($this->redirectMock);
119+
$scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
120+
->disableOriginalConstructor()
121+
->getMock();
122+
$session = $this->getMockBuilder('Magento\Checkout\Model\Session')
123+
->disableOriginalConstructor()
124+
->getMock();
125+
$storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
126+
->disableOriginalConstructor()
127+
->getMockForAbstractClass();
128+
$formKeyValidator = $this->getMockBuilder('Magento\Core\App\Action\FormKeyValidator')
129+
->disableOriginalConstructor()
130+
->getMockForAbstractClass();
131+
$this->cartMock = $this->getMockBuilder('Magento\Checkout\Model\Cart')
132+
->disableOriginalConstructor()
133+
->getMock();
134+
$this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory')
135+
->disableOriginalConstructor()
136+
->getMock();
137+
138+
$this->configureController = new \Magento\Checkout\Controller\Cart\Configure(
139+
$this->contextMock,
140+
$scopeConfig,
141+
$session,
142+
$storeManager,
143+
$formKeyValidator,
144+
$this->cartMock,
145+
$this->resultPageFactoryMock
146+
);
147+
}
148+
149+
/**
150+
* Test checks controller call product view and send parameter to it
151+
*
152+
* @return void
153+
*/
154+
public function testPrepareAndRenderCall()
155+
{
156+
$quoteId = 1;
157+
$actualProductId = 1;
158+
$quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote')
159+
->disableOriginalConstructor()
160+
->getMock();
161+
$quoteItemMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Item')
162+
->disableOriginalConstructor()
163+
->getMock();
164+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
165+
->disableOriginalConstructor()
166+
->getMock();
167+
$viewMock = $this->getMockBuilder('Magento\Catalog\Helper\Product\View')
168+
->disableOriginalConstructor()
169+
->getMock();
170+
$pageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
171+
->disableOriginalConstructor()
172+
->getMock();
173+
$buyRequestMock = $this->getMockBuilder('Magento\Framework\Object')
174+
->disableOriginalConstructor()
175+
->getMock();
176+
//expects
177+
$this->requestMock->expects($this->at(0))
178+
->method('getParam')
179+
->with('id')
180+
->willReturn($quoteId);
181+
$this->requestMock->expects($this->at(1))
182+
->method('getParam')
183+
->with('product_id')
184+
->willReturn($actualProductId);
185+
$this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
186+
187+
$quoteItemMock->expects($this->exactly(1))->method('getBuyRequest')->willReturn($buyRequestMock);
188+
189+
$this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($pageMock);
190+
$this->objectManagerMock->expects($this->at(0))
191+
->method('get')
192+
->with('Magento\Catalog\Helper\Product\View')
193+
->willReturn($viewMock);
194+
195+
$viewMock->expects($this->once())->method('prepareAndRender')->with(
196+
$pageMock,
197+
$actualProductId,
198+
$this->configureController,
199+
$this->callback(
200+
function ($subject) use ($buyRequestMock) {
201+
return $subject->getBuyRequest() === $buyRequestMock;
202+
}
203+
)
204+
)->willReturn($pageMock);
205+
206+
$quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock);
207+
$quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($productMock);
208+
209+
$productMock->expects($this->exactly(2))->method('getId')->willReturn($actualProductId);
210+
211+
$this->assertSame($pageMock, $this->configureController->execute());
212+
}
213+
214+
/**
215+
* Test checks controller redirect user to cart
216+
* if user request product id in cart edit page is not same as quota product id
217+
*
218+
* @return void
219+
*/
220+
public function testRedirectWithWrongProductId()
221+
{
222+
$quotaId = 1;
223+
$productIdInQuota = 1;
224+
$productIdInRequest = null;
225+
$quoteItemMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Item')
226+
->disableOriginalConstructor()
227+
->getMock();
228+
$quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote')
229+
->disableOriginalConstructor()
230+
->getMock();
231+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
232+
->disableOriginalConstructor()
233+
->getMock();
234+
$this->requestMock->expects($this->at(0))
235+
->method('getParam')
236+
->with('id')
237+
->willReturn($quotaId);
238+
$this->requestMock->expects($this->at(1))
239+
->method('getParam')
240+
->with('product_id')
241+
->willReturn($productIdInRequest);
242+
$this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
243+
$quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock);
244+
$quoteItemMock->expects($this->exactly(1))->method('getProduct')->willReturn($productMock);
245+
$productMock->expects($this->exactly(1))->method('getId')->willReturn($productIdInQuota);
246+
$this->messageManagerMock->expects($this->once())->method('addError');
247+
$this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'checkout/cart', []);
248+
$this->configureController->execute();
249+
}
250+
}

dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ByPercentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function calculateDataProvider()
209209
'amount' => 42,
210210
'baseAmount' => 25.5,
211211
'originalAmount' => 51,
212-
'baseOriginalAmount' => 46.5,
212+
'baseOriginalAmount' => 34.5,
213213
],
214214
]
215215
];

dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ToPercentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function calculateDataProvider()
209209
'amount' => 98,
210210
'baseAmount' => 59.5,
211211
'originalAmount' => 119,
212-
'baseOriginalAmount' => 108.5,
212+
'baseOriginalAmount' => 80.5,
213213
],
214214
]
215215
];

lib/web/mage/adminhtml/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ FormElementDependenceController.prototype = {
458458
}
459459
} else {
460460
$(idTo).show();
461-
if (isAnInputOrSelect) {
461+
if (isAnInputOrSelect && !isInheritCheckboxChecked) {
462462
$(idTo).disabled = false;
463463
jQuery('#' + idTo).removeClass('ignore-validate');
464464
}

0 commit comments

Comments
 (0)