Skip to content

Commit 6524ee6

Browse files
Merge branch '2.2-develop' of github.com:magento/magento2ce into SPRINT-41
2 parents 9d7ab32 + fd81f51 commit 6524ee6

File tree

19 files changed

+1819
-101
lines changed

19 files changed

+1819
-101
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Email\Model\Mail;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\Exception\MailException;
10+
use Magento\Framework\Mail\TransportInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
/**
14+
* Plugin over \Magento\Framework\Mail\TransportInterface
15+
*
16+
* It disables email sending depending on the system configuration settings
17+
*/
18+
class TransportInterfacePlugin
19+
{
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private $scopeConfig;
24+
25+
/**
26+
* @param ScopeConfigInterface $scopeConfig
27+
*/
28+
public function __construct(
29+
ScopeConfigInterface $scopeConfig
30+
) {
31+
$this->scopeConfig = $scopeConfig;
32+
}
33+
34+
/**
35+
* Omit email sending depending on the system configuration setting
36+
*
37+
* @param TransportInterface $subject
38+
* @param \Closure $proceed
39+
* @return void
40+
* @throws MailException
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function aroundSendMessage(
44+
TransportInterface $subject,
45+
\Closure $proceed
46+
) {
47+
if (!$this->scopeConfig->isSetFlag('system/smtp/disable', ScopeInterface::SCOPE_STORE)) {
48+
$proceed();
49+
}
50+
}
51+
}

app/code/Magento/Email/Model/Template.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Template extends AbstractTemplate implements \Magento\Framework\Mail\Templ
5757
/**
5858
* Config path to mail sending setting that shows if email communications are disabled
5959
* @deprecated
60-
* @see \Magento\Email\Model\Transport::XML_PATH_SYSTEM_SMTP_DISABLE
6160
*/
6261
const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable';
6362

app/code/Magento/Email/Model/Transport.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@
1313

1414
/**
1515
* Class that responsible for filling some message data before transporting it.
16-
* This class checks whether this email should be sent in the first place, based on System Configurations.
1716
* @see Zend_Mail_Transport_Sendmail is used for transport
1817
*/
1918
class Transport implements TransportInterface
2019
{
21-
/**
22-
* Config path to mail sending setting that shows if email communications are disabled
23-
*/
24-
const XML_PATH_SYSTEM_SMTP_DISABLE = 'system/smtp/disable';
25-
2620
/**
2721
* Configuration path to source of Return-Path and whether it should be set at all
2822
* @see \Magento\Config\Model\Config\Source\Yesnocustom to possible values
@@ -85,29 +79,27 @@ public function __construct(
8579
public function sendMessage()
8680
{
8781
try {
88-
if (!$this->scopeConfig->isSetFlag(self::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE)) {
89-
/* configuration of whether return path should be set or no. Possible values are:
90-
* 0 - no
91-
* 1 - yes (set value as FROM address)
92-
* 2 - use custom value
93-
* @see Magento\Config\Model\Config\Source\Yesnocustom
94-
*/
95-
$isSetReturnPath = $this->scopeConfig->getValue(
96-
self::XML_PATH_SENDING_SET_RETURN_PATH,
97-
ScopeInterface::SCOPE_STORE
98-
);
99-
$returnPathValue = $this->scopeConfig->getValue(
100-
self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
101-
ScopeInterface::SCOPE_STORE
102-
);
82+
/* configuration of whether return path should be set or no. Possible values are:
83+
* 0 - no
84+
* 1 - yes (set value as FROM address)
85+
* 2 - use custom value
86+
* @see Magento\Config\Model\Config\Source\Yesnocustom
87+
*/
88+
$isSetReturnPath = $this->scopeConfig->getValue(
89+
self::XML_PATH_SENDING_SET_RETURN_PATH,
90+
ScopeInterface::SCOPE_STORE
91+
);
92+
$returnPathValue = $this->scopeConfig->getValue(
93+
self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
94+
ScopeInterface::SCOPE_STORE
95+
);
10396

104-
if ($isSetReturnPath == '1') {
105-
$this->message->setReturnPath($this->message->getFrom());
106-
} elseif ($isSetReturnPath == '2' && $returnPathValue !== null) {
107-
$this->message->setReturnPath($returnPathValue);
108-
}
109-
$this->transport->send($this->message);
97+
if ($isSetReturnPath == '1') {
98+
$this->message->setReturnPath($this->message->getFrom());
99+
} elseif ($isSetReturnPath == '2' && $returnPathValue !== null) {
100+
$this->message->setReturnPath($returnPathValue);
110101
}
102+
$this->transport->send($this->message);
111103
} catch (\Exception $e) {
112104
throw new MailException(__($e->getMessage()), $e);
113105
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Email\Test\Unit\Model\Mail;
7+
8+
use Magento\Email\Model\Mail\TransportInterfacePlugin;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\Mail\TransportInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
/**
14+
* Covers \Magento\Email\Model\Transport
15+
*/
16+
class TransportInterfacePluginTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* @var TransportInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $transportMock;
22+
23+
/**
24+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $scopeConfigMock;
27+
28+
/**
29+
* @var \Callable|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $proceedMock;
32+
33+
/**
34+
* @var bool
35+
*/
36+
private $isProceedMockCalled = false;
37+
38+
/**
39+
* @var TransportInterfacePlugin
40+
*/
41+
private $model;
42+
43+
protected function setUp()
44+
{
45+
$this->transportMock = $this->createMock(TransportInterface::class);
46+
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
47+
$this->proceedMock = function () {
48+
$this->isProceedMockCalled = true;
49+
};
50+
51+
$this->model = new TransportInterfacePlugin($this->scopeConfigMock);
52+
}
53+
54+
/**
55+
* @dataProvider sendMessageDataProvider
56+
* @param bool $isDisabled
57+
* @param bool $shouldProceedRun
58+
*/
59+
public function testAroundSendMessage(bool $isDisabled, bool $shouldProceedRun)
60+
{
61+
$this->isProceedMockCalled = false;
62+
63+
$this->scopeConfigMock->expects($this->once())
64+
->method('isSetFlag')
65+
->with('system/smtp/disable', ScopeInterface::SCOPE_STORE)
66+
->willReturn($isDisabled);
67+
$this->model->aroundSendMessage($this->transportMock, $this->proceedMock);
68+
$this->assertEquals($shouldProceedRun, $this->isProceedMockCalled);
69+
}
70+
71+
/**
72+
* Data provider for testAroundSendMessage
73+
* @return array
74+
*/
75+
public function sendMessageDataProvider()
76+
{
77+
return [
78+
[false, true],
79+
[true, false],
80+
];
81+
}
82+
}

app/code/Magento/Email/Test/Unit/Model/TransportTest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,11 @@ protected function setUp()
5454
public function testSendMessageException()
5555
{
5656
$this->scopeConfigMock->expects($this->once())
57-
->method('isSetFlag')
57+
->method('getValue')
5858
->willThrowException(new \Exception('some exception'));
5959
$this->model->sendMessage();
6060
}
6161

62-
/**
63-
* Tests that if sending emails is disabled in System Configuration, send nothing
64-
*/
65-
public function testSendMessageSmtpDisabled()
66-
{
67-
$this->scopeConfigMock->expects($this->once())
68-
->method('isSetFlag')
69-
->with(Transport::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE)
70-
->willReturn(true);
71-
$this->transportMock->expects($this->never())
72-
->method('send');
73-
$this->model->sendMessage();
74-
}
75-
7662
/**
7763
* Tests that if sending Return-Path was disabled or email was not provided, - this header won't be set
7864
*
@@ -154,11 +140,6 @@ public function testGetMessage()
154140
*/
155141
private function prepareSendingMessage($returnPathSet, $returnPathEmail)
156142
{
157-
$this->scopeConfigMock->expects($this->once())
158-
->method('isSetFlag')
159-
->with(Transport::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE)
160-
->willReturn(false);
161-
162143
$map = [
163144
[Transport::XML_PATH_SENDING_SET_RETURN_PATH, ScopeInterface::SCOPE_STORE, null, $returnPathSet],
164145
[Transport::XML_PATH_SENDING_RETURN_PATH_EMAIL, ScopeInterface::SCOPE_STORE, null, $returnPathEmail]

app/code/Magento/Email/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</type>
6060
<type name="Magento\Framework\Mail\TransportInterface">
6161
<plugin name="WindowsSmtpConfig" type="Magento\Email\Model\Plugin\WindowsSmtpConfig" />
62+
<plugin name="EmailDisable" type="Magento\Email\Model\Mail\TransportInterfacePlugin" />
6263
</type>
6364
<type name="Magento\Config\Model\Config\TypePool">
6465
<arguments>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Util\Command\Cli;
8+
9+
use Magento\Mtf\Util\Command\Cli;
10+
11+
/**
12+
* Setup Magento for tests executions.
13+
*/
14+
class DeployMode extends Cli
15+
{
16+
/**
17+
* Parameter for Magento command to set the deploy mode
18+
*/
19+
const PARAM_DEPLOY_MODE_DEVELOPER = 'deploy:mode:set developer';
20+
21+
/**
22+
* Parameter for Magento command to set the deploy mode to Production
23+
*/
24+
const PARAM_DEPLOY_MODE_PRODUCTION = 'deploy:mode:set production';
25+
26+
/**
27+
* set the deployment mode to developer
28+
*
29+
* @return void
30+
*/
31+
public function setDeployModeToDeveloper()
32+
{
33+
parent::execute(DeployMode::PARAM_DEPLOY_MODE_DEVELOPER);
34+
}
35+
36+
/**
37+
* set the deployment mode to production
38+
*
39+
* @return void
40+
*/
41+
public function setDeployModeToProduction()
42+
{
43+
parent::execute(DeployMode::PARAM_DEPLOY_MODE_PRODUCTION);
44+
}
45+
}

dev/tests/functional/tests/app/Magento/Backend/Test/Repository/ConfigData.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@
183183
<item name="value" xsi:type="number">1</item>
184184
</field>
185185
</dataset>
186+
187+
<dataset name="minify_js_files">
188+
<field name="dev/js/minify_files" xsi:type="array">
189+
<item name="scope" xsi:type="string">default</item>
190+
<item name="scope_id" xsi:type="number">0</item>
191+
<item name="label" xsi:type="string">Yes</item>
192+
<item name="value" xsi:type="number">1</item>
193+
</field>
194+
</dataset>
186195

187196
<dataset name="enable_https_frontend_admin">
188197
<field name="web/secure/use_in_frontend" xsi:type="array">
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\TestCase;
7+
8+
use Magento\Mtf\TestCase\Injectable;
9+
use Magento\Backend\Test\Page\Adminhtml\Dashboard;
10+
use Magento\Mtf\Util\Command\Cli\DeployMode;
11+
use Magento\Mtf\TestStep\TestStepFactory;
12+
13+
/**
14+
* Verify visibility of form elements on Configuration page.
15+
*
16+
* @ZephyrId MAGETWO-71416
17+
*/
18+
class LoginAfterJSMinificationTest extends Injectable
19+
{
20+
21+
/**
22+
* Admin dashboard page
23+
* @var Dashboard
24+
*/
25+
private $adminDashboardPage;
26+
27+
/**
28+
* Factory for Test Steps.
29+
*
30+
* @var TestStepFactory
31+
*/
32+
private $stepFactory;
33+
34+
/**
35+
* Configuration setting.
36+
*
37+
* @var string
38+
*/
39+
private $configData;
40+
41+
/**
42+
* Prepare data for further test execution.
43+
*
44+
* @param Dashboard $adminDashboardPage
45+
* @return void
46+
*/
47+
public function __inject(
48+
Dashboard $adminDashboardPage,
49+
TestStepFactory $stepFactory
50+
) {
51+
$this->adminDashboardPage = $adminDashboardPage;
52+
$this->stepFactory = $stepFactory;
53+
}
54+
55+
/**
56+
* Admin login test after JS minification is turned on in production mode
57+
* @param DeployMode $cli
58+
* @param null $configData
59+
* @return void
60+
*/
61+
public function test(
62+
DeployMode $cli,
63+
$configData = null
64+
) {
65+
$this->configData = $configData;
66+
67+
//Pre-conditions
68+
$cli->setDeployModeToDeveloper();
69+
$this->objectManager->create(
70+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
71+
['configData' => $this->configData]
72+
)->run();
73+
74+
// Steps
75+
$cli->setDeployModeToProduction();
76+
$this->adminDashboardPage->open();
77+
}
78+
}

0 commit comments

Comments
 (0)