AccessibleTestingTrait.php

Same filename in other branches
  1. 9 core/modules/block_content/tests/src/Unit/Access/AccessibleTestingTrait.php
  2. 8.9.x core/modules/block_content/tests/src/Unit/Access/AccessibleTestingTrait.php
  3. 10 core/modules/block_content/tests/src/Unit/Access/AccessibleTestingTrait.php

Namespace

Drupal\Tests\block_content\Unit\Access

File

core/modules/block_content/tests/src/Unit/Access/AccessibleTestingTrait.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\block_content\Unit\Access;

use Drupal\Core\Access\AccessibleInterface;
use Drupal\Core\Access\AccessResultInterface;

/**
 * Helper methods testing accessible interfaces.
 */
trait AccessibleTestingTrait {
    
    /**
     * The test account.
     *
     * @var \Drupal\Core\Session\AccountInterface
     */
    protected $account;
    
    /**
     * Creates AccessibleInterface object from access result object for testing.
     *
     * @param \Drupal\Core\Access\AccessResultInterface $accessResult
     *   The accessible result to return.
     *
     * @return \Drupal\Core\Access\AccessibleInterface
     *   The AccessibleInterface object.
     */
    private function createAccessibleDouble(AccessResultInterface $accessResult) {
        $accessible = $this->prophesize(AccessibleInterface::class);
        $accessible->access('view', $this->account, TRUE)
            ->willReturn($accessResult);
        return $accessible->reveal();
    }

}

Traits

Title Deprecated Summary
AccessibleTestingTrait Helper methods testing accessible interfaces.

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