You are here

public function ControllerTest::testController in Authorization 8

Test processing authorizations.

File

tests/src/Kernel/ControllerTest.php, line 48

Class

ControllerTest
Test description.

Namespace

Drupal\Tests\authorization\Kernel

Code

public function testController() : void {
  $user = $this
    ->createUser();
  $user
    ->save();
  $user->proposals = [
    'student',
  ];

  /** @var \Drupal\authorization\AuthorizationController $controller */
  $controller = $this->container
    ->get('authorization.manager');
  $controller
    ->setUser($user);
  $controller
    ->queryAllProfiles();
  $authorizations = $controller
    ->getProcessedAuthorizations();
  $authorization = reset($authorizations);
  self::assertArrayHasKey('student', $authorization
    ->getAuthorizationsApplied());
  $controller
    ->clearAuthorizations();
  $user->proposals = [
    'exception',
  ];
  $controller
    ->queryAllProfiles();
  $authorizations = $controller
    ->getProcessedAuthorizations();
  $authorization = reset($authorizations);
  self::assertEmpty($authorization
    ->getAuthorizationsApplied());
  self::assertEquals(TRUE, $authorization
    ->getSkipped());
}