Skip to content

Commit 94bcbc5

Browse files
committed
Merge remote-tracking branch 'origin/MC-19716' into 2.3-develop-pr32
2 parents de0fc3b + 686a71c commit 94bcbc5

File tree

2 files changed

+99
-7
lines changed

2 files changed

+99
-7
lines changed
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
87

9-
class NewActionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
8+
use Magento\Framework\App\Action\HttpPostActionInterface;
9+
use Magento\Rule\Model\Condition\AbstractCondition;
10+
use Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
11+
use Magento\SalesRule\Model\Rule;
12+
13+
/**
14+
* New action html action
15+
*/
16+
class NewActionHtml extends Quote implements HttpPostActionInterface
1017
{
1118
/**
1219
* New action html action
@@ -15,8 +22,10 @@ class NewActionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
1522
*/
1623
public function execute()
1724
{
18-
$id = $this->getRequest()->getParam('id');
19-
$formName = $this->getRequest()->getParam('form');
25+
$id = $this->getRequest()
26+
->getParam('id');
27+
$formName = $this->getRequest()
28+
->getParam('form_namespace');
2029
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
2130
$type = $typeArr[0];
2231

@@ -27,20 +36,22 @@ public function execute()
2736
)->setType(
2837
$type
2938
)->setRule(
30-
$this->_objectManager->create(\Magento\SalesRule\Model\Rule::class)
39+
$this->_objectManager->create(Rule::class)
3140
)->setPrefix(
3241
'actions'
3342
);
3443
if (!empty($typeArr[1])) {
3544
$model->setAttribute($typeArr[1]);
3645
}
3746

38-
if ($model instanceof \Magento\Rule\Model\Condition\AbstractCondition) {
47+
if ($model instanceof AbstractCondition) {
3948
$model->setJsFormObject($formName);
49+
$model->setFormName($formName);
4050
$html = $model->asHtmlRecursive();
4151
} else {
4252
$html = '';
4353
}
44-
$this->getResponse()->setBody($html);
54+
$this->getResponse()
55+
->setBody($html);
4556
}
4657
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
9+
10+
use Magento\TestFramework\TestCase\AbstractBackendController;
11+
12+
/**
13+
* New action html test
14+
*
15+
* @magentoAppArea adminhtml
16+
*/
17+
class NewActionHtmlTest extends AbstractBackendController
18+
{
19+
/**
20+
* @var string
21+
*/
22+
protected $resource = 'Magento_SalesRule::quote';
23+
24+
/**
25+
* @var string
26+
*/
27+
protected $uri = 'backend/sales_rule/promo_quote/newActionHtml';
28+
29+
/**
30+
* @var string
31+
*/
32+
private $formName = 'test_form';
33+
34+
/**
35+
* Test verifies that execute method has the proper data-form-part value in html response
36+
*
37+
* @return void
38+
*/
39+
public function testExecute(): void
40+
{
41+
$this->prepareRequest();
42+
$this->dispatch($this->uri);
43+
$html = $this->getResponse()
44+
->getBody();
45+
$this->assertContains($this->formName, $html);
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function testAclHasAccess()
52+
{
53+
$this->prepareRequest();
54+
parent::testAclHasAccess();
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function testAclNoAccess()
61+
{
62+
$this->prepareRequest();
63+
parent::testAclNoAccess();
64+
}
65+
66+
/**
67+
* Prepare request
68+
*
69+
* @return void
70+
*/
71+
private function prepareRequest(): void
72+
{
73+
$this->getRequest()->setParams(
74+
[
75+
'id' => 1,
76+
'form_namespace' => $this->formName,
77+
'type' => 'Magento\SalesRule\Model\Rule\Condition\Product|quote_item_price',
78+
]
79+
)->setMethod('POST');
80+
}
81+
}

0 commit comments

Comments
 (0)