public function testSaveExtraFilledId() { $uid = 123; $this->userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid); $this->resourceMock->expects($this->once())->method('getConnection')->willReturn($this->dbAdapterMock); $this->dbAdapterMock->expects($this->once())->method('update'); $this->assertInstanceOf('Magento\\User\\Model\\ResourceModel\\User', $this->model->saveExtra($this->userMock, [1, 2, 3])); }
public function testBeforeSave() { $this->userMock->expects($this->once())->method('isObjectNew')->willReturn(true); $this->assertInstanceOf( '\Magento\User\Model\ResourceModel\User', $this->invokeMethod($this->model, '_beforeSave', [$this->userMock]) ); }
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(); }
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(); }
/** * @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(); }
/** * @param string $actionName * @return \Magento\Integration\Controller\Adminhtml\Integration * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _createIntegrationController($actionName) { // Mock Layout passed into constructor $this->_viewMock = $this->getMockBuilder('Magento\\Framework\\App\\ViewInterface')->getMock(); $this->_layoutMock = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $this->_layoutMergeMock = $this->getMockBuilder('Magento\\Framework\\View\\Model\\Layout\\Merge')->disableOriginalConstructor()->getMock(); $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnValue($this->_layoutMergeMock)); $testElement = new \Magento\Framework\Simplexml\Element('<test>test</test>'); $this->_layoutMock->expects($this->any())->method('getNode')->will($this->returnValue($testElement)); // for _setActiveMenu $this->_viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->_layoutMock)); $blockMock = $this->getMockBuilder('Magento\\Backend\\Block\\Menu')->disableOriginalConstructor()->getMock(); $menuMock = $this->getMock('Magento\\Backend\\Model\\Menu', [], [$this->getMock('Psr\\Log\\LoggerInterface')]); $loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $loggerMock->expects($this->any())->method('critical')->will($this->returnSelf()); $menuMock->expects($this->any())->method('getParentItems')->will($this->returnValue([])); $blockMock->expects($this->any())->method('getMenuModel')->will($this->returnValue($menuMock)); $this->_layoutMock->expects($this->any())->method('getMessagesBlock')->will($this->returnValue($blockMock)); $this->_layoutMock->expects($this->any())->method('getBlock')->will($this->returnValue($blockMock)); $this->_viewMock->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->viewConfigMock); $this->viewConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock); $this->_escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); $this->resultRedirectFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_authMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock)); $this->_userMock->expects($this->any())->method('load')->willReturn($this->_userMock); $this->_backendSessionMock->expects($this->any())->method('getIntegrationData')->willReturn(['all_resources' => 1]); $contextParameters = ['view' => $this->_viewMock, 'objectManager' => $this->_objectManagerMock, 'session' => $this->_backendSessionMock, 'translator' => $this->_translateModelMock, 'request' => $this->_requestMock, 'response' => $this->_responseMock, 'messageManager' => $this->_messageManager, 'resultRedirectFactory' => $this->resultRedirectFactory, 'resultFactory' => $this->resultFactory, 'auth' => $this->_authMock, 'eventManager' => $this->_eventManagerMock]; $this->_backendActionCtxMock = $this->_objectManagerHelper->getObject('Magento\\Backend\\App\\Action\\Context', $contextParameters); $integrationCollection = $this->getMockBuilder('\\Magento\\Integration\\Model\\ResourceModel\\Integration\\Collection')->disableOriginalConstructor()->setMethods(['addUnsecureUrlsFilter', 'getSize'])->getMock(); $integrationCollection->expects($this->any())->method('addUnsecureUrlsFilter')->will($this->returnValue($integrationCollection)); $integrationCollection->expects($this->any())->method('getSize')->will($this->returnValue(0)); $subControllerParams = ['context' => $this->_backendActionCtxMock, 'integrationService' => $this->_integrationSvcMock, 'oauthService' => $this->_oauthSvcMock, 'registry' => $this->_registryMock, 'logger' => $loggerMock, 'integrationData' => $this->_integrationHelperMock, 'escaper' => $this->_escaper, 'integrationCollection' => $integrationCollection]; /** Create IntegrationController to test */ $controller = $this->_objectManagerHelper->getObject('\\Magento\\Integration\\Controller\\Adminhtml\\Integration\\' . $actionName, $subControllerParams); if ($actionName == 'Save') { $reflection = new \ReflectionClass(get_class($controller)); $reflectionProperty = $reflection->getProperty('securityCookie'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($controller, $this->securityCookieMock); } return $controller; }