Skip to content

Commit

Permalink
Merge pull request #771 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
slavvka authored Jan 24, 2017
2 parents d166004 + 861c3e8 commit c86d777
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 88 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Cms/Helper/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function prepareResultPage(Action $action, $pageId = null)

$this->_eventManager->dispatch(
'cms_page_render',
['page' => $this->_page, 'controller_action' => $action]
['page' => $this->_page, 'controller_action' => $action, 'request' => $this->_getRequest()]
);

if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {
Expand Down
159 changes: 159 additions & 0 deletions app/code/Magento/Cms/Test/Unit/Controller/RouterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Test\Unit\Controller;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class RouterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Cms\Controller\Router
*/
private $router;

/**
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $eventManagerMock;

/**
* @var \Magento\Cms\Model\PageFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $pageFactoryMock;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

/**
* @var \Magento\Store\Api\Data\StoreInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeMock;

/**
* @var \Magento\Framework\App\ActionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $actionFactoryMock;

protected function setUp()
{
$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
->getMockForAbstractClass();

$this->pageFactoryMock = $this->getMockBuilder(\Magento\Cms\Model\PageFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
->getMockForAbstractClass();

$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
->getMockForAbstractClass();
$this->storeManagerMock->expects($this->any())
->method('getStore')
->willReturn($this->storeMock);

$this->actionFactoryMock = $this->getMockBuilder(\Magento\Framework\App\ActionFactory::class)
->disableOriginalConstructor()
->getMock();

$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->router = $objectManagerHelper->getObject(
\Magento\Cms\Controller\Router::class,
[
'eventManager' => $this->eventManagerMock,
'pageFactory' => $this->pageFactoryMock,
'storeManager' => $this->storeManagerMock,
'actionFactory' => $this->actionFactoryMock,
]
);
}

public function testMatchCmsControllerRouterMatchBeforeEventParams()
{
$identifier = '/test';
$trimedIdentifier = 'test';
$pageId = 1;
$storeId = 1;

/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject $requestMock */
$requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
->setMethods([
'getPathInfo',
'setModuleName',
'setControllerName',
'setActionName',
'setParam',
'setAlias',
])
->getMockForAbstractClass();
$requestMock->expects($this->once())
->method('getPathInfo')
->willReturn($identifier);
$requestMock->expects($this->once())
->method('setModuleName')
->with('cms')
->willReturnSelf();
$requestMock->expects($this->once())
->method('setControllerName')
->with('page')
->willReturnSelf();
$requestMock->expects($this->once())
->method('setActionName')
->with('view')
->willReturnSelf();
$requestMock->expects($this->once())
->method('setParam')
->with('page_id', $pageId)
->willReturnSelf();
$requestMock->expects($this->once())
->method('setAlias')
->with(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $trimedIdentifier)
->willReturnSelf();

$condition = new \Magento\Framework\DataObject(['identifier' => $trimedIdentifier, 'continue' => true]);

$this->eventManagerMock->expects($this->once())
->method('dispatch')
->with(
'cms_controller_router_match_before',
[
'router' => $this->router,
'condition' => $condition,
]
)
->willReturnSelf();

$pageMock = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
->disableOriginalConstructor()
->getMock();
$pageMock->expects($this->once())
->method('checkIdentifier')
->with($trimedIdentifier, $storeId)
->willReturn($pageId);

$this->pageFactoryMock->expects($this->once())
->method('create')
->willReturn($pageMock);

$this->storeMock->expects($this->once())
->method('getId')
->willReturn($storeId);

$actionMock = $this->getMockBuilder(\Magento\Framework\App\ActionInterface::class)
->getMockForAbstractClass();

$this->actionFactoryMock->expects($this->once())
->method('create')
->with(\Magento\Framework\App\Action\Forward::class)
->willReturn($actionMock);

$this->assertEquals($actionMock, $this->router->match($requestMock));
}
}
13 changes: 11 additions & 2 deletions app/code/Magento/Cms/Test/Unit/Helper/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class PageTest extends \PHPUnit_Framework_TestCase
*/
protected $resultPageFactory;

/**
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $httpRequestMock;

protected function setUp()
{
$this->actionMock = $this->getMockBuilder(\Magento\Framework\App\Action\Action::class)
Expand Down Expand Up @@ -157,6 +162,8 @@ protected function setUp()
->getMockForAbstractClass();
$this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
->getMockForAbstractClass();
$this->httpRequestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
->getMockForAbstractClass();
$this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -184,7 +191,8 @@ protected function setUp()
\Magento\Framework\App\Helper\Context::class,
[
'eventManager' => $this->eventManagerMock,
'urlBuilder' => $this->urlBuilderMock
'urlBuilder' => $this->urlBuilderMock,
'httpRequest' => $this->httpRequestMock,
]
);

Expand Down Expand Up @@ -318,7 +326,8 @@ public function testPrepareResultPage(
'cms_page_render',
[
'page' => $this->pageMock,
'controller_action' => $this->actionMock
'controller_action' => $this->actionMock,
'request' => $this->httpRequestMock,
]
);
$this->pageMock->expects($this->any())
Expand Down
24 changes: 1 addition & 23 deletions app/code/Magento/Customer/Controller/Account/EditPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class EditPost extends \Magento\Customer\Controller\AbstractAccount
/** @var EmailNotificationInterface */
private $emailNotification;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var AuthenticationInterface
*/
Expand Down Expand Up @@ -171,8 +166,7 @@ public function execute()
$this->messageManager->addError($e->getMessage());
} catch (UserLockedException $e) {
$message = __(
'The account is locked. Please wait and try again or contact %1.',
$this->getScopeConfig()->getValue('contact/email/recipient_email')
'You did not sign in correctly or your account is temporarily disabled.'
);
$this->session->logout();
$this->session->start();
Expand All @@ -195,22 +189,6 @@ public function execute()
return $resultRedirect->setPath('*/*/edit');
}

/**
* Get scope config
*
* @return ScopeConfigInterface
*/
private function getScopeConfig()
{
if (!($this->scopeConfig instanceof \Magento\Framework\App\Config\ScopeConfigInterface)) {
return ObjectManager::getInstance()->get(
\Magento\Framework\App\Config\ScopeConfigInterface::class
);
} else {
return $this->scopeConfig;
}
}

/**
* Account editing action completed successfully event
*
Expand Down
5 changes: 2 additions & 3 deletions app/code/Magento/Customer/Controller/Account/LoginPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,12 @@ public function execute()
$this->session->setUsername($login['username']);
} catch (UserLockedException $e) {
$message = __(
'The account is locked. Please wait and try again or contact %1.',
$this->getScopeConfig()->getValue('contact/email/recipient_email')
'You did not sign in correctly or your account is temporarily disabled.'
);
$this->messageManager->addError($message);
$this->session->setUsername($login['username']);
} catch (AuthenticationException $e) {
$message = __('Invalid login or password.');
$message = __('You did not sign in correctly or your account is temporarily disabled.');
$this->messageManager->addError($message);
$this->session->setUsername($login['username']);
} catch (LocalizedException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Magento\Customer\Model\EmailNotificationInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\Result\RedirectFactory;
Expand Down Expand Up @@ -127,13 +126,6 @@ protected function setUp()
->disableOriginalConstructor()
->getMock();

$scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
->disableOriginalConstructor()
->getMock();
$scopeConfigMock->expects($this->any())
->method('getValue')
->willReturn('test@host.com');

$this->authenticationMock = $this->getMockBuilder(AuthenticationInterface::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -157,11 +149,7 @@ protected function setUp()
'emailNotification',
$this->emailNotification
);
$objectManager->setBackwardCompatibleProperty(
$this->model,
'scopeConfig',
$scopeConfigMock
);

$objectManager->setBackwardCompatibleProperty(
$this->model,
'authentication',
Expand Down Expand Up @@ -216,7 +204,6 @@ public function testGeneralSave()

$address = $this->getMockBuilder(\Magento\Customer\Api\Data\AddressInterface::class)
->getMockForAbstractClass();

$currentCustomerMock = $this->getCurrentCustomerMock($customerId, $address);
$newCustomerMock = $this->getNewCustomerMock($customerId, $address);

Expand Down Expand Up @@ -412,7 +399,7 @@ public function changeEmailExceptionDataProvider()
[
'testNumber' => 2,
'exceptionClass' => \Magento\Framework\Exception\State\UserLockedException::class,
'errorMessage' => __('The account is locked. Please wait and try again or contact %1.', 'test@host.com')
'errorMessage' => __('You did not sign in correctly or your account is temporarily disabled.')
]
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ protected function prepareContext()
protected function mockExceptions($exception, $username)
{
$url = 'url1';
$email = 'hello@example.com';

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

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

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

0 comments on commit c86d777

Please sign in to comment.