function UserAnonymousActivateTest::testAnonymousActivate

Same name in other branches
  1. 11.x core/modules/user/tests/src/Kernel/UserAnonymousActivateTest.php \Drupal\Tests\user\Kernel\UserAnonymousActivateTest::testAnonymousActivate()

Tests that the anonymous user cannot be activated.

File

core/modules/user/tests/src/Kernel/UserAnonymousActivateTest.php, line 34

Class

UserAnonymousActivateTest
Tests unblocking the anonymous user account.

Namespace

Drupal\Tests\user\Kernel

Code

public function testAnonymousActivate() : void {
    $accountAnon = \Drupal::entityTypeManager()->getStorage('user')
        ->load(0);
    // Test that the anonymous user is blocked.
    $this->assertTrue($accountAnon->isBlocked());
    // Test that the anonymous user cannot be activated.
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage('The anonymous user account should remain blocked at all times.');
    $accountAnon->activate();
}

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