class NodeViewsFieldAccessTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php \Drupal\Tests\node\Kernel\Views\NodeViewsFieldAccessTest
Tests base field access in Views for the node entity.
@group Node
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase implements \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\node\Kernel\Views\NodeViewsFieldAccessTest implements \Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase
- class \Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase implements \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of NodeViewsFieldAccessTest
File
-
core/
modules/ node/ tests/ src/ Kernel/ Views/ NodeViewsFieldAccessTest.php, line 15
Namespace
Drupal\Tests\node\Kernel\ViewsView source
class NodeViewsFieldAccessTest extends FieldFieldAccessTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'entity_test',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this->installEntitySchema('node');
}
/**
* Check access for node fields.
*/
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();
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
$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());
// @todo Don't we want to display Published / Unpublished by default,
// see https://www.drupal.org/node/2465623
$this->assertFieldAccess('node', 'status', 'On');
$this->assertFieldAccess('node', 'promote', 'On');
$this->assertFieldAccess('node', 'sticky', 'Off');
// $this->assertFieldAccess('node', 'created', \Drupal::service('date.formatter')->format(123456));
// $this->assertFieldAccess('node', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.