EntityViewTest.php in Chaos Tool Suite (ctools) 8.3
File
tests/src/Kernel/Plugin/Block/EntityViewTest.php
View source
<?php
namespace Drupal\Tests\ctools\Kernel\Plugin\Block;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\ctools\Plugin\Block\EntityView;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
class EntityViewTest extends KernelTestBase {
use NodeCreationTrait;
use UserCreationTrait;
protected static $modules = [
'block',
'ctools',
'filter',
'node',
'system',
'user',
];
protected $pageVariant;
protected function setUp() {
parent::setUp();
$this
->installConfig([
'filter',
]);
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
}
public function testAccess() {
$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);
$account = $this
->createUser([], NULL, TRUE);
$access = $block
->access($account);
$this
->assertTrue($access);
}
}