Chris@0: logger = $this->prophesize(LoggerInterface::class)->reveal(); Chris@0: Chris@0: $this->userSettings = $this->prophesize(ImmutableConfig::class); Chris@0: Chris@0: $this->currentUser = $this->prophesize(AccountInterface::class); Chris@0: Chris@0: $this->testClass = new UserRegistrationResource([], 'plugin_id', '', [], $this->logger, $this->userSettings->reveal(), $this->currentUser->reveal()); Chris@0: $this->reflection = new \ReflectionClass($this->testClass); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that an exception is thrown when no data provided for the account. Chris@0: */ Chris@0: public function testEmptyPost() { Chris@0: $this->setExpectedException(BadRequestHttpException::class); Chris@0: $this->testClass->post(NULL); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that only new user accounts can be registered. Chris@0: */ Chris@0: public function testExistedEntityPost() { Chris@0: $entity = $this->prophesize(User::class); Chris@0: $entity->isNew()->willReturn(FALSE); Chris@0: $this->setExpectedException(BadRequestHttpException::class); Chris@0: Chris@0: $this->testClass->post($entity->reveal()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that admin permissions are required to register a user account. Chris@0: */ Chris@0: public function testRegistrationAdminOnlyPost() { Chris@0: Chris@18: $this->userSettings->get('register')->willReturn(UserInterface::REGISTER_ADMINISTRATORS_ONLY); Chris@0: Chris@0: $this->currentUser->isAnonymous()->willReturn(TRUE); Chris@0: Chris@0: $this->testClass = new UserRegistrationResource([], 'plugin_id', '', [], $this->logger, $this->userSettings->reveal(), $this->currentUser->reveal()); Chris@0: Chris@0: $entity = $this->prophesize(User::class); Chris@0: $entity->isNew()->willReturn(TRUE); Chris@0: Chris@0: $this->setExpectedException(AccessDeniedHttpException::class); Chris@0: Chris@0: $this->testClass->post($entity->reveal()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that only anonymous users can register users. Chris@0: */ Chris@0: public function testRegistrationAnonymousOnlyPost() { Chris@0: $this->currentUser->isAnonymous()->willReturn(FALSE); Chris@0: Chris@0: $this->testClass = new UserRegistrationResource([], 'plugin_id', '', [], $this->logger, $this->userSettings->reveal(), $this->currentUser->reveal()); Chris@0: Chris@0: $entity = $this->prophesize(User::class); Chris@0: $entity->isNew()->willReturn(TRUE); Chris@0: Chris@0: $this->setExpectedException(AccessDeniedHttpException::class); Chris@0: Chris@0: $this->testClass->post($entity->reveal()); Chris@0: } Chris@0: Chris@0: }