function EntityViewTest::testAccess

Same name in other branches
  1. 4.0.x tests/src/Kernel/Plugin/Block/EntityViewTest.php \Drupal\Tests\ctools\Kernel\Plugin\Block\EntityViewTest::testAccess()

Tests plugin access.

@covers ::access

File

tests/src/Kernel/Plugin/Block/EntityViewTest.php, line 59

Class

EntityViewTest
Tests the entity_view block plugin.

Namespace

Drupal\Tests\ctools\Kernel\Plugin\Block

Code

public function testAccess() {
    // Create an unpublished node.
    $node = $this->createNode([
        'status' => 0,
    ]);
    $configuration = [
        'view_mode' => 'default',
    ];
    $definition = [
        'context_definitions' => [
            'entity' => new EntityContextDefinition('entity:node', NULL, TRUE, FALSE, NULL, $node),
        ],
        'provider' => 'ctools',
    ];
    $block = EntityView::create($this->container, $configuration, 'entity_view:node', $definition);
    $block->setContextValue('entity', $node);
    $access = $block->access(\Drupal::currentUser());
    $this->assertFalse($access);
    // Add a user than can see the unpublished block.
    $account = $this->createUser([], NULL, TRUE);
    $access = $block->access($account);
    $this->assertTrue($access);
}