You are here

public function AccessResultTest::testOrIf in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\AccessResultTest::testOrIf()

@covers ::orIf

File

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

Class

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

Namespace

Drupal\Tests\Core\Access

Code

public function testOrIf() {
  $neutral = AccessResult::neutral();
  $allowed = AccessResult::allowed();
  $forbidden = AccessResult::forbidden();
  $unused_access_result_due_to_lazy_evaluation = $this
    ->getMock('\\Drupal\\Core\\Access\\AccessResultInterface');
  $unused_access_result_due_to_lazy_evaluation
    ->expects($this
    ->never())
    ->method($this
    ->anything());

  // ALLOWED || ALLOWED === ALLOWED.
  $access = $allowed
    ->orIf($allowed);
  $this
    ->assertTrue($access
    ->isAllowed());
  $this
    ->assertFalse($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // ALLOWED || NEUTRAL === ALLOWED.
  $access = $allowed
    ->orIf($neutral);
  $this
    ->assertTrue($access
    ->isAllowed());
  $this
    ->assertFalse($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // ALLOWED || FORBIDDEN === FORBIDDEN.
  $access = $allowed
    ->orIf($forbidden);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertTrue($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // NEUTRAL || NEUTRAL === NEUTRAL.
  $access = $neutral
    ->orIf($neutral);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertFalse($access
    ->isForbidden());
  $this
    ->assertTrue($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // NEUTRAL || ALLOWED === ALLOWED.
  $access = $neutral
    ->orIf($allowed);
  $this
    ->assertTrue($access
    ->isAllowed());
  $this
    ->assertFalse($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // NEUTRAL || FORBIDDEN === FORBIDDEN.
  $access = $neutral
    ->orIf($forbidden);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertTrue($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // FORBIDDEN || ALLOWED === FORBIDDEN.
  $access = $forbidden
    ->orIf($allowed);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertTrue($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // FORBIDDEN || NEUTRAL === FORBIDDEN.
  $access = $forbidden
    ->orIf($allowed);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertTrue($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // FORBIDDEN || FORBIDDEN === FORBIDDEN.
  $access = $forbidden
    ->orIf($allowed);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertTrue($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);

  // FORBIDDEN || * === FORBIDDEN.
  $access = $forbidden
    ->orIf($unused_access_result_due_to_lazy_evaluation);
  $this
    ->assertFalse($access
    ->isAllowed());
  $this
    ->assertTrue($access
    ->isForbidden());
  $this
    ->assertFalse($access
    ->isNeutral());
  $this
    ->assertDefaultCacheability($access);
}