You are here

public function EntityViewTest::testAccess in Chaos Tool Suite (ctools) 8.3

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',
    'context' => [
      'entity' => $node,
    ],
  ];
  $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);
  $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);
}