You are here

public function AccessResultTest::testConstruction in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testConstruction()
  2. 10 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testConstruction()

Tests the construction of an AccessResult object.

@covers ::neutral

File

core/tests/Drupal/Tests/Core/Access/AccessResultTest.php, line 61
Contains \Drupal\Tests\Core\Access\AccessResultTest.

Class

AccessResultTest
@coversDefaultClass \Drupal\Core\Access\AccessResult @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testConstruction() {
  $verify = function (AccessResult $access) {
    $this
      ->assertFalse($access
      ->isAllowed());
    $this
      ->assertFalse($access
      ->isForbidden());
    $this
      ->assertTrue($access
      ->isNeutral());
    $this
      ->assertDefaultCacheability($access);
  };

  // Verify the object when using the constructor.
  $a = new AccessResultNeutral();
  $verify($a);

  // Verify the object when using the ::create() convenience method.
  $b = AccessResult::neutral();
  $verify($b);
  $this
    ->assertEquals($a, $b);
}