Skip to content

Commit 9bc0af1

Browse files
Merge pull request #2454 from magento-qwerty/MAGETWO-71381-2
Fixed issues: - MAGETWO-71381: Widget tied with cart price rule displays even when rule was not applied
2 parents 90839c1 + 108cb64 commit 9bc0af1

File tree

5 files changed

+121
-5
lines changed

5 files changed

+121
-5
lines changed

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/DiscountCodes.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ class DiscountCodes extends Form
3737
protected $couponCode = '#coupon_code';
3838

3939
/**
40-
* Click apply button selector
40+
* Locator for "Apply Discount" button.
4141
*
4242
* @var string
4343
*/
4444
protected $applyButton = '.action.apply';
4545

4646
/**
47-
* Enter discount code and click apply button
47+
* Locator for "Cancel Coupon" button.
48+
*
49+
* @var string
50+
*/
51+
protected $cancelButton = '.action.cancel';
52+
53+
/**
54+
* Enter Discount Code and click "Apply Discount" button.
4855
*
4956
* @param string $code
5057
* @return void
@@ -57,4 +64,17 @@ public function applyCouponCode($code)
5764
$this->_rootElement->find($this->couponCode, Locator::SELECTOR_CSS)->setValue($code);
5865
$this->_rootElement->find($this->applyButton, Locator::SELECTOR_CSS)->click();
5966
}
67+
68+
/**
69+
* Click "Cancel Coupon" button.
70+
*
71+
* @return void
72+
*/
73+
public function cancelCouponCode()
74+
{
75+
if (!$this->_rootElement->find($this->formWrapper)->isVisible()) {
76+
$this->_rootElement->find($this->openForm)->click();
77+
}
78+
$this->_rootElement->find($this->cancelButton)->click();
79+
}
6080
}

dev/tests/functional/tests/app/Magento/SalesRule/Test/TestStep/ApplySalesRuleOnFrontendStep.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@ class ApplySalesRuleOnFrontendStep implements TestStepInterface
2929
*/
3030
protected $salesRule;
3131

32+
/**
33+
* Sales Rule Discount Code.
34+
*
35+
* @var SalesRule
36+
*/
37+
protected $couponCode;
38+
3239
/**
3340
* @constructor
3441
* @param CheckoutCart $checkoutCart
3542
* @param SalesRule $salesRule
43+
* @param string $couponCode
3644
*/
37-
public function __construct(CheckoutCart $checkoutCart, SalesRule $salesRule = null)
45+
public function __construct(CheckoutCart $checkoutCart, SalesRule $salesRule = null, $couponCode = null)
3846
{
3947
$this->checkoutCart = $checkoutCart;
4048
$this->salesRule = $salesRule;
49+
$this->couponCode = $couponCode;
4150
}
4251

4352
/**
@@ -51,5 +60,10 @@ public function run()
5160
$this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($this->salesRule->getCouponCode());
5261
$this->checkoutCart->getTotalsBlock()->waitForUpdatedTotals();
5362
}
63+
64+
if ($this->couponCode !== null) {
65+
$this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($this->couponCode);
66+
$this->checkoutCart->getTotalsBlock()->waitForUpdatedTotals();
67+
}
5468
}
5569
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SalesRule\Test\TestStep;
8+
9+
use Magento\Checkout\Test\Page\CheckoutCart;
10+
use Magento\Mtf\TestStep\TestStepInterface;
11+
12+
/**
13+
* Cancel Sales Rule before one page checkout.
14+
*/
15+
class CancelSalesRuleOnFrontendStep implements TestStepInterface
16+
{
17+
/**
18+
* Checkout cart page.
19+
*
20+
* @var CheckoutCart
21+
*/
22+
protected $checkoutCart;
23+
24+
/**
25+
* @constructor
26+
* @param CheckoutCart $checkoutCart
27+
*/
28+
public function __construct(CheckoutCart $checkoutCart)
29+
{
30+
$this->checkoutCart = $checkoutCart;
31+
}
32+
33+
/**
34+
* Apply coupon before one page checkout.
35+
*
36+
* @return void
37+
*/
38+
public function run()
39+
{
40+
$this->checkoutCart->getDiscountCodesBlock()->cancelCouponCode();
41+
$this->checkoutCart->getTotalsBlock()->waitForUpdatedTotals();
42+
}
43+
}

dev/tests/functional/tests/app/Magento/Widget/Test/Block/Adminhtml/Widget/Instance/Edit/Tab/WidgetInstanceType/GenericPages.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<selector>.page_group_select</selector>
1212
<input>optgroupselect</input>
1313
</page_group>
14+
<layout_handle>
15+
<selector>#layout_handle</selector>
16+
<input>select</input>
17+
</layout_handle>
1418
<block>
1519
<selector>.block_reference select</selector>
1620
<input>select</input>

dev/tests/functional/tests/app/Magento/Widget/Test/TestCase/AbstractCreateWidgetEntityTest.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@
66

77
namespace Magento\Widget\Test\TestCase;
88

9+
use Magento\Mtf\TestStep\TestStepFactory;
910
use Magento\Widget\Test\Fixture\Widget;
1011
use Magento\Widget\Test\Page\Adminhtml\WidgetInstanceEdit;
1112
use Magento\Widget\Test\Page\Adminhtml\WidgetInstanceIndex;
1213
use Magento\Widget\Test\Page\Adminhtml\WidgetInstanceNew;
1314
use Magento\Mtf\TestCase\Injectable;
15+
use Magento\PageCache\Test\Page\Adminhtml\AdminCache;
1416

1517
/**
1618
* Test Creation for New Instance of WidgetEntity.
1719
*/
1820
abstract class AbstractCreateWidgetEntityTest extends Injectable
1921
{
22+
/**
23+
* Factory for Test Steps.
24+
*
25+
* @var TestStepFactory
26+
*/
27+
protected $testStep;
28+
2029
/**
2130
* WidgetInstanceIndex page.
2231
*
@@ -38,31 +47,57 @@ abstract class AbstractCreateWidgetEntityTest extends Injectable
3847
*/
3948
protected $widgetInstanceEdit;
4049

50+
/**
51+
* "Cache Management" Admin panel page.
52+
*
53+
* @var AdminCache
54+
*/
55+
protected $cachePage;
56+
4157
/**
4258
* Injection data.
4359
*
4460
* @param WidgetInstanceIndex $widgetInstanceIndex
4561
* @param WidgetInstanceNew $widgetInstanceNew
4662
* @param WidgetInstanceEdit $widgetInstanceEdit
63+
* @param AdminCache $adminCache
64+
* @param TestStepFactory $testStepFactory
4765
* @return void
4866
*/
4967
public function __inject(
5068
WidgetInstanceIndex $widgetInstanceIndex,
5169
WidgetInstanceNew $widgetInstanceNew,
52-
WidgetInstanceEdit $widgetInstanceEdit
70+
WidgetInstanceEdit $widgetInstanceEdit,
71+
AdminCache $adminCache,
72+
TestStepFactory $testStepFactory
5373
) {
5474
$this->widgetInstanceIndex = $widgetInstanceIndex;
5575
$this->widgetInstanceNew = $widgetInstanceNew;
5676
$this->widgetInstanceEdit = $widgetInstanceEdit;
77+
$this->cachePage = $adminCache;
78+
$this->testStep = $testStepFactory;
5779
}
5880

5981
/**
60-
* Delete all widgets.
82+
* Delete all Widgets & flush the Cache.
6183
*
6284
* @return void
6385
*/
6486
public function tearDown()
6587
{
6688
$this->objectManager->create('Magento\Widget\Test\TestStep\DeleteAllWidgetsStep')->run();
89+
$this->flushCache();
90+
}
91+
92+
/**
93+
* Flush Magento Cache in Admin panel.
94+
*
95+
* @return void
96+
*/
97+
protected function flushCache()
98+
{
99+
$this->cachePage->open();
100+
$this->cachePage->getActionsBlock()->flushMagentoCache();
101+
$this->cachePage->getMessagesBlock()->waitSuccessMessage();
67102
}
68103
}

0 commit comments

Comments
 (0)