objectManager = new ObjectManager($this); $this->request = $this->createMock(\Magento\Framework\App\RequestInterface::class); $this->securityManager = $this->createPartialMock( \Magento\Security\Model\SecurityManager::class, ['performSecurityCheck'] ); $this->accountManagement = $this->createMock(AccountManagement::class); $this->scope = $this->createMock(ScopeInterface::class); } /** * @param $area * @param $passwordRequestEvent * @param $expectedTimes * @dataProvider beforeInitiatePasswordResetDataProvider */ public function testBeforeInitiatePasswordReset($area, $passwordRequestEvent, $expectedTimes) { $email = 'test@example.com'; $template = AccountManagement::EMAIL_RESET; $this->model = $this->objectManager->getObject( \Magento\Security\Model\Plugin\AccountManagement::class, [ 'passwordRequestEvent' => $passwordRequestEvent, 'request' => $this->request, 'securityManager' => $this->securityManager, 'scope' => $this->scope ] ); $this->scope->expects($this->once()) ->method('getCurrentScope') ->willReturn($area); $this->securityManager->expects($this->exactly($expectedTimes)) ->method('performSecurityCheck') ->with($passwordRequestEvent, $email) ->willReturnSelf(); $this->model->beforeInitiatePasswordReset( $this->accountManagement, $email, $template ); } /** * @return array */ public function beforeInitiatePasswordResetDataProvider() { return [ [Area::AREA_ADMINHTML, PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, 0], [Area::AREA_ADMINHTML, PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, 1], [Area::AREA_FRONTEND, PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST, 1], // This should never happen, but let's cover it with tests [Area::AREA_FRONTEND, PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST, 1], ]; } }