function UserRegistrationResourceTest::testRegistrationAnonymousOnlyPost

Tests that only anonymous users can register users.

File

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

Class

UserRegistrationResourceTest
Tests User Registration REST resource.

Namespace

Drupal\Tests\user\Unit

Code

public function testRegistrationAnonymousOnlyPost() : void {
  $this->currentUser
    ->isAnonymous()
    ->willReturn(FALSE);
  $this->testClass = new UserRegistrationResource([], 'plugin_id', '', [], $this->logger, $this->userSettings
    ->reveal(), $this->currentUser
    ->reveal(), $this->passwordGenerator);
  $entity = $this->prophesize(User::class);
  $entity->isNew()
    ->willReturn(TRUE);
  $this->expectException(AccessDeniedHttpException::class);
  $this->testClass
    ->post($entity->reveal());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.