You are here

public function UserRegistrationResourceTest::testRegistrationAdminOnlyPost in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php \Drupal\Tests\user\Unit\UserRegistrationResourceTest::testRegistrationAdminOnlyPost()
  2. 9 core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php \Drupal\Tests\user\Unit\UserRegistrationResourceTest::testRegistrationAdminOnlyPost()

Tests that admin permissions are required to register a user account.

File

core/modules/user/tests/src/Unit/UserRegistrationResourceTest.php, line 98

Class

UserRegistrationResourceTest
Tests User Registration REST resource.

Namespace

Drupal\Tests\user\Unit

Code

public function testRegistrationAdminOnlyPost() {
  $this->userSettings
    ->get('register')
    ->willReturn(UserInterface::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
    ->expectException(AccessDeniedHttpException::class);
  $this->testClass
    ->post($entity
    ->reveal());
}