From 3975d22cf5803e14fda0c7986e154836914becd8 Mon Sep 17 00:00:00 2001 From: Ihor Sytnykov Date: Thu, 26 Nov 2015 16:15:25 +0200 Subject: [PATCH 01/10] =?UTF-8?q?MDVA-14:=20Quantity=20for=20individual=20?= =?UTF-8?q?items=20in=20a=20Bundle=20Product=20doesn=E2=80=99t=20show=20in?= =?UTF-8?q?=20the=20order=20when=20viewed=20in=20the=20Admin=20panel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code/Magento/Bundle/etc/di.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Bundle/etc/di.xml b/app/code/Magento/Bundle/etc/di.xml index ea48884a30a8d..412c603a8880f 100644 --- a/app/code/Magento/Bundle/etc/di.xml +++ b/app/code/Magento/Bundle/etc/di.xml @@ -90,4 +90,7 @@ Magento\CatalogInventory\Api\StockStateInterface\Proxy + + + From c2bb8bca27de74e5bddd6f85e7fb43a337f284aa Mon Sep 17 00:00:00 2001 From: Ihor Sytnykov Date: Thu, 26 Nov 2015 16:12:26 +0200 Subject: [PATCH 02/10] MDVA-22: Guests who already subscribed to the newsletter will always get a thank you message and receive a subscription success email if they subscribe again --- .../Magento/Newsletter/Model/Subscriber.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index be26e78f1d181..0920a1141ba93 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -399,6 +399,11 @@ public function subscribe($email) $this->setSubscriberConfirmCode($this->randomSequence()); } + $sendConfirmationEmail = true; + if ($this->getStatus() == self::STATUS_SUBSCRIBED && !$this->getCustomerId()) { + $sendConfirmationEmail = false; + } + $isConfirmNeed = $this->_scopeConfig->getValue( self::XML_PATH_CONFIRMATION_FLAG, \Magento\Store\Model\ScopeInterface::SCOPE_STORE @@ -442,12 +447,14 @@ public function subscribe($email) $this->setStatusChanged(true); try { - if ($isConfirmNeed === true - && $isOwnSubscribes === false - ) { - $this->sendConfirmationRequestEmail(); - } else { - $this->sendConfirmationSuccessEmail(); + if ($sendConfirmationEmail === true) { + if ($isConfirmNeed === true + && $isOwnSubscribes === false + ) { + $this->sendConfirmationRequestEmail(); + } else { + $this->sendConfirmationSuccessEmail(); + } } $this->save(); return $this->getStatus(); From 68038f6f746010e0f03f17576575237bffa1e04c Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Wed, 28 Oct 2015 12:13:09 +0200 Subject: [PATCH 03/10] MAGETWO-44045: Reset password page not displayed, instead user login page displayed. --- app/code/Magento/User/Model/User.php | 2 + .../Framework/Mail/Template/Factory.php | 14 ++--- .../Mail/Template/FactoryInterface.php | 3 +- .../Mail/Template/TransportBuilder.php | 21 ++++++- .../Mail/Test/Unit/Template/FactoryTest.php | 61 ++++++++++++++----- 5 files changed, 78 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/User/Model/User.php b/app/code/Magento/User/Model/User.php index 00878d88c5e05..5f8e85a80205e 100644 --- a/app/code/Magento/User/Model/User.php +++ b/app/code/Magento/User/Model/User.php @@ -369,6 +369,7 @@ public function sendPasswordResetConfirmationEmail() { $templateId = $this->_config->getValue(self::XML_PATH_FORGOT_EMAIL_TEMPLATE); $transport = $this->_transportBuilder->setTemplateIdentifier($templateId) + ->setTemplateNamespace('Magento\Email\Model\BackendTemplate') ->setTemplateOptions(['area' => FrontNameResolver::AREA_CODE, 'store' => Store::DEFAULT_STORE_ID]) ->setTemplateVars(['user' => $this, 'store' => $this->_storeManager->getStore(Store::DEFAULT_STORE_ID)]) ->setFrom($this->_config->getValue(self::XML_PATH_FORGOT_EMAIL_IDENTITY)) @@ -388,6 +389,7 @@ public function sendPasswordResetNotificationEmail() { $templateId = $this->_config->getValue(self::XML_PATH_RESET_PASSWORD_TEMPLATE); $transport = $this->_transportBuilder->setTemplateIdentifier($templateId) + ->setTemplateNamespace('Magento\Email\Model\BackendTemplate') ->setTemplateOptions(['area' => FrontNameResolver::AREA_CODE, 'store' => Store::DEFAULT_STORE_ID]) ->setTemplateVars(['user' => $this, 'store' => $this->_storeManager->getStore(Store::DEFAULT_STORE_ID)]) ->setFrom($this->_config->getValue(self::XML_PATH_FORGOT_EMAIL_IDENTITY)) diff --git a/lib/internal/Magento/Framework/Mail/Template/Factory.php b/lib/internal/Magento/Framework/Mail/Template/Factory.php index c3f2f7025565e..6162c23019a51 100644 --- a/lib/internal/Magento/Framework/Mail/Template/Factory.php +++ b/lib/internal/Magento/Framework/Mail/Template/Factory.php @@ -12,12 +12,12 @@ class Factory implements \Magento\Framework\Mail\Template\FactoryInterface /** * @var \Magento\Framework\ObjectManagerInterface */ - protected $_objectManager = null; + protected $objectManager = null; /** * @var string */ - protected $_instanceName = null; + protected $instanceName = null; /** * @param \Magento\Framework\ObjectManagerInterface $objectManager @@ -27,17 +27,17 @@ public function __construct( \Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = 'Magento\Framework\Mail\TemplateInterface' ) { - $this->_objectManager = $objectManager; - $this->_instanceName = $instanceName; + $this->objectManager = $objectManager; + $this->instanceName = $instanceName; } /** * {@inheritdoc} */ - public function get($identifier) + public function get($identifier, $namespace = null) { - return $this->_objectManager->create( - $this->_instanceName, + return $this->objectManager->create( + $namespace ? $namespace : $this->instanceName, ['data' => ['template_id' => $identifier]] ); } diff --git a/lib/internal/Magento/Framework/Mail/Template/FactoryInterface.php b/lib/internal/Magento/Framework/Mail/Template/FactoryInterface.php index 1f162aa77dd5e..c79961d2d297b 100644 --- a/lib/internal/Magento/Framework/Mail/Template/FactoryInterface.php +++ b/lib/internal/Magento/Framework/Mail/Template/FactoryInterface.php @@ -16,7 +16,8 @@ interface FactoryInterface * Returns the mail template associated with the identifier. * * @param string $identifier + * @param null|string $namespace * @return \Magento\Framework\Mail\TemplateInterface */ - public function get($identifier); + public function get($identifier, $namespace = null); } diff --git a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php index 837baa773bda2..c2f0f0501689f 100644 --- a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php +++ b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php @@ -23,6 +23,13 @@ class TransportBuilder */ protected $templateIdentifier; + /** + * Template Namespace + * + * @var string + */ + protected $templateNamespace; + /** * Template Variables * @@ -174,6 +181,18 @@ public function setTemplateIdentifier($templateIdentifier) return $this; } + /** + * Set template namespace + * + * @param string $templateNamespace + * @return $this + */ + public function setTemplateNamespace($templateNamespace) + { + $this->templateNamespace = $templateNamespace; + return $this; + } + /** * Set template vars * @@ -233,7 +252,7 @@ protected function reset() */ protected function getTemplate() { - return $this->templateFactory->get($this->templateIdentifier) + return $this->templateFactory->get($this->templateIdentifier, $this->templateNamespace) ->setVars($this->templateVars) ->setOptions($this->templateOptions); } diff --git a/lib/internal/Magento/Framework/Mail/Test/Unit/Template/FactoryTest.php b/lib/internal/Magento/Framework/Mail/Test/Unit/Template/FactoryTest.php index eb9f08e670118..34046ed77dc2d 100644 --- a/lib/internal/Magento/Framework/Mail/Test/Unit/Template/FactoryTest.php +++ b/lib/internal/Magento/Framework/Mail/Test/Unit/Template/FactoryTest.php @@ -5,37 +5,70 @@ */ namespace Magento\Framework\Mail\Test\Unit\Template; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; + class FactoryTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $objectManagerMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_objectManagerMock; + protected $templateMock; /** - * @var \PHPUnit_Framework_MockObject + * @var ObjectManagerHelper */ - protected $_templateMock; + protected $objectManagerHelper; + /** + * @return void + */ public function setUp() { - $this->_objectManagerMock = $this->getMock('\Magento\Framework\ObjectManagerInterface'); - $this->_templateMock = $this->getMock('\Magento\Framework\Mail\TemplateInterface'); + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->objectManagerMock = $this->getMock('\Magento\Framework\ObjectManagerInterface'); + $this->templateMock = $this->getMock('\Magento\Framework\Mail\TemplateInterface'); } /** - * @covers \Magento\Framework\Mail\Template\Factory::get - * @covers \Magento\Framework\Mail\Template\Factory::__construct + * @param string $expectedArgument + * @param null|string $namespace + * @return void + * @dataProvider getDataProvider */ - public function testGet() + public function testGet($expectedArgument, $namespace) { - $model = new \Magento\Framework\Mail\Template\Factory($this->_objectManagerMock); + $factory = $this->objectManagerHelper->getObject( + 'Magento\Framework\Mail\Template\Factory', + ['objectManager' => $this->objectManagerMock] + ); - $this->_objectManagerMock->expects($this->once()) + $this->objectManagerMock->expects($this->once()) ->method('create') - ->with('Magento\Framework\Mail\TemplateInterface', ['data' => ['template_id' => 'identifier']]) - ->will($this->returnValue($this->_templateMock)); + ->with($expectedArgument, ['data' => ['template_id' => 'identifier']]) + ->willReturn($this->templateMock); - $this->assertInstanceOf('\Magento\Framework\Mail\TemplateInterface', $model->get('identifier')); + $this->assertInstanceOf('\Magento\Framework\Mail\TemplateInterface', $factory->get('identifier', $namespace)); + } + + /** + * @return array + */ + public function getDataProvider() + { + return [ + [ + 'expectedArgument' => 'Magento\Framework\Mail\TemplateInterface', + 'namespace' => null + ], + [ + 'expectedArgument' => 'Test\Namespace\Implements\TemplateInterface', + 'namespace' => 'Test\Namespace\Implements\TemplateInterface' + ] + ]; } } From 382df0ad86da3747485119e00a2fde8ca107efb8 Mon Sep 17 00:00:00 2001 From: Anna Bukatar Date: Fri, 13 Nov 2015 18:14:17 +0200 Subject: [PATCH 04/10] MAGETWO-38927: Add unit test coverage for \Magento\User\Model --- .../Model/Plugin/AuthorizationRoleTest.php | 55 +++ .../Magento/User/Test/Unit/Model/UserTest.php | 415 ++++++++++++++---- 2 files changed, 377 insertions(+), 93 deletions(-) create mode 100644 app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php diff --git a/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php b/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php new file mode 100644 index 0000000000000..be819b6e8c9bc --- /dev/null +++ b/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php @@ -0,0 +1,55 @@ +userResourceModelMock = $this->getMockBuilder('Magento\User\Model\Resource\User') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->roleMock = $this->getMockBuilder('Magento\Authorization\Model\Role') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManager->getObject( + 'Magento\User\Model\Plugin\AuthorizationRole', + [ + 'userResourceModel' => $this->userResourceModelMock + ] + ); + } + + public function testAfterSave() + { + $this->userResourceModelMock->expects($this->once())->method('updateRoleUsersAcl')->with($this->roleMock); + $this->assertInstanceOf( + '\Magento\Authorization\Model\Role', + $this->model->afterSave($this->roleMock, $this->roleMock) + ); + } +} diff --git a/app/code/Magento/User/Test/Unit/Model/UserTest.php b/app/code/Magento/User/Test/Unit/Model/UserTest.php index 76facbc520bc8..05fd01ff4d268 100644 --- a/app/code/Magento/User/Test/Unit/Model/UserTest.php +++ b/app/code/Magento/User/Test/Unit/Model/UserTest.php @@ -16,59 +16,71 @@ class UserTest extends \PHPUnit_Framework_TestCase { /** @var \Magento\User\Model\User */ - protected $_model; + protected $model; - /** @var \Magento\User\Helper\Data */ - protected $_userData; + /** @var \Magento\User\Helper\Data|\PHPUnit_Framework_MockObject_MockObject */ + protected $userDataMock; /** @var \Magento\Framework\Mail\Template\TransportBuilder|\PHPUnit_Framework_MockObject_MockObject */ - protected $_transportBuilderMock; + protected $transportBuilderMock; /** @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject */ - protected $_contextMock; + protected $contextMock; /** @var \Magento\User\Model\Resource\User|\PHPUnit_Framework_MockObject_MockObject */ - protected $_resourceMock; + protected $resourceMock; /** @var \Magento\Framework\Data\Collection\AbstractDb|\PHPUnit_Framework_MockObject_MockObject */ - protected $_collectionMock; + protected $collectionMock; /** @var \Magento\Framework\Mail\TransportInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $_transportMock; + protected $transportMock; /** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $_storeManagerMock; + protected $storeManagerMock; /** @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */ - protected $_storetMock; + protected $storetMock; - /** @var \Magento\Backend\App\ConfigInterface */ - protected $_configMock; + /** @var \Magento\Backend\App\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $configMock; /** @var \Magento\Framework\Encryption\EncryptorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $_encryptorMock; + protected $encryptorMock; + + /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventManagerMock; + + /** @var \Magento\Framework\Validator\DataObjectFactory|\PHPUnit_Framework_MockObject_MockObject */ + protected $validatorObjectFactoryMock; + + /** @var \Magento\User\Model\UserValidationRules|\PHPUnit_Framework_MockObject_MockObject */ + protected $validationRulesMock; + + /** @var \Magento\Authorization\Model\RoleFactory|\PHPUnit_Framework_MockObject_MockObject */ + protected $roleFactoryMock; /** * Set required values */ protected function setUp() { - $this->_userData = $this->getMockBuilder( + $this->userDataMock = $this->getMockBuilder( 'Magento\User\Helper\Data' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_contextMock = $this->getMockBuilder( + $this->contextMock = $this->getMockBuilder( 'Magento\Framework\Model\Context' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_resourceMock = $this->getMockBuilder( + $this->resourceMock = $this->getMockBuilder( 'Magento\User\Model\Resource\User' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_collectionMock = $this->getMockBuilder( + $this->collectionMock = $this->getMockBuilder( 'Magento\Framework\Data\Collection\AbstractDb' )->disableOriginalConstructor()->setMethods( [] @@ -78,69 +90,73 @@ protected function setUp() )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $eventManagerMock = $this->getMockBuilder( + $this->eventManagerMock = $this->getMockBuilder( 'Magento\Framework\Event\ManagerInterface' )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $objectFactoryMock = $this->getMockBuilder( + ['dispatch'] + )->getMockForAbstractClass(); + $this->validatorObjectFactoryMock = $this->getMockBuilder( 'Magento\Framework\Validator\ObjectFactory' )->disableOriginalConstructor()->setMethods( ['create'] )->getMock(); - $roleFactoryMock = $this->getMockBuilder( + $this->roleFactoryMock = $this->getMockBuilder( 'Magento\Authorization\Model\RoleFactory' )->disableOriginalConstructor()->setMethods( ['create'] )->getMock(); - $this->_transportMock = $this->getMockBuilder( + $this->transportMock = $this->getMockBuilder( 'Magento\Framework\Mail\TransportInterface' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_transportBuilderMock = $this->getMockBuilder( + $this->transportBuilderMock = $this->getMockBuilder( '\Magento\Framework\Mail\Template\TransportBuilder' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_storetMock = $this->getMockBuilder( + $this->storetMock = $this->getMockBuilder( '\Magento\Store\Model\Store' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_storeManagerMock = $this->getMockBuilder( + $this->storeManagerMock = $this->getMockBuilder( '\Magento\Store\Model\StoreManagerInterface' )->disableOriginalConstructor()->setMethods( [] )->getMock(); - $this->_configMock = $this->getMockBuilder( + $this->configMock = $this->getMockBuilder( '\Magento\Backend\App\ConfigInterface' )->disableOriginalConstructor()->setMethods( [] )->getMock(); + $this->validationRulesMock = $this->getMockBuilder( + 'Magento\User\Model\UserValidationRules' + )->disableOriginalConstructor()->setMethods( + [] + )->getMock(); - $this->_encryptorMock = $this->getMockBuilder('Magento\Framework\Encryption\EncryptorInterface') + $this->encryptorMock = $this->getMockBuilder('Magento\Framework\Encryption\EncryptorInterface') ->setMethods(['validateHash']) ->getMockForAbstractClass(); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->_model = $helper->getObject( + $this->model = $helper->getObject( 'Magento\User\Model\User', [ - 'eventManager' => $eventManagerMock, - 'userData' => $this->_userData, - 'context' => $this->_contextMock, + 'eventManager' => $this->eventManagerMock, + 'userData' => $this->userDataMock, 'registry' => $coreRegistry, - 'resource' => $this->_resourceMock, - 'resourceCollection' => $this->_collectionMock, - 'validatorObjectFactory' => $objectFactoryMock, - 'roleFactory' => $roleFactoryMock, - 'transportBuilder' => $this->_transportBuilderMock, - 'storeManager' => $this->_storeManagerMock, - 'validationRules' => new UserValidationRules(), - 'config' => $this->_configMock, - 'encryptor' => $this->_encryptorMock + 'resource' => $this->resourceMock, + 'resourceCollection' => $this->collectionMock, + 'validatorObjectFactory' => $this->validatorObjectFactoryMock, + 'roleFactory' => $this->roleFactoryMock, + 'transportBuilder' => $this->transportBuilderMock, + 'storeManager' => $this->storeManagerMock, + 'validationRules' => $this->validationRulesMock, + 'config' => $this->configMock, + 'encryptor' => $this->encryptorMock ] ); } @@ -152,11 +168,11 @@ public function testSendPasswordResetNotificationEmail() $firstName = 'Foo'; $lastName = 'Bar'; - $this->_model->setEmail($email); - $this->_model->setFirstname($firstName); - $this->_model->setLastname($lastName); + $this->model->setEmail($email); + $this->model->setFirstname($firstName); + $this->model->setLastname($lastName); - $this->_configMock->expects( + $this->configMock->expects( $this->at(0) )->method( 'getValue' @@ -165,7 +181,7 @@ public function testSendPasswordResetNotificationEmail() )->will( $this->returnValue('templateId') ); - $this->_configMock->expects( + $this->configMock->expects( $this->at(1) )->method( 'getValue' @@ -174,17 +190,17 @@ public function testSendPasswordResetNotificationEmail() )->will( $this->returnValue('sender') ); - $this->_transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); + $this->transportBuilderMock->expects( $this->once() )->method( 'setTemplateVars' )->with( - ['user' => $this->_model, 'store' => $this->_storetMock] + ['user' => $this->model, 'store' => $this->storetMock] )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'addTo' @@ -194,7 +210,7 @@ public function testSendPasswordResetNotificationEmail() )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'setFrom' @@ -203,7 +219,7 @@ public function testSendPasswordResetNotificationEmail() )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'setTemplateIdentifier' @@ -212,26 +228,26 @@ public function testSendPasswordResetNotificationEmail() )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'getTransport' )->will( - $this->returnValue($this->_transportMock) + $this->returnValue($this->transportMock) ); - $this->_transportMock->expects($this->once())->method('sendMessage'); + $this->transportMock->expects($this->once())->method('sendMessage'); - $this->_storeManagerMock->expects( + $this->storeManagerMock->expects( $this->once() )->method( 'getStore' )->with( $storeId )->will( - $this->returnValue($this->_storetMock) + $this->returnValue($this->storetMock) ); - $this->assertInstanceOf('\Magento\User\Model\User', $this->_model->sendPasswordResetNotificationEmail()); + $this->assertInstanceOf('\Magento\User\Model\User', $this->model->sendPasswordResetNotificationEmail()); } public function testSendPasswordResetConfirmationEmail() @@ -241,11 +257,11 @@ public function testSendPasswordResetConfirmationEmail() $firstName = 'Foo'; $lastName = 'Bar'; - $this->_model->setEmail($email); - $this->_model->setFirstname($firstName); - $this->_model->setLastname($lastName); + $this->model->setEmail($email); + $this->model->setFirstname($firstName); + $this->model->setLastname($lastName); - $this->_configMock->expects( + $this->configMock->expects( $this->at(0) )->method( 'getValue' @@ -254,7 +270,7 @@ public function testSendPasswordResetConfirmationEmail() )->will( $this->returnValue('templateId') ); - $this->_configMock->expects( + $this->configMock->expects( $this->at(1) )->method( 'getValue' @@ -263,17 +279,17 @@ public function testSendPasswordResetConfirmationEmail() )->will( $this->returnValue('sender') ); - $this->_transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); + $this->transportBuilderMock->expects( $this->once() )->method( 'setTemplateVars' )->with( - ['user' => $this->_model, 'store' => $this->_storetMock] + ['user' => $this->model, 'store' => $this->storetMock] )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'addTo' @@ -283,7 +299,7 @@ public function testSendPasswordResetConfirmationEmail() )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'setFrom' @@ -292,7 +308,7 @@ public function testSendPasswordResetConfirmationEmail() )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'setTemplateIdentifier' @@ -301,40 +317,40 @@ public function testSendPasswordResetConfirmationEmail() )->will( $this->returnSelf() ); - $this->_transportBuilderMock->expects( + $this->transportBuilderMock->expects( $this->once() )->method( 'getTransport' )->will( - $this->returnValue($this->_transportMock) + $this->returnValue($this->transportMock) ); - $this->_transportMock->expects($this->once())->method('sendMessage'); + $this->transportMock->expects($this->once())->method('sendMessage'); - $this->_storeManagerMock->expects( + $this->storeManagerMock->expects( $this->once() )->method( 'getStore' )->with( $storeId )->will( - $this->returnValue($this->_storetMock) + $this->returnValue($this->storetMock) ); - $this->assertInstanceOf('\Magento\User\Model\User', $this->_model->sendPasswordResetConfirmationEmail()); + $this->assertInstanceOf('\Magento\User\Model\User', $this->model->sendPasswordResetConfirmationEmail()); } public function testVerifyIdentity() { $password = 'password'; - $this->_encryptorMock + $this->encryptorMock ->expects($this->once()) ->method('validateHash') - ->with($password, $this->_model->getPassword()) + ->with($password, $this->model->getPassword()) ->will($this->returnValue(true)); - $this->_model->setIsActive(true); - $this->_resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(true)); + $this->model->setIsActive(true); + $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(true)); $this->assertTrue( - $this->_model->verifyIdentity($password), + $this->model->verifyIdentity($password), 'Identity verification failed while should have passed.' ); } @@ -342,13 +358,13 @@ public function testVerifyIdentity() public function testVerifyIdentityFailure() { $password = 'password'; - $this->_encryptorMock + $this->encryptorMock ->expects($this->once()) ->method('validateHash') - ->with($password, $this->_model->getPassword()) + ->with($password, $this->model->getPassword()) ->will($this->returnValue(false)); $this->assertFalse( - $this->_model->verifyIdentity($password), + $this->model->verifyIdentity($password), 'Identity verification passed while should have failed.' ); } @@ -356,33 +372,246 @@ public function testVerifyIdentityFailure() public function testVerifyIdentityInactiveRecord() { $password = 'password'; - $this->_encryptorMock + $this->encryptorMock ->expects($this->once()) ->method('validateHash') - ->with($password, $this->_model->getPassword()) + ->with($password, $this->model->getPassword()) ->will($this->returnValue(true)); - $this->_model->setIsActive(false); + $this->model->setIsActive(false); $this->setExpectedException( 'Magento\\Framework\\Exception\\AuthenticationException', - 'This account is inactive.' + 'You did not sign in correctly or your account is temporarily disabled.' ); - $this->_model->verifyIdentity($password); + $this->model->verifyIdentity($password); } public function testVerifyIdentityNoAssignedRoles() { $password = 'password'; - $this->_encryptorMock + $this->encryptorMock ->expects($this->once()) ->method('validateHash') - ->with($password, $this->_model->getPassword()) + ->with($password, $this->model->getPassword()) ->will($this->returnValue(true)); - $this->_model->setIsActive(true); - $this->_resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(false)); + $this->model->setIsActive(true); + $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(false)); $this->setExpectedException( 'Magento\\Framework\\Exception\\AuthenticationException', 'You need more permissions to access this.' ); - $this->_model->verifyIdentity($password); + $this->model->verifyIdentity($password); + } + + public function testSleep() + { + $excludedProperties = [ + '_eventManager', + '_cacheManager', + '_registry', + '_appState', + '_userData', + '_config', + '_validatorObject', + '_roleFactory', + '_encryptor', + '_transportBuilder', + '_storeManager', + '_validatorBeforeSave' + ]; + $actualResult = $this->model->__sleep(); + $this->assertNotEmpty($actualResult); + $expectedResult = array_intersect($actualResult, $excludedProperties); + $this->assertEmpty($expectedResult); + } + + public function testBeforeSave() + { + $this->eventManagerMock->expects($this->any())->method('dispatch'); + $this->model->setIsActive(1); + $actualData = $this->model->beforeSave()->getData(); + $this->assertArrayHasKey('extra', $actualData); + $this->assertArrayHasKey('password', $actualData); + $this->assertArrayHasKey('is_active', $actualData); + } + + public function testValidateOk() + { + /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */ + $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\DataObject') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock); + $this->validationRulesMock->expects($this->once()) + ->method('addUserInfoRules') + ->with($validatorMock); + $validatorMock->expects($this->once())->method('isValid')->willReturn(true); + $this->assertTrue($this->model->validate()); + } + + public function testValidateInvalid() + { + $messages = ['Invalid username']; + /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */ + $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\DataObject') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock); + $this->validationRulesMock->expects($this->once()) + ->method('addUserInfoRules') + ->with($validatorMock); + $validatorMock->expects($this->once())->method('isValid')->willReturn(false); + $validatorMock->expects($this->once())->method('getMessages')->willReturn($messages); + $this->assertEquals($messages, $this->model->validate()); + } + + public function testSaveExtra() + { + $data = [1, 2, 3]; + $this->resourceMock->expects($this->once())->method('saveExtra')->with($this->model, serialize($data)); + $this->assertInstanceOf('Magento\User\Model\User', $this->model->saveExtra($data)); + } + + public function testGetRoles() + { + $this->resourceMock->expects($this->once())->method('getRoles')->with($this->model)->willReturn([]); + $this->assertInternalType('array', $this->model->getRoles()); + } + + public function testGetRole() + { + $roles = ['role']; + $roleMock = $this->getMockBuilder('Magento\Authorization\Model\Role') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->roleFactoryMock->expects($this->once())->method('create')->willReturn($roleMock); + $this->resourceMock->expects($this->once())->method('getRoles')->with($this->model)->willReturn($roles); + $roleMock->expects($this->once())->method('load')->with($roles[0]); + $this->assertInstanceOf('Magento\Authorization\Model\Role', $this->model->getRole()); + } + + public function testDeleteFromRole() + { + $this->resourceMock->expects($this->once())->method('deleteFromRole')->with($this->model); + $this->assertInstanceOf('Magento\User\Model\User', $this->model->deleteFromRole()); + } + + public function testRoleUserExistsTrue() + { + $result = ['role']; + $this->resourceMock->expects($this->once())->method('roleUserExists')->with($this->model)->willReturn($result); + $this->assertTrue($this->model->roleUserExists()); + } + + public function testRoleUserExistsFalse() + { + $result = []; + $this->resourceMock->expects($this->once())->method('roleUserExists')->with($this->model)->willReturn($result); + $this->assertFalse($this->model->roleUserExists()); + } + + public function testGetAclRole() + { + $roles = ['role']; + $result = 1; + $roleMock = $this->getMockBuilder('Magento\Authorization\Model\Role') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->roleFactoryMock->expects($this->once())->method('create')->willReturn($roleMock); + $this->resourceMock->expects($this->once())->method('getRoles')->with($this->model)->willReturn($roles); + $roleMock->expects($this->once())->method('load')->with($roles[0]); + $roleMock->expects($this->once())->method('getId')->willReturn($result); + $this->assertEquals($result, $this->model->getAclRole()); + } + + public function testAuthenticate($usernameIn, $usernameOut, $expectedResult) + { + $password = 'password'; + $config = 'config'; + + $data = ['id' => 1, 'is_active' => 1, 'username' => $usernameOut]; + + $this->configMock->expects($this->once()) + ->method('isSetFlag') + ->with('admin/security/use_case_sensitive_login') + ->willReturn($config); + $this->eventManagerMock->expects($this->any())->method('dispatch'); + + $this->resourceMock->expects($this->any())->method('loadByUsername')->willReturn($data); + $this->model->setIdFieldName('id'); + + $this->encryptorMock->expects($this->any())->method('validateHash')->willReturn(true); + $this->resourceMock->expects($this->any())->method('hasAssigned2Role')->willReturn(true); + $this->assertEquals($expectedResult, $this->model->authenticate($usernameIn, $password)); + } + + public function authenticateDataProvider() + { + return [ + 'success' => [ + 'usernameIn' => 'username', + 'usernameOut' => 'username', + 'expectedResult' => true + ], + 'failedUsername' => [ + 'usernameIn' => 'username1', + 'usernameOut' => 'username2', + 'expectedResult' => false + ] + ]; + } + + public function testAuthenticateException() + { + $username = 'username'; + $password = 'password'; + $config = 'config'; + + $this->configMock->expects($this->once()) + ->method('isSetFlag') + ->with('admin/security/use_case_sensitive_login') + ->willReturn($config); + + $this->eventManagerMock->expects($this->any())->method('dispatch'); + $this->resourceMock->expects($this->once()) + ->method('loadByUsername') + ->willThrowException(new \Magento\Framework\Exception\LocalizedException(__())); + $this->model->authenticate($username, $password); + } + + public function testChangeResetPasswordLinkToken() + { + $token = '1'; + $this->assertInstanceOf('Magento\User\Model\User', $this->model->changeResetPasswordLinkToken($token)); + $this->assertEquals($token, $this->model->getRpToken()); + $this->assertInternalType('string', $this->model->getRpTokenCreatedAt()); + } + + public function testIsResetPasswordLinkTokenExpiredEmptyToken() + { + $this->assertTrue($this->model->isResetPasswordLinkTokenExpired()); + } + + public function testIsResetPasswordLinkTokenExpiredIsExpiredToken() + { + $this->model->setRpToken('1'); + $this->model->setRpTokenCreatedAt( + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); + $this->userDataMock->expects($this->once())->method('getResetPasswordLinkExpirationPeriod')->willReturn(0); + $this->assertTrue($this->model->isResetPasswordLinkTokenExpired()); + } + + public function testIsResetPasswordLinkTokenExpiredIsNotExpiredToken() + { + $this->model->setRpToken('1'); + $this->model->setRpTokenCreatedAt( + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); + $this->userDataMock->expects($this->once())->method('getResetPasswordLinkExpirationPeriod')->willReturn(1); + $this->assertFalse($this->model->isResetPasswordLinkTokenExpired()); } } From 86d5a188a6f8b45cd4b45874feb9cc64b9f3fcce Mon Sep 17 00:00:00 2001 From: Anna Bukatar Date: Fri, 13 Nov 2015 18:30:15 +0200 Subject: [PATCH 05/10] MAGETWO-44045: Reset password page not displayed, instead user login page displayed. --- .../Magento/User/Test/Unit/Model/UserTest.php | 441 +++++++++--------- .../Mail/Template/TransportBuilder.php | 6 +- .../Unit/Template/TransportBuilderTest.php | 129 ++--- 3 files changed, 271 insertions(+), 305 deletions(-) diff --git a/app/code/Magento/User/Test/Unit/Model/UserTest.php b/app/code/Magento/User/Test/Unit/Model/UserTest.php index 05fd01ff4d268..08547ba0e52d7 100644 --- a/app/code/Magento/User/Test/Unit/Model/UserTest.php +++ b/app/code/Magento/User/Test/Unit/Model/UserTest.php @@ -65,84 +65,70 @@ class UserTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->userDataMock = $this->getMockBuilder( - 'Magento\User\Helper\Data' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->contextMock = $this->getMockBuilder( - 'Magento\Framework\Model\Context' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->resourceMock = $this->getMockBuilder( - 'Magento\User\Model\Resource\User' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->collectionMock = $this->getMockBuilder( - 'Magento\Framework\Data\Collection\AbstractDb' - )->disableOriginalConstructor()->setMethods( - [] - )->getMockForAbstractClass(); - $coreRegistry = $this->getMockBuilder( - 'Magento\Framework\Registry' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->eventManagerMock = $this->getMockBuilder( - 'Magento\Framework\Event\ManagerInterface' - )->disableOriginalConstructor()->setMethods( - ['dispatch'] - )->getMockForAbstractClass(); - $this->validatorObjectFactoryMock = $this->getMockBuilder( - 'Magento\Framework\Validator\ObjectFactory' - )->disableOriginalConstructor()->setMethods( - ['create'] - )->getMock(); - $this->roleFactoryMock = $this->getMockBuilder( - 'Magento\Authorization\Model\RoleFactory' - )->disableOriginalConstructor()->setMethods( - ['create'] - )->getMock(); - $this->transportMock = $this->getMockBuilder( - 'Magento\Framework\Mail\TransportInterface' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->transportBuilderMock = $this->getMockBuilder( - '\Magento\Framework\Mail\Template\TransportBuilder' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->storetMock = $this->getMockBuilder( - '\Magento\Store\Model\Store' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->storeManagerMock = $this->getMockBuilder( - '\Magento\Store\Model\StoreManagerInterface' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - - $this->configMock = $this->getMockBuilder( - '\Magento\Backend\App\ConfigInterface' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); - $this->validationRulesMock = $this->getMockBuilder( - 'Magento\User\Model\UserValidationRules' - )->disableOriginalConstructor()->setMethods( - [] - )->getMock(); + $this->userDataMock = $this->getMockBuilder('Magento\User\Helper\Data') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->contextMock = $this->getMockBuilder('Magento\Framework\Model\Context') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->resourceMock = $this->getMockBuilder('Magento\User\Model\ResourceModel\User') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->collectionMock = $this->getMockBuilder('Magento\Framework\Data\Collection\AbstractDb') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $coreRegistry = $this->getMockBuilder('Magento\Framework\Registry') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface') + ->disableOriginalConstructor() + ->setMethods(['dispatch']) + ->getMockForAbstractClass(); + $this->validatorObjectFactoryMock = $this->getMockBuilder('Magento\Framework\Validator\DataObjectFactory') + ->disableOriginalConstructor()->setMethods(['create']) + ->getMock(); + $this->roleFactoryMock = $this->getMockBuilder('Magento\Authorization\Model\RoleFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->transportMock = $this->getMockBuilder('Magento\Framework\Mail\TransportInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->transportBuilderMock = $this->getMockBuilder('Magento\Framework\Mail\Template\TransportBuilder') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->storetMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->configMock = $this->getMockBuilder('Magento\Backend\App\ConfigInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->validationRulesMock = $this->getMockBuilder('Magento\User\Model\UserValidationRules') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); $this->encryptorMock = $this->getMockBuilder('Magento\Framework\Encryption\EncryptorInterface') ->setMethods(['validateHash']) ->getMockForAbstractClass(); - $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->model = $helper->getObject( + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManagerHelper->getObject( 'Magento\User\Model\User', [ 'eventManager' => $this->eventManagerMock, @@ -161,6 +147,9 @@ protected function setUp() ); } + /** + * @return void + */ public function testSendPasswordResetNotificationEmail() { $storeId = 0; @@ -172,84 +161,53 @@ public function testSendPasswordResetNotificationEmail() $this->model->setFirstname($firstName); $this->model->setLastname($lastName); - $this->configMock->expects( - $this->at(0) - )->method( - 'getValue' - )->with( - \Magento\User\Model\User::XML_PATH_RESET_PASSWORD_TEMPLATE - )->will( - $this->returnValue('templateId') - ); - $this->configMock->expects( - $this->at(1) - )->method( - 'getValue' - )->with( - \Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY - )->will( - $this->returnValue('sender') - ); - $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'setTemplateVars' - )->with( - ['user' => $this->model, 'store' => $this->storetMock] - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'addTo' - )->with( - $this->equalTo($email), - $this->equalTo($firstName . ' ' . $lastName) - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'setFrom' - )->with( - 'sender' - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'setTemplateIdentifier' - )->with( - 'templateId' - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'getTransport' - )->will( - $this->returnValue($this->transportMock) - ); + $this->configMock->expects($this->at(0)) + ->method('getValue') + ->with(\Magento\User\Model\User::XML_PATH_RESET_PASSWORD_TEMPLATE) + ->willReturn('templateId'); + $this->configMock->expects($this->at(1)) + ->method('getValue') + ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY) + ->willReturn('sender'); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateNamespace') + ->with($this->equalTo('Magento\Email\Model\BackendTemplate')) + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateOptions') + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateVars') + ->with(['user' => $this->model, 'store' => $this->storetMock]) + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('addTo') + ->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName)) + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setFrom') + ->with('sender') + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateIdentifier') + ->with('templateId') + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('getTransport') + ->willReturn($this->transportMock); $this->transportMock->expects($this->once())->method('sendMessage'); - $this->storeManagerMock->expects( - $this->once() - )->method( - 'getStore' - )->with( - $storeId - )->will( - $this->returnValue($this->storetMock) - ); + $this->storeManagerMock->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->willReturn($this->storetMock); $this->assertInstanceOf('\Magento\User\Model\User', $this->model->sendPasswordResetNotificationEmail()); } + /** + * @return void + */ public function testSendPasswordResetConfirmationEmail() { $storeId = 0; @@ -261,84 +219,53 @@ public function testSendPasswordResetConfirmationEmail() $this->model->setFirstname($firstName); $this->model->setLastname($lastName); - $this->configMock->expects( - $this->at(0) - )->method( - 'getValue' - )->with( - \Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE - )->will( - $this->returnValue('templateId') - ); - $this->configMock->expects( - $this->at(1) - )->method( - 'getValue' - )->with( - \Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY - )->will( - $this->returnValue('sender') - ); - $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->will($this->returnSelf()); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'setTemplateVars' - )->with( - ['user' => $this->model, 'store' => $this->storetMock] - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'addTo' - )->with( - $this->equalTo($email), - $this->equalTo($firstName . ' ' . $lastName) - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'setFrom' - )->with( - 'sender' - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'setTemplateIdentifier' - )->with( - 'templateId' - )->will( - $this->returnSelf() - ); - $this->transportBuilderMock->expects( - $this->once() - )->method( - 'getTransport' - )->will( - $this->returnValue($this->transportMock) - ); + $this->configMock->expects($this->at(0)) + ->method('getValue') + ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_TEMPLATE) + ->willReturn('templateId'); + $this->configMock->expects($this->at(1)) + ->method('getValue') + ->with(\Magento\User\Model\User::XML_PATH_FORGOT_EMAIL_IDENTITY) + ->willReturn('sender'); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateNamespace') + ->with($this->equalTo('Magento\Email\Model\BackendTemplate')) + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateOptions') + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateVars') + ->with(['user' => $this->model, 'store' => $this->storetMock]) + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('addTo') + ->with($this->equalTo($email), $this->equalTo($firstName . ' ' . $lastName)) + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setFrom') + ->with('sender') + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('setTemplateIdentifier') + ->with('templateId') + ->willReturnSelf(); + $this->transportBuilderMock->expects($this->once()) + ->method('getTransport') + ->willReturn($this->transportMock); $this->transportMock->expects($this->once())->method('sendMessage'); - $this->storeManagerMock->expects( - $this->once() - )->method( - 'getStore' - )->with( - $storeId - )->will( - $this->returnValue($this->storetMock) - ); + $this->storeManagerMock->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->willReturn($this->storetMock); $this->assertInstanceOf('\Magento\User\Model\User', $this->model->sendPasswordResetConfirmationEmail()); } + /** + * @return void + */ public function testVerifyIdentity() { $password = 'password'; @@ -346,15 +273,18 @@ public function testVerifyIdentity() ->expects($this->once()) ->method('validateHash') ->with($password, $this->model->getPassword()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->model->setIsActive(true); - $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(true)); + $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->willReturn(true); $this->assertTrue( $this->model->verifyIdentity($password), 'Identity verification failed while should have passed.' ); } + /** + * @return void + */ public function testVerifyIdentityFailure() { $password = 'password'; @@ -362,13 +292,16 @@ public function testVerifyIdentityFailure() ->expects($this->once()) ->method('validateHash') ->with($password, $this->model->getPassword()) - ->will($this->returnValue(false)); + ->willReturn(false); $this->assertFalse( $this->model->verifyIdentity($password), 'Identity verification passed while should have failed.' ); } + /** + * @return void + */ public function testVerifyIdentityInactiveRecord() { $password = 'password'; @@ -376,7 +309,7 @@ public function testVerifyIdentityInactiveRecord() ->expects($this->once()) ->method('validateHash') ->with($password, $this->model->getPassword()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->model->setIsActive(false); $this->setExpectedException( 'Magento\\Framework\\Exception\\AuthenticationException', @@ -385,6 +318,9 @@ public function testVerifyIdentityInactiveRecord() $this->model->verifyIdentity($password); } + /** + * @return void + */ public function testVerifyIdentityNoAssignedRoles() { $password = 'password'; @@ -392,9 +328,9 @@ public function testVerifyIdentityNoAssignedRoles() ->expects($this->once()) ->method('validateHash') ->with($password, $this->model->getPassword()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->model->setIsActive(true); - $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(false)); + $this->resourceMock->expects($this->once())->method('hasAssigned2Role')->willReturn(false); $this->setExpectedException( 'Magento\\Framework\\Exception\\AuthenticationException', 'You need more permissions to access this.' @@ -402,6 +338,9 @@ public function testVerifyIdentityNoAssignedRoles() $this->model->verifyIdentity($password); } + /** + * @return void + */ public function testSleep() { $excludedProperties = [ @@ -424,6 +363,9 @@ public function testSleep() $this->assertEmpty($expectedResult); } + /** + * @return void + */ public function testBeforeSave() { $this->eventManagerMock->expects($this->any())->method('dispatch'); @@ -434,6 +376,9 @@ public function testBeforeSave() $this->assertArrayHasKey('is_active', $actualData); } + /** + * @return void + */ public function testValidateOk() { /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */ @@ -449,6 +394,9 @@ public function testValidateOk() $this->assertTrue($this->model->validate()); } + /** + * @return void + */ public function testValidateInvalid() { $messages = ['Invalid username']; @@ -466,6 +414,9 @@ public function testValidateInvalid() $this->assertEquals($messages, $this->model->validate()); } + /** + * @return void + */ public function testSaveExtra() { $data = [1, 2, 3]; @@ -473,12 +424,18 @@ public function testSaveExtra() $this->assertInstanceOf('Magento\User\Model\User', $this->model->saveExtra($data)); } + /** + * @return void + */ public function testGetRoles() { $this->resourceMock->expects($this->once())->method('getRoles')->with($this->model)->willReturn([]); $this->assertInternalType('array', $this->model->getRoles()); } + /** + * @return void + */ public function testGetRole() { $roles = ['role']; @@ -492,12 +449,18 @@ public function testGetRole() $this->assertInstanceOf('Magento\Authorization\Model\Role', $this->model->getRole()); } + /** + * @return void + */ public function testDeleteFromRole() { $this->resourceMock->expects($this->once())->method('deleteFromRole')->with($this->model); $this->assertInstanceOf('Magento\User\Model\User', $this->model->deleteFromRole()); } + /** + * @return void + */ public function testRoleUserExistsTrue() { $result = ['role']; @@ -505,6 +468,9 @@ public function testRoleUserExistsTrue() $this->assertTrue($this->model->roleUserExists()); } + /** + * @return void + */ public function testRoleUserExistsFalse() { $result = []; @@ -512,6 +478,9 @@ public function testRoleUserExistsFalse() $this->assertFalse($this->model->roleUserExists()); } + /** + * @return void + */ public function testGetAclRole() { $roles = ['role']; @@ -527,6 +496,13 @@ public function testGetAclRole() $this->assertEquals($result, $this->model->getAclRole()); } + /** + * @dataProvider authenticateDataProvider + * @param string $usernameIn + * @param string $usernameOut + * @param bool $expectedResult + * @return void + */ public function testAuthenticate($usernameIn, $usernameOut, $expectedResult) { $password = 'password'; @@ -548,6 +524,9 @@ public function testAuthenticate($usernameIn, $usernameOut, $expectedResult) $this->assertEquals($expectedResult, $this->model->authenticate($usernameIn, $password)); } + /** + * @return array + */ public function authenticateDataProvider() { return [ @@ -564,6 +543,10 @@ public function authenticateDataProvider() ]; } + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @return void + */ public function testAuthenticateException() { $username = 'username'; @@ -582,6 +565,9 @@ public function testAuthenticateException() $this->model->authenticate($username, $password); } + /** + * @return void + */ public function testChangeResetPasswordLinkToken() { $token = '1'; @@ -590,11 +576,17 @@ public function testChangeResetPasswordLinkToken() $this->assertInternalType('string', $this->model->getRpTokenCreatedAt()); } + /** + * @return void + */ public function testIsResetPasswordLinkTokenExpiredEmptyToken() { $this->assertTrue($this->model->isResetPasswordLinkTokenExpired()); } + /** + * @return void + */ public function testIsResetPasswordLinkTokenExpiredIsExpiredToken() { $this->model->setRpToken('1'); @@ -605,6 +597,9 @@ public function testIsResetPasswordLinkTokenExpiredIsExpiredToken() $this->assertTrue($this->model->isResetPasswordLinkTokenExpired()); } + /** + * @return void + */ public function testIsResetPasswordLinkTokenExpiredIsNotExpiredToken() { $this->model->setRpToken('1'); diff --git a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php index c2f0f0501689f..414fc4d738860 100644 --- a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php +++ b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php @@ -82,7 +82,7 @@ class TransportBuilder /** * @var \Magento\Framework\Mail\TransportInterfaceFactory */ - protected $_mailTransportFactory; + protected $mailTransportFactory; /** * @param FactoryInterface $templateFactory @@ -102,7 +102,7 @@ public function __construct( $this->message = $message; $this->objectManager = $objectManager; $this->_senderResolver = $senderResolver; - $this->_mailTransportFactory = $mailTransportFactory; + $this->mailTransportFactory = $mailTransportFactory; } /** @@ -225,7 +225,7 @@ public function setTemplateOptions($templateOptions) public function getTransport() { $this->prepareMessage(); - $mailTransport = $this->_mailTransportFactory->create(['message' => clone $this->message]); + $mailTransport = $this->mailTransportFactory->create(['message' => clone $this->message]); $this->reset(); return $mailTransport; diff --git a/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php b/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php index 0a93ee2ca9ee2..2c2a6d55af32a 100644 --- a/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php +++ b/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php @@ -40,26 +40,30 @@ class TransportBuilderTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_mailTransportFactoryMock; + protected $mailTransportFactoryMock; + /** + * @return void + */ public function setUp() { - $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->templateFactoryMock = $this->getMock('Magento\Framework\Mail\Template\FactoryInterface'); $this->messageMock = $this->getMock('Magento\Framework\Mail\Message'); $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); $this->senderResolverMock = $this->getMock('Magento\Framework\Mail\Template\SenderResolverInterface'); - $this->_mailTransportFactoryMock = $this->getMockBuilder( - 'Magento\Framework\Mail\TransportInterfaceFactory' - )->disableOriginalConstructor()->setMethods(['create'])->getMock(); - $this->builder = $helper->getObject( + $this->mailTransportFactoryMock = $this->getMockBuilder('Magento\Framework\Mail\TransportInterfaceFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->builder = $objectManagerHelper->getObject( $this->builderClassName, [ 'templateFactory' => $this->templateFactoryMock, 'message' => $this->messageMock, 'objectManager' => $this->objectManagerMock, 'senderResolver' => $this->senderResolverMock, - 'mailTransportFactory' => $this->_mailTransportFactoryMock + 'mailTransportFactory' => $this->mailTransportFactoryMock ] ); } @@ -69,93 +73,60 @@ public function setUp() * @param int $templateType * @param string $messageType * @param string $bodyText + * @param string $templateNamespace + * @return void */ - public function testGetTransport($templateType, $messageType, $bodyText) + public function testGetTransport($templateType, $messageType, $bodyText, $templateNamespace) { + $this->builder->setTemplateNamespace($templateNamespace); + $vars = ['reason' => 'Reason', 'customer' => 'Customer']; $options = ['area' => 'frontend', 'store' => 1]; + $template = $this->getMock('\Magento\Framework\Mail\TemplateInterface'); - $template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->will($this->returnSelf()); - $template->expects( - $this->once() - )->method( - 'setOptions' - )->with( - $this->equalTo($options) - )->will( - $this->returnSelf() - ); - $template->expects($this->once())->method('getSubject')->will($this->returnValue('Email Subject')); - $template->expects($this->once())->method('getType')->will($this->returnValue($templateType)); - $template->expects($this->once())->method('processTemplate')->will($this->returnValue($bodyText)); + $template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->willReturnSelf(); + $template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->willReturnSelf(); + $template->expects($this->once())->method('getSubject')->willReturn('Email Subject'); + $template->expects($this->once())->method('getType')->willReturn($templateType); + $template->expects($this->once())->method('processTemplate')->willReturn($bodyText); - $this->templateFactoryMock->expects( - $this->once() - )->method( - 'get' - )->with( - $this->equalTo('identifier') - )->will( - $this->returnValue($template) - ); + $this->templateFactoryMock->expects($this->once()) + ->method('get') + ->with($this->equalTo('identifier'), $this->equalTo($templateNamespace)) + ->willReturn($template); - $this->messageMock->expects( - $this->once() - )->method( - 'setSubject' - )->with( - $this->equalTo('Email Subject') - )->will( - $this->returnSelf() - ); - $this->messageMock->expects( - $this->once() - )->method( - 'setMessageType' - )->with( - $this->equalTo($messageType) - )->will( - $this->returnSelf() - ); - $this->messageMock->expects( - $this->once() - )->method( - 'setBody' - )->with( - $this->equalTo($bodyText) - )->will( - $this->returnSelf() - ); + $this->messageMock->expects($this->once()) + ->method('setSubject') + ->with($this->equalTo('Email Subject')) + ->willReturnSelf(); + $this->messageMock->expects($this->once()) + ->method('setMessageType') + ->with($this->equalTo($messageType)) + ->willReturnSelf(); + $this->messageMock->expects($this->once()) + ->method('setBody') + ->with($this->equalTo($bodyText)) + ->willReturnSelf(); $transport = $this->getMock('\Magento\Framework\Mail\TransportInterface'); - $this->_mailTransportFactoryMock->expects( - $this->at(0) - )->method( - 'create' - )->with( - $this->equalTo(['message' => $this->messageMock]) - )->will( - $this->returnValue($transport) - ); + $this->mailTransportFactoryMock->expects($this->at(0)) + ->method('create') + ->with($this->equalTo(['message' => $this->messageMock])) + ->willReturn($transport); - $this->objectManagerMock->expects( - $this->at(0) - )->method( - 'create' - )->with( - $this->equalTo('Magento\Framework\Mail\Message') - )->will( - $this->returnValue($transport) - ); + $this->objectManagerMock->expects($this->at(0)) + ->method('create') + ->with($this->equalTo('Magento\Framework\Mail\Message')) + ->willReturn($transport); $this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options); - - $result = $this->builder->getTransport(); - - $this->assertInstanceOf('Magento\Framework\Mail\TransportInterface', $result); + $this->assertInstanceOf('Magento\Framework\Mail\TransportInterface', $this->builder->getTransport()); } + /** + * @return array + */ public function getTransportDataProvider() { return [ From 580e9bf33b2c7ba87b0076295af9f823e208a230 Mon Sep 17 00:00:00 2001 From: Anna Bukatar Date: Wed, 18 Nov 2015 16:18:23 +0200 Subject: [PATCH 06/10] MDVA-7: Link in admin user forgot password email results in 404 error - Fixed errors with unit tests --- .../Unit/Model/Queue/TransportBuilderTest.php | 2 +- .../Magento/User/Test/Unit/Model/UserTest.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php index 52a501f9ef3b6..2148585197063 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php @@ -95,7 +95,7 @@ public function testGetTransport( $transport = $this->getMock('\Magento\Framework\Mail\TransportInterface'); - $this->_mailTransportFactoryMock->expects( + $this->mailTransportFactoryMock->expects( $this->at(0) )->method( 'create' diff --git a/app/code/Magento/User/Test/Unit/Model/UserTest.php b/app/code/Magento/User/Test/Unit/Model/UserTest.php index 08547ba0e52d7..1c3ae6d1ead66 100644 --- a/app/code/Magento/User/Test/Unit/Model/UserTest.php +++ b/app/code/Magento/User/Test/Unit/Model/UserTest.php @@ -51,7 +51,7 @@ class UserTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $eventManagerMock; - /** @var \Magento\Framework\Validator\DataObjectFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Framework\Validator\ObjectFactory|\PHPUnit_Framework_MockObject_MockObject */ protected $validatorObjectFactoryMock; /** @var \Magento\User\Model\UserValidationRules|\PHPUnit_Framework_MockObject_MockObject */ @@ -73,7 +73,7 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods([]) ->getMock(); - $this->resourceMock = $this->getMockBuilder('Magento\User\Model\ResourceModel\User') + $this->resourceMock = $this->getMockBuilder('Magento\User\Model\Resource\User') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); @@ -89,7 +89,7 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['dispatch']) ->getMockForAbstractClass(); - $this->validatorObjectFactoryMock = $this->getMockBuilder('Magento\Framework\Validator\DataObjectFactory') + $this->validatorObjectFactoryMock = $this->getMockBuilder('Magento\Framework\Validator\ObjectFactory') ->disableOriginalConstructor()->setMethods(['create']) ->getMock(); $this->roleFactoryMock = $this->getMockBuilder('Magento\Authorization\Model\RoleFactory') @@ -313,7 +313,7 @@ public function testVerifyIdentityInactiveRecord() $this->model->setIsActive(false); $this->setExpectedException( 'Magento\\Framework\\Exception\\AuthenticationException', - 'You did not sign in correctly or your account is temporarily disabled.' + 'This account is inactive.' ); $this->model->verifyIdentity($password); } @@ -381,8 +381,8 @@ public function testBeforeSave() */ public function testValidateOk() { - /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */ - $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\DataObject') + /** @var $validatorMock \Magento\Framework\Validator\Object|\PHPUnit_Framework_MockObject_MockObject */ + $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\Object') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); @@ -400,8 +400,8 @@ public function testValidateOk() public function testValidateInvalid() { $messages = ['Invalid username']; - /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */ - $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\DataObject') + /** @var $validatorMock \Magento\Framework\Validator\Object|\PHPUnit_Framework_MockObject_MockObject */ + $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\Object') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); From cddd90683f88018310a9cf23e5ff9e12a3881a77 Mon Sep 17 00:00:00 2001 From: Anna Bukatar Date: Wed, 18 Nov 2015 19:17:50 +0200 Subject: [PATCH 07/10] MDVA-7: Link in admin user forgot password email results in 404 error - Fixed errors with bamboo tests --- .../User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php | 2 +- app/code/Magento/User/etc/module.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php b/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php index be819b6e8c9bc..8a486e4a745b7 100644 --- a/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php +++ b/app/code/Magento/User/Test/Unit/Model/Plugin/AuthorizationRoleTest.php @@ -46,7 +46,7 @@ protected function setUp() public function testAfterSave() { - $this->userResourceModelMock->expects($this->once())->method('updateRoleUsersAcl')->with($this->roleMock); + $this->userResourceModelMock->expects($this->once())->method('updateRoleUsersAcl')->with($this->roleMock); $this->assertInstanceOf( '\Magento\Authorization\Model\Role', $this->model->afterSave($this->roleMock, $this->roleMock) diff --git a/app/code/Magento/User/etc/module.xml b/app/code/Magento/User/etc/module.xml index d0467cb70e860..27e9687602945 100644 --- a/app/code/Magento/User/etc/module.xml +++ b/app/code/Magento/User/etc/module.xml @@ -9,6 +9,7 @@ + From bc6ce8cad22fb772cbdfcdc73309af01c28bdb52 Mon Sep 17 00:00:00 2001 From: Anna Bukatar Date: Wed, 18 Nov 2015 19:57:04 +0200 Subject: [PATCH 08/10] MDVA-7: Link in admin user forgot password email results in 404 error - Conflict resolving --- app/code/Magento/User/composer.json | 1 + app/code/Magento/User/etc/module.xml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/User/composer.json b/app/code/Magento/User/composer.json index 7f0260d1e5074..db9427dae1788 100644 --- a/app/code/Magento/User/composer.json +++ b/app/code/Magento/User/composer.json @@ -7,6 +7,7 @@ "magento/module-authorization": "1.0.0-beta7", "magento/module-backend": "1.0.0-beta7", "magento/module-integration": "1.0.0-beta7", + "magento/module-email": "1.0.0-beta7", "magento/framework": "1.0.0-beta7", "magento/magento-composer-installer": "*" }, diff --git a/app/code/Magento/User/etc/module.xml b/app/code/Magento/User/etc/module.xml index 27e9687602945..d0467cb70e860 100644 --- a/app/code/Magento/User/etc/module.xml +++ b/app/code/Magento/User/etc/module.xml @@ -9,7 +9,6 @@ - From aecb82ef64c8e760d85bb804f288ae3a482e6b78 Mon Sep 17 00:00:00 2001 From: akaplya Date: Fri, 13 Nov 2015 14:39:40 +0200 Subject: [PATCH 09/10] MAGETWO-44191: Random exception during using admin "Unable to send the cookie. Maximum number of cookies would be exceeded." --- .../Magento/Framework/Stdlib/Cookie/PhpCookieManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php b/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php index 611683a912530..f34e0064930e8 100644 --- a/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php +++ b/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php @@ -22,9 +22,9 @@ class PhpCookieManager implements CookieManagerInterface /**#@+ * Constants for Cookie manager. * RFC 2109 - Page 15 - * http://www.ietf.org/rfc/rfc2109.txt + * http://www.ietf.org/rfc/rfc6265.txt */ - const MAX_NUM_COOKIES = 20; + const MAX_NUM_COOKIES = 50; const MAX_COOKIE_SIZE = 4096; const EXPIRE_NOW_TIME = 1; const EXPIRE_AT_END_OF_SESSION_TIME = 0; From 9a577bd7cb345635c8551551b8464d67df26cab2 Mon Sep 17 00:00:00 2001 From: akaplya Date: Fri, 13 Nov 2015 17:00:28 +0200 Subject: [PATCH 10/10] MAGETWO-44191: Random exception during using admin "Unable to send the cookie. Maximum number of cookies would be exceeded." --- .../Magento/Framework/Stdlib/Cookie/PhpCookieManager.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php b/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php index f34e0064930e8..6e23952d787f5 100644 --- a/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php +++ b/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php @@ -16,6 +16,8 @@ * To aid in security, the cookie manager will make it possible for the application to indicate if the cookie contains * sensitive data so that extra protection can be added to the contents of the cookie as well as how the browser * stores the cookie. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class PhpCookieManager implements CookieManagerInterface {