Skip to content

Commit ea9da45

Browse files
merge magento/2.2.10-develop into magento-trigger/MC-18831
2 parents 711ea5d + 5b1f11f commit ea9da45

File tree

28 files changed

+670
-78
lines changed

28 files changed

+670
-78
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
970970
null,
971971
$extensions
972972
);
973+
$customer->setConfirmation(null);
973974
} catch (MailException $e) {
974975
// If we are not able to send a new account email, this should be ignored
975976
$this->logger->critical($e);

app/code/Magento/Downloadable/Controller/Adminhtml/Downloadable/File/Upload.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\MediaStorage\Helper\File\Storage\Database;
1818
use Magento\Framework\App\RequestInterface;
1919
use Magento\Framework\App\State;
20+
use Magento\Framework\Exception\FileSystemException;
21+
use Magento\Framework\Exception\LocalizedException;
2022

2123
/**
2224
* Upload controller
@@ -109,23 +111,27 @@ public function dispatch(RequestInterface $request)
109111
*/
110112
public function execute()
111113
{
112-
$type = $this->getRequest()->getParam('type');
113-
$tmpPath = '';
114-
if ($type == 'samples') {
115-
$tmpPath = $this->_sample->getBaseTmpPath();
116-
} elseif ($type == 'links') {
117-
$tmpPath = $this->_link->getBaseTmpPath();
118-
} elseif ($type == 'link_samples') {
119-
$tmpPath = $this->_link->getBaseSampleTmpPath();
120-
}
121-
122114
try {
115+
$type = $this->getRequest()->getParam('type');
116+
$tmpPath = '';
117+
if ($type === 'samples') {
118+
$tmpPath = $this->_sample->getBaseTmpPath();
119+
} elseif ($type === 'links') {
120+
$tmpPath = $this->_link->getBaseTmpPath();
121+
} elseif ($type === 'link_samples') {
122+
$tmpPath = $this->_link->getBaseSampleTmpPath();
123+
} else {
124+
throw new LocalizedException(__('Upload type can not be determined.'));
125+
}
126+
123127
$uploader = $this->uploaderFactory->create(['fileId' => $type]);
124128

125129
$result = $this->_fileHelper->uploadFromTmp($tmpPath, $uploader);
126130

127131
if (!$result) {
128-
throw new \Exception('File can not be moved from temporary folder to the destination folder.');
132+
throw new FileSystemException(
133+
__('File can not be moved from temporary folder to the destination folder.')
134+
);
129135
}
130136

131137
unset($result['tmp_name'], $result['path']);
@@ -137,6 +143,7 @@ public function execute()
137143
} catch (\Exception $e) {
138144
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
139145
}
146+
140147
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
141148
}
142149
}

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Magento\Eav\Model\Entity\Attribute as EntityAttribute;
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\DB\Select;
13+
use Magento\Framework\Exception\CouldNotDeleteException;
1314
use Magento\Framework\Model\AbstractModel;
15+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1416

1517
/**
1618
* EAV attribute resource model
@@ -19,7 +21,7 @@
1921
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2022
* @since 100.0.2
2123
*/
22-
class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
24+
class Attribute extends AbstractDb
2325
{
2426
/**
2527
* Eav Entity attributes cache
@@ -188,6 +190,23 @@ protected function _beforeSave(AbstractModel $object)
188190
return parent::_beforeSave($object);
189191
}
190192

193+
/**
194+
* @inheritdoc
195+
*
196+
* @param AbstractModel $attribute
197+
* @return AbstractDb
198+
* @throws CouldNotDeleteException
199+
*/
200+
protected function _beforeDelete(AbstractModel $attribute)
201+
{
202+
/** @var $attribute \Magento\Eav\Api\Data\AttributeInterface */
203+
if ($attribute->getId() && !$attribute->getIsUserDefined()) {
204+
throw new CouldNotDeleteException(__("The system attribute can't be deleted."));
205+
}
206+
207+
return parent::_beforeDelete($attribute);
208+
}
209+
191210
/**
192211
* Save additional attribute data after save attribute
193212
*

app/code/Magento/Email/Block/Adminhtml/Template/Preview.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Adminhtml system template preview block
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
11-
*/
127
namespace Magento\Email\Block\Adminhtml\Template;
138

149
/**
@@ -56,6 +51,7 @@ public function __construct(
5651
*
5752
* @return string
5853
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
54+
* @throws \Exception
5955
*/
6056
protected function _toHtml()
6157
{

app/code/Magento/Email/Controller/Adminhtml/Email/Template/Popup.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function __construct(
4545
*/
4646
public function execute()
4747
{
48+
if (!$this->getRequest()->isPost()) {
49+
$this->_forward('noroute');
50+
return;
51+
}
52+
4853
return $this->resultPageFactory->create();
4954
}
5055
}

app/code/Magento/Email/Controller/Adminhtml/Email/Template/Preview.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Email\Controller\Adminhtml\Email\Template;
87

8+
use Magento\Email\Controller\Adminhtml\Email\Template;
9+
910
/**
1011
* Rendering email template preview.
1112
*/
12-
class Preview extends \Magento\Email\Controller\Adminhtml\Email\Template
13+
class Preview extends Template
1314
{
1415
/**
1516
* Preview transactional email action.
16-
*
17-
* @return void
1817
*/
1918
public function execute()
2019
{
2120
try {
2221
$this->_view->loadLayout();
2322
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Email Preview'));
2423
$this->_view->renderLayout();
25-
$this->getResponse()->setHeader('Content-Security-Policy', "script-src 'self'");
2624
} catch (\Exception $e) {
2725
$this->messageManager->addErrorMessage(
2826
__('An error occurred. The email template can not be opened for preview.')

app/code/Magento/Email/Test/Unit/Controller/Adminhtml/Email/Template/PreviewTest.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class PreviewTest extends \PHPUnit\Framework\TestCase
6060
*/
6161
private $pageTitleMock;
6262

63-
/**
64-
* @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
65-
*/
66-
private $responseMock;
67-
6863
/**
6964
* @inheritdoc
7065
*/
@@ -93,16 +88,11 @@ protected function setUp()
9388
->disableOriginalConstructor()
9489
->getMock();
9590

96-
$this->responseMock = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)
97-
->setMethods(['setHeader'])
98-
->getMockForAbstractClass();
99-
10091
$this->context = $objectManager->getObject(
10192
\Magento\Backend\App\Action\Context::class,
10293
[
10394
'request' => $this->requestMock,
104-
'view' => $this->viewMock,
105-
'response' => $this->responseMock,
95+
'view' => $this->viewMock
10696
]
10797
);
10898
$this->object = $objectManager->getObject(
@@ -131,9 +121,6 @@ public function testExecute()
131121
$this->pageTitleMock->expects($this->once())
132122
->method('prepend')
133123
->willReturnSelf();
134-
$this->responseMock->expects($this->once())
135-
->method('setHeader')
136-
->with('Content-Security-Policy', "script-src 'self'");
137124

138125
$this->assertNull($this->object->execute());
139126
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Email\Test\Unit\ViewModel\Template\Preview;
8+
9+
use Magento\Email\ViewModel\Template\Preview\Form;
10+
use Magento\Framework\App\Request\Http;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
14+
/**
15+
* Class FormTest
16+
*
17+
* @covers \Magento\Email\ViewModel\Template\Preview\Form
18+
*/
19+
class FormTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/** @var Form */
22+
protected $form;
23+
24+
/** @var Http|\PHPUnit_Framework_MockObject_MockObject */
25+
protected $requestMock;
26+
27+
protected function setUp()
28+
{
29+
$this->requestMock = $this->createPartialMock(
30+
Http::class,
31+
['getParam', 'getMethod']
32+
);
33+
34+
$objectManagerHelper = new ObjectManager($this);
35+
36+
$this->form = $objectManagerHelper->getObject(
37+
Form::class,
38+
['request' => $this->requestMock]
39+
);
40+
}
41+
42+
/**
43+
* Tests that the form is created with the expected fields based on the request type.
44+
*
45+
* @dataProvider getFormFieldsDataProvider
46+
* @param string $httpMethod
47+
* @param array $httpParams
48+
* @param array $expectedFields
49+
* @throws LocalizedException
50+
*/
51+
public function testGetFormFields(string $httpMethod, array $httpParams, array $expectedFields)
52+
{
53+
$this->requestMock->expects($this->once())
54+
->method('getMethod')
55+
->willReturn($httpMethod);
56+
57+
$this->requestMock->expects($this->any())
58+
->method('getParam')
59+
->willReturnMap($httpParams);
60+
61+
$actualFields = $this->form->getFormFields();
62+
63+
$this->assertEquals($expectedFields, $actualFields);
64+
}
65+
66+
/**
67+
* Tests that an exception is thrown when a required parameter is missing for the request type.
68+
*
69+
* @dataProvider getFormFieldsInvalidDataProvider
70+
* @expectedException \Magento\Framework\Exception\LocalizedException
71+
* @expectedExceptionMessage Missing expected parameter
72+
* @param string $httpMethod
73+
* @param array $httpParams
74+
*/
75+
public function testGetFormFieldsMissingParameter(string $httpMethod, array $httpParams)
76+
{
77+
$this->requestMock->expects($this->once())
78+
->method('getMethod')
79+
->willReturn($httpMethod);
80+
81+
$this->requestMock->expects($this->once())
82+
->method('getParam')
83+
->willReturnMap($httpParams);
84+
85+
$this->form->getFormFields();
86+
}
87+
88+
/**
89+
* @return array
90+
*/
91+
public function getFormFieldsDataProvider()
92+
{
93+
return [
94+
'get_request_valid' => [
95+
'httpMethod' => 'GET',
96+
'httpParams' => [
97+
['id', null, 1]
98+
],
99+
'expectedFields' => [
100+
'id' => 1
101+
]
102+
],
103+
'get_request_valid_ignore_params' => [
104+
'httpMethod' => 'GET',
105+
'httpParams' => [
106+
['id', null, 1],
107+
['text', null, 'Hello World'],
108+
['type', null, 2],
109+
['styles', null, '']
110+
],
111+
'expectedFields' => [
112+
'id' => 1
113+
]
114+
],
115+
'post_request_valid' => [
116+
'httpMethod' => 'POST',
117+
'httpParams' => [
118+
['text', null, 'Hello World'],
119+
['type', null, 2],
120+
['styles', null, '']
121+
],
122+
'expectedFields' => [
123+
'text' => 'Hello World',
124+
'type' => 2,
125+
'styles' => ''
126+
]
127+
]
128+
];
129+
}
130+
131+
/**
132+
* @return array
133+
*/
134+
public function getFormFieldsInvalidDataProvider()
135+
{
136+
return [
137+
'get_request_missing_id' => [
138+
'httpMethod' => 'GET',
139+
'httpParams' => [
140+
['text', null, 'Hello World'],
141+
['type', null, 2],
142+
['styles', null, '']
143+
]
144+
],
145+
'post_request_missing_text' => [
146+
'httpMethod' => 'POST',
147+
'httpParams' => [
148+
['type', null, 2],
149+
['styles', null, '']
150+
]
151+
]
152+
];
153+
}
154+
}

0 commit comments

Comments
 (0)