Example #1
0
 /**
  * @param int|null $userId
  * @return void
  */
 public function setupUserId($userId)
 {
     $this->adminSession->expects($this->once())->method('hasUser')->will($this->returnValue($userId));
     if ($userId) {
         $this->adminSession->expects($this->once())->method('getUser')->will($this->returnSelf());
         $this->adminSession->expects($this->once())->method('getId')->will($this->returnValue($userId));
     }
 }
Example #2
0
 protected function setUp()
 {
     $this->_session = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false);
     $this->_authSession = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', ['getUser'], [], '', false);
     $userMock = new \Magento\Framework\Object();
     $this->_authSession->expects($this->any())->method('getUser')->will($this->returnValue($userMock));
     $this->_translator = $this->getMock('Magento\\Framework\\TranslateInterface', [], [], '', false);
     $this->_translator->expects($this->any())->method('setLocale')->will($this->returnValue($this->_translator));
     $this->_translator->expects($this->any())->method('init')->will($this->returnValue(false));
     $this->_model = new \Magento\Backend\Model\Locale\Manager($this->_session, $this->_authSession, $this->_translator);
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentAdminsToNewRelic()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlushToNewRelic()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $userMock->expects($this->once())->method('getId')->willReturn('2');
     $this->deploymentsFactory->expects($this->once())->method('create')->willReturn($this->deploymentsModel);
     $this->deploymentsModel->expects($this->once())->method('setDeployment')->willReturnSelf();
     $this->model->execute($eventObserver);
 }
 /**
  * @return void
  */
 public function testAroundProlongSessionIsNotActiveAndIsAjaxRequest()
 {
     $result = 'result';
     $status = 1;
     $proceed = function () use($result) {
         return $result;
     };
     $this->currentSessionMock->expects($this->any())->method('isActive')->willReturn(false);
     $this->authSessionMock->expects($this->once())->method('destroy');
     $this->requestMock->expects($this->once())->method('getParam')->with('isAjax')->willReturn(true);
     $this->currentSessionMock->expects($this->once())->method('getStatus')->willReturn($status);
     $this->securityCookieMock->expects($this->once())->method('setLogoutReasonCookie')->with($status)->willReturnSelf();
     $this->model->aroundProlong($this->authSessionMock, $proceed);
 }
 public function testAdminAuthenticate()
 {
     $password = "******";
     $uid = 123;
     $authResult = true;
     $lockExpires = false;
     $userPassword = ['expires' => 1];
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getPassword', 'getUser', 'getResult'])->getMock();
     /** @var ModelUser|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getLockExpires', 'getPassword', 'save'])->getMock();
     $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getPassword')->willReturn($password);
     $eventMock->expects($this->once())->method('getUser')->willReturn($userMock);
     $eventMock->expects($this->once())->method('getResult')->willReturn($authResult);
     $userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid);
     $userMock->expects($this->once())->method('getLockExpires')->willReturn($lockExpires);
     $this->userMock->expects($this->once())->method('unlock');
     $this->userMock->expects($this->once())->method('getLatestPassword')->willReturn($userPassword);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getLastAddedMessage')->willReturn($this->messageInterfaceMock);
     $this->messageInterfaceMock->expects($this->once())->method('setIdentifier')->willReturnSelf();
     $this->authSessionMock->expects($this->once())->method('setPciAdminUserIsPasswordExpired');
     $this->encryptorMock->expects($this->once())->method('validateHashVersion')->willReturn(false);
     $this->model->execute($eventObserverMock);
 }
Example #7
0
 protected function setUp()
 {
     $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_group = $this->getMock('Magento\\Config\\Model\\Config\\Structure\\Element\\Group', [], [], '', false);
     $this->_element = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false, true, true, ['getHtmlId', 'getElementHtml', 'getName', 'getElements', 'getId']);
     $this->_element->expects($this->any())->method('getHtmlId')->will($this->returnValue('html id'));
     $this->_element->expects($this->any())->method('getElementHtml')->will($this->returnValue('element html'));
     $this->_element->expects($this->any())->method('getName')->will($this->returnValue('name'));
     $this->_element->expects($this->any())->method('getElements')->will($this->returnValue([]));
     $this->_element->expects($this->any())->method('getId')->will($this->returnValue('id'));
     $this->_user = $this->getMock('Magento\\User\\Model\\User', [], [], '', false);
     $this->_authSession = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', [], [], '', false);
     $this->_authSession->expects($this->any())->method('__call')->with('getUser')->will($this->returnValue($this->_user));
     $this->_model = $helper->getObject('Magento\\Paypal\\Block\\Adminhtml\\System\\Config\\Fieldset\\Group', ['authSession' => $this->_authSession]);
     $this->_model->setGroup($this->_group);
 }
Example #8
0
 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = array('password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**');
     $testedMessage = 'The account has been saved.';
     $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true));
     $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock));
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Locale\\Validator'))->will($this->returnValue($this->_validatorMock));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock));
     $this->_userMock->setUserId($userId);
     $this->_userMock->expects($this->once())->method('save');
     $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->_requestMock->setParams($requestParams);
     $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->_controller->execute();
 }
Example #9
0
 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = ['password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**', \Magento\Backend\Block\System\Account\Edit\Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password'];
     $testedMessage = 'You saved the account.';
     $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true));
     $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock));
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Validator\\Locale'))->will($this->returnValue($this->_validatorMock));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock));
     $this->_userMock->setUserId($userId);
     $this->_userMock->expects($this->once())->method('save');
     $this->_userMock->expects($this->once())->method('verifyIdentity')->will($this->returnValue(true));
     $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->_requestMock->setParams($requestParams);
     $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->_controller->execute();
 }
 public function testTrackAdminPassword()
 {
     $newPW = "mYn3wpassw0rd";
     $uid = 123;
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getObject'])->getMock();
     /** @var \Magento\User\Model\User|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getPassword', 'getForceNewPassword'])->getMock();
     $eventObserverMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getObject')->willReturn($userMock);
     $userMock->expects($this->once())->method('getId')->willReturn($uid);
     $userMock->expects($this->once())->method('getPassword')->willReturn($newPW);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     $userMock->expects($this->once())->method('getForceNewPassword')->willReturn(false);
     /** @var \Magento\Framework\Message\Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock);
     $this->authSessionMock->expects($this->once())->method('unsPciAdminUserIsPasswordExpired')->willReturn(null);
     $this->model->execute($eventObserverMock);
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentAdmins()
 {
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'admin_activity', 'action' => $testAction])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
 public function testForceAdminPasswordChange()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getControllerAction', 'getRequest'])->getMock();
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     $this->authSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
     /** @var \Magento\Framework\App\Action\Action $controllerMock */
     $controllerMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\AbstractAction')->disableOriginalConstructor()->setMethods(['getRedirect', 'getRequest'])->getMockForAbstractClass();
     /** @var \Magento\Framework\App\RequestInterface $requestMock */
     $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getFullActionName', 'setDispatched'])->getMockForAbstractClass();
     $eventMock->expects($this->once())->method('getControllerAction')->willReturn($controllerMock);
     $eventMock->expects($this->once())->method('getRequest')->willReturn($requestMock);
     $this->authSessionMock->expects($this->once())->method('getPciAdminUserIsPasswordExpired')->willReturn(true);
     $requestMock->expects($this->once())->method('getFullActionName')->willReturn('not_in_array');
     $this->authSessionMock->expects($this->once())->method('clearStorage');
     $this->sessionMock->expects($this->once())->method('clearStorage');
     $this->managerInterfaceMock->expects($this->once())->method('addErrorMessage');
     $controllerMock->expects($this->once())->method('getRequest')->willReturn($requestMock);
     $requestMock->expects($this->once())->method('setDispatched')->willReturn(false);
     $this->model->execute($eventObserverMock);
 }
 /**
  * @return void
  */
 public function testLogoutOtherUserSessions()
 {
     $useId = 1;
     $sessionLifetime = 100;
     $sessionId = 50;
     $this->adminSessionInfoCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->adminSessionInfoCollectionMock);
     $this->authSessionMock->expects($this->once())->method('getUser')->willReturn($this->userMock);
     $this->authSessionMock->expects($this->once())->method('getSessionId')->willReturn($sessionId);
     $this->userMock->expects($this->once())->method('getId')->willReturn($useId);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')->with($useId, \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $sessionId)->willReturnSelf();
     $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->willReturn($sessionLifetime);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterExpiredSessions')->with($sessionLifetime)->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('loadData')->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('setDataToAll')->with($this->equalTo('status'), \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('save');
     $this->model->logoutOtherUserSessions();
 }