diff --git a/core/modules/rest/tests/src/Unit/UserLoginResourceTest.php b/core/modules/rest/tests/src/Unit/UserLoginResourceTest.php deleted file mode 100644 index a3a274a..0000000 --- a/core/modules/rest/tests/src/Unit/UserLoginResourceTest.php +++ /dev/null @@ -1,199 +0,0 @@ -getMock(UserAuthInterface::class); - $user_auth_service->expects($this->any()) - ->method('authenticate') - ->will($this->returnValue(FALSE)); - - $container = new ContainerBuilder(); - $container->set('user.auth', $user_auth_service); - \Drupal::setContainer($container); - - $this->flood = $this->getMock(FloodInterface::class); - - $this->userStorage = $this->getMockBuilder(UserStorageInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->config = $this->getConfigFactoryStub([ - 'user.flood' => [], - ]); - - $this->logger = $this->getMock('Psr\Log\LoggerInterface'); - - $this->csrfToken = $this->prophesize(CsrfTokenGenerator::class); - - $this->userLoginResource = new TestUserLoginResource([], 'plugin_id', '', [], $this->logger, $this->config, $this->flood, $this->userStorage, $this->csrfToken->reveal(), $user_auth_service); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Missing credentials. - */ - public function testMissingCredentials() { - $this->userLoginResource->post([]); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Missing credentials.pass. - */ - public function testLoginMissingCredentialPass() { - $this->userLoginResource->post(['name' => 'Druplicon']); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Blocked. - */ - public function testLoginBlockedUserByFloodControl() { - $this->flood->expects($this->once()) - ->method('isAllowed') - ->willReturn(FALSE); - - $this->userLoginResource->post(['name' => 'Druplicon', 'pass' => 'SuperSecret']); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage The user has not been activated or is blocked. - */ - public function testLoginBlockedUser() { - $this->flood->expects($this->once()) - ->method('isAllowed') - ->willReturn(TRUE); - - $this->userLoginResource->setUserIsBlocked(TRUE); - - $this->userLoginResource->post(['name' => 'Druplicon', 'pass' => 'SuperSecret']); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Sorry, unrecognized username or password. - */ - public function testLoginUnrecognizedUsernameOrPassword() { - $this->flood->expects($this->once()) - ->method('isAllowed') - ->willReturn(TRUE); - - $this->userLoginResource->setUserIsBlocked(FALSE); - - $this->userLoginResource->post(['name' => 'Druplicon', 'pass' => 'SuperSecret']); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Missing Email or Username. - */ - public function testResetPasswordMissingNameOrEmail() { - $method = $this->getProtectedMethod('requestNewPassword'); - $method->invokeArgs($this->userLoginResource, [['name' => '']]); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Sorry, Druplicon is not recognized as a user name or an e-mail address. - */ - public function testResetPasswordNotRecognizedNameOrEmail() { - $this->userStorage->expects($this->any()) - ->method('loadByProperties') - ->will($this->returnValue([])); - - $method = $this->getProtectedMethod('requestNewPassword'); - $method->invokeArgs($this->userLoginResource, [['name' => 'Druplicon']]); - } -} - -class TestUserLoginResource extends UserLoginResource { - - /** - * @var bool|null - */ - protected $blocked; - - public function setUserIsBlocked($blocked) { - $this->blocked = $blocked; - return $this; - } - - /** - * {@inheritdoc} - */ - protected function userIsBlocked($name) { - if (isset($this->blocked)) { - return $this->blocked; - } - - return parent::userIsBlocked($name); - } - -} diff --git a/core/modules/rest/tests/src/Unit/UserPasswordResetTest.php b/core/modules/rest/tests/src/Unit/UserPasswordResetTest.php deleted file mode 100644 index c51fb22..0000000 --- a/core/modules/rest/tests/src/Unit/UserPasswordResetTest.php +++ /dev/null @@ -1,90 +0,0 @@ -getMock('Drupal\user\UserAuthInterface'); - $user_auth_service->expects($this->any()) - ->method('authenticate') - ->will($this->returnValue(FALSE)); - - $container = new ContainerBuilder(); - $container->set('user.auth', $user_auth_service); - \Drupal::setContainer($container); - - $this->flood = $this->getMock(FloodInterface::class); - - $this->userStorage = $this->getMockBuilder('\Drupal\user\UserStorage') - ->disableOriginalConstructor() - ->getMock(); - - $this->config = $this->getConfigFactoryStub([ - 'user.flood' => [], - ]); - - $this->logger = $this->getMock('Psr\Log\LoggerInterface'); - - $this->csrfToken = $this->prophesize(CsrfTokenGenerator::class); - - $this->userPasswordReset = new UserPasswordReset([], 'plugin_id', '', [], $this->logger, $this->config, $this->flood, $this->userStorage, $this->csrfToken->reveal()); - } - -}