View source
<?php
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\User;
use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
class NodeViewsFieldAccessTest extends FieldFieldAccessTestBase {
protected static $modules = [
'node',
'entity_test',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('node');
}
public function testNodeFields() {
$user = User::create([
'name' => 'test user',
]);
$user
->save();
NodeType::create([
'type' => 'article',
'name' => 'Article',
])
->save();
$node = Node::create([
'type' => 'article',
'title' => 'Test title',
'uid' => $user
->id(),
'status' => 1,
'promote' => 1,
'sticky' => 0,
'created' => 123456,
]);
$node
->save();
$this
->assertFieldAccess('node', 'nid', $node
->id());
$this
->assertFieldAccess('node', 'uuid', $node
->uuid());
$this
->assertFieldAccess('node', 'vid', $node
->id());
$this
->assertFieldAccess('node', 'type', $node->type->entity
->label());
$this
->assertFieldAccess('node', 'langcode', $node
->language()
->getName());
$this
->assertFieldAccess('node', 'title', 'Test title');
$this
->assertFieldAccess('node', 'uid', $user
->getAccountName());
$this
->assertFieldAccess('node', 'status', 'On');
$this
->assertFieldAccess('node', 'promote', 'On');
$this
->assertFieldAccess('node', 'sticky', 'Off');
}
}