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