Skip to content

Commit c86d777

Browse files
authored
Merge pull request #771 from magento-south/BUGS
[SOUTH] Bugs: - MAGETWO-61873 Customer email Enumeration through frontend login - MAGETWO-58796 CMS Hierarchy menu is not shown when adding a page to hierarchy (when URL rewrite for new page exists) - MAGETWO-62916 [GITHUB] Added fr_CH to allowed locales list #8019
2 parents d166004 + 861c3e8 commit c86d777

File tree

12 files changed

+374
-88
lines changed

12 files changed

+374
-88
lines changed

app/code/Magento/Cms/Helper/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function prepareResultPage(Action $action, $pageId = null)
156156

157157
$this->_eventManager->dispatch(
158158
'cms_page_render',
159-
['page' => $this->_page, 'controller_action' => $action]
159+
['page' => $this->_page, 'controller_action' => $action, 'request' => $this->_getRequest()]
160160
);
161161

162162
if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Test\Unit\Controller;
7+
8+
/**
9+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10+
*/
11+
class RouterTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Cms\Controller\Router
15+
*/
16+
private $router;
17+
18+
/**
19+
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $eventManagerMock;
22+
23+
/**
24+
* @var \Magento\Cms\Model\PageFactory|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $pageFactoryMock;
27+
28+
/**
29+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $storeManagerMock;
32+
33+
/**
34+
* @var \Magento\Store\Api\Data\StoreInterface|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $storeMock;
37+
38+
/**
39+
* @var \Magento\Framework\App\ActionFactory|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $actionFactoryMock;
42+
43+
protected function setUp()
44+
{
45+
$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
46+
->getMockForAbstractClass();
47+
48+
$this->pageFactoryMock = $this->getMockBuilder(\Magento\Cms\Model\PageFactory::class)
49+
->disableOriginalConstructor()
50+
->setMethods(['create'])
51+
->getMock();
52+
53+
$this->storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
54+
->getMockForAbstractClass();
55+
56+
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
57+
->getMockForAbstractClass();
58+
$this->storeManagerMock->expects($this->any())
59+
->method('getStore')
60+
->willReturn($this->storeMock);
61+
62+
$this->actionFactoryMock = $this->getMockBuilder(\Magento\Framework\App\ActionFactory::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
66+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
67+
$this->router = $objectManagerHelper->getObject(
68+
\Magento\Cms\Controller\Router::class,
69+
[
70+
'eventManager' => $this->eventManagerMock,
71+
'pageFactory' => $this->pageFactoryMock,
72+
'storeManager' => $this->storeManagerMock,
73+
'actionFactory' => $this->actionFactoryMock,
74+
]
75+
);
76+
}
77+
78+
public function testMatchCmsControllerRouterMatchBeforeEventParams()
79+
{
80+
$identifier = '/test';
81+
$trimedIdentifier = 'test';
82+
$pageId = 1;
83+
$storeId = 1;
84+
85+
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject $requestMock */
86+
$requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
87+
->setMethods([
88+
'getPathInfo',
89+
'setModuleName',
90+
'setControllerName',
91+
'setActionName',
92+
'setParam',
93+
'setAlias',
94+
])
95+
->getMockForAbstractClass();
96+
$requestMock->expects($this->once())
97+
->method('getPathInfo')
98+
->willReturn($identifier);
99+
$requestMock->expects($this->once())
100+
->method('setModuleName')
101+
->with('cms')
102+
->willReturnSelf();
103+
$requestMock->expects($this->once())
104+
->method('setControllerName')
105+
->with('page')
106+
->willReturnSelf();
107+
$requestMock->expects($this->once())
108+
->method('setActionName')
109+
->with('view')
110+
->willReturnSelf();
111+
$requestMock->expects($this->once())
112+
->method('setParam')
113+
->with('page_id', $pageId)
114+
->willReturnSelf();
115+
$requestMock->expects($this->once())
116+
->method('setAlias')
117+
->with(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $trimedIdentifier)
118+
->willReturnSelf();
119+
120+
$condition = new \Magento\Framework\DataObject(['identifier' => $trimedIdentifier, 'continue' => true]);
121+
122+
$this->eventManagerMock->expects($this->once())
123+
->method('dispatch')
124+
->with(
125+
'cms_controller_router_match_before',
126+
[
127+
'router' => $this->router,
128+
'condition' => $condition,
129+
]
130+
)
131+
->willReturnSelf();
132+
133+
$pageMock = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
134+
->disableOriginalConstructor()
135+
->getMock();
136+
$pageMock->expects($this->once())
137+
->method('checkIdentifier')
138+
->with($trimedIdentifier, $storeId)
139+
->willReturn($pageId);
140+
141+
$this->pageFactoryMock->expects($this->once())
142+
->method('create')
143+
->willReturn($pageMock);
144+
145+
$this->storeMock->expects($this->once())
146+
->method('getId')
147+
->willReturn($storeId);
148+
149+
$actionMock = $this->getMockBuilder(\Magento\Framework\App\ActionInterface::class)
150+
->getMockForAbstractClass();
151+
152+
$this->actionFactoryMock->expects($this->once())
153+
->method('create')
154+
->with(\Magento\Framework\App\Action\Forward::class)
155+
->willReturn($actionMock);
156+
157+
$this->assertEquals($actionMock, $this->router->match($requestMock));
158+
}
159+
}

app/code/Magento/Cms/Test/Unit/Helper/PageTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class PageTest extends \PHPUnit_Framework_TestCase
113113
*/
114114
protected $resultPageFactory;
115115

116+
/**
117+
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
118+
*/
119+
private $httpRequestMock;
120+
116121
protected function setUp()
117122
{
118123
$this->actionMock = $this->getMockBuilder(\Magento\Framework\App\Action\Action::class)
@@ -157,6 +162,8 @@ protected function setUp()
157162
->getMockForAbstractClass();
158163
$this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
159164
->getMockForAbstractClass();
165+
$this->httpRequestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
166+
->getMockForAbstractClass();
160167
$this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
161168
->disableOriginalConstructor()
162169
->getMock();
@@ -184,7 +191,8 @@ protected function setUp()
184191
\Magento\Framework\App\Helper\Context::class,
185192
[
186193
'eventManager' => $this->eventManagerMock,
187-
'urlBuilder' => $this->urlBuilderMock
194+
'urlBuilder' => $this->urlBuilderMock,
195+
'httpRequest' => $this->httpRequestMock,
188196
]
189197
);
190198

@@ -318,7 +326,8 @@ public function testPrepareResultPage(
318326
'cms_page_render',
319327
[
320328
'page' => $this->pageMock,
321-
'controller_action' => $this->actionMock
329+
'controller_action' => $this->actionMock,
330+
'request' => $this->httpRequestMock,
322331
]
323332
);
324333
$this->pageMock->expects($this->any())

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class EditPost extends \Magento\Customer\Controller\AbstractAccount
6060
/** @var EmailNotificationInterface */
6161
private $emailNotification;
6262

63-
/**
64-
* @var ScopeConfigInterface
65-
*/
66-
private $scopeConfig;
67-
6863
/**
6964
* @var AuthenticationInterface
7065
*/
@@ -171,8 +166,7 @@ public function execute()
171166
$this->messageManager->addError($e->getMessage());
172167
} catch (UserLockedException $e) {
173168
$message = __(
174-
'The account is locked. Please wait and try again or contact %1.',
175-
$this->getScopeConfig()->getValue('contact/email/recipient_email')
169+
'You did not sign in correctly or your account is temporarily disabled.'
176170
);
177171
$this->session->logout();
178172
$this->session->start();
@@ -195,22 +189,6 @@ public function execute()
195189
return $resultRedirect->setPath('*/*/edit');
196190
}
197191

198-
/**
199-
* Get scope config
200-
*
201-
* @return ScopeConfigInterface
202-
*/
203-
private function getScopeConfig()
204-
{
205-
if (!($this->scopeConfig instanceof \Magento\Framework\App\Config\ScopeConfigInterface)) {
206-
return ObjectManager::getInstance()->get(
207-
\Magento\Framework\App\Config\ScopeConfigInterface::class
208-
);
209-
} else {
210-
return $this->scopeConfig;
211-
}
212-
}
213-
214192
/**
215193
* Account editing action completed successfully event
216194
*

app/code/Magento/Customer/Controller/Account/LoginPost.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ public function execute()
171171
$this->session->setUsername($login['username']);
172172
} catch (UserLockedException $e) {
173173
$message = __(
174-
'The account is locked. Please wait and try again or contact %1.',
175-
$this->getScopeConfig()->getValue('contact/email/recipient_email')
174+
'You did not sign in correctly or your account is temporarily disabled.'
176175
);
177176
$this->messageManager->addError($message);
178177
$this->session->setUsername($login['username']);
179178
} catch (AuthenticationException $e) {
180-
$message = __('Invalid login or password.');
179+
$message = __('You did not sign in correctly or your account is temporarily disabled.');
181180
$this->messageManager->addError($message);
182181
$this->session->setUsername($login['username']);
183182
} catch (LocalizedException $e) {

app/code/Magento/Customer/Test/Unit/Controller/Account/EditPostTest.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\Customer\Model\EmailNotificationInterface;
1313
use Magento\Customer\Model\Session;
1414
use Magento\Framework\App\Action\Context;
15-
use Magento\Framework\App\Config\ScopeConfigInterface;
1615
use Magento\Framework\App\Request\Http;
1716
use Magento\Framework\Controller\Result\Redirect;
1817
use Magento\Framework\Controller\Result\RedirectFactory;
@@ -127,13 +126,6 @@ protected function setUp()
127126
->disableOriginalConstructor()
128127
->getMock();
129128

130-
$scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
131-
->disableOriginalConstructor()
132-
->getMock();
133-
$scopeConfigMock->expects($this->any())
134-
->method('getValue')
135-
->willReturn('test@host.com');
136-
137129
$this->authenticationMock = $this->getMockBuilder(AuthenticationInterface::class)
138130
->disableOriginalConstructor()
139131
->getMock();
@@ -157,11 +149,7 @@ protected function setUp()
157149
'emailNotification',
158150
$this->emailNotification
159151
);
160-
$objectManager->setBackwardCompatibleProperty(
161-
$this->model,
162-
'scopeConfig',
163-
$scopeConfigMock
164-
);
152+
165153
$objectManager->setBackwardCompatibleProperty(
166154
$this->model,
167155
'authentication',
@@ -216,7 +204,6 @@ public function testGeneralSave()
216204

217205
$address = $this->getMockBuilder(\Magento\Customer\Api\Data\AddressInterface::class)
218206
->getMockForAbstractClass();
219-
220207
$currentCustomerMock = $this->getCurrentCustomerMock($customerId, $address);
221208
$newCustomerMock = $this->getNewCustomerMock($customerId, $address);
222209

@@ -412,7 +399,7 @@ public function changeEmailExceptionDataProvider()
412399
[
413400
'testNumber' => 2,
414401
'exceptionClass' => \Magento\Framework\Exception\State\UserLockedException::class,
415-
'errorMessage' => __('The account is locked. Please wait and try again or contact %1.', 'test@host.com')
402+
'errorMessage' => __('You did not sign in correctly or your account is temporarily disabled.')
416403
]
417404
];
418405
}

app/code/Magento/Customer/Test/Unit/Controller/Account/LoginPostTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ protected function prepareContext()
536536
protected function mockExceptions($exception, $username)
537537
{
538538
$url = 'url1';
539-
$email = 'hello@example.com';
540539

541540
switch ($exception) {
542541
case \Magento\Framework\Exception\EmailNotConfirmedException::class:
@@ -564,7 +563,7 @@ protected function mockExceptions($exception, $username)
564563
case \Magento\Framework\Exception\AuthenticationException::class:
565564
$this->messageManager->expects($this->once())
566565
->method('addError')
567-
->with(__('Invalid login or password.'))
566+
->with(__('You did not sign in correctly or your account is temporarily disabled.'))
568567
->willReturnSelf();
569568

570569
$this->session->expects($this->once())
@@ -581,10 +580,8 @@ protected function mockExceptions($exception, $username)
581580
break;
582581

583582
case \Magento\Framework\Exception\State\UserLockedException::class:
584-
$this->scopeConfig->expects($this->once())->method('getValue')->willReturn($email);
585583
$message = __(
586-
'The account is locked. Please wait and try again or contact %1.',
587-
$email
584+
'You did not sign in correctly or your account is temporarily disabled.'
588585
);
589586
$this->messageManager->expects($this->once())
590587
->method('addError')

0 commit comments

Comments
 (0)