You are here

class UncacheableTestAccessResult in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\UncacheableTestAccessResult
  2. 9 core/tests/Drupal/Tests/Core/Access/AccessResultTest.php \Drupal\Tests\Core\Access\UncacheableTestAccessResult

Hierarchy

Expanded class hierarchy of UncacheableTestAccessResult

File

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

Namespace

Drupal\Tests\Core\Access
View source
class UncacheableTestAccessResult implements AccessResultInterface {

  /**
   * The access result value. 'ALLOWED', 'FORBIDDEN' or 'NEUTRAL'.
   *
   * @var string
   */
  protected $value;

  /**
   * Constructs a new UncacheableTestAccessResult object.
   */
  public function __construct($value) {
    $this->value = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function isAllowed() {
    return $this->value === 'ALLOWED';
  }

  /**
   * {@inheritdoc}
   */
  public function isForbidden() {
    return $this->value === 'FORBIDDEN';
  }

  /**
   * {@inheritdoc}
   */
  public function isNeutral() {
    return $this->value === 'NEUTRAL';
  }

  /**
   * {@inheritdoc}
   */
  public function orIf(AccessResultInterface $other) {
    if ($this
      ->isForbidden() || $other
      ->isForbidden()) {
      return new static('FORBIDDEN');
    }
    elseif ($this
      ->isAllowed() || $other
      ->isAllowed()) {
      return new static('ALLOWED');
    }
    else {
      return new static('NEUTRAL');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function andIf(AccessResultInterface $other) {
    if ($this
      ->isForbidden() || $other
      ->isForbidden()) {
      return new static('FORBIDDEN');
    }
    elseif ($this
      ->isAllowed() && $other
      ->isAllowed()) {
      return new static('ALLOWED');
    }
    else {
      return new static('NEUTRAL');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UncacheableTestAccessResult::$value protected property The access result value. 'ALLOWED', 'FORBIDDEN' or 'NEUTRAL'.
UncacheableTestAccessResult::andIf public function Combine this access result with another using AND. Overrides AccessResultInterface::andIf
UncacheableTestAccessResult::isAllowed public function Checks whether this access result indicates access is explicitly allowed. Overrides AccessResultInterface::isAllowed
UncacheableTestAccessResult::isForbidden public function Checks whether this access result indicates access is explicitly forbidden. Overrides AccessResultInterface::isForbidden
UncacheableTestAccessResult::isNeutral public function Checks whether this access result indicates access is not yet determined. Overrides AccessResultInterface::isNeutral
UncacheableTestAccessResult::orIf public function Combine this access result with another using OR. Overrides AccessResultInterface::orIf
UncacheableTestAccessResult::__construct public function Constructs a new UncacheableTestAccessResult object.