public function FieldTest::testAccess in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testAccess()
- 9 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testAccess()
@covers ::access
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ field/ FieldTest.php, line 267 - Contains \Drupal\Tests\views\Unit\Plugin\field\FieldTest.
Class
- FieldTest
- @coversDefaultClass \Drupal\views\Plugin\views\field\EntityField @group views
Namespace
Drupal\Tests\views\Unit\Plugin\fieldCode
public function testAccess() {
$definition = [
'entity_type' => 'test_entity',
'field_name' => 'title',
];
$handler = new EntityField([], 'field', $definition, $this->entityTypeManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer, $this->entityRepository, $this->entityFieldManager);
$handler->view = $this->executable;
$handler
->setViewsData($this->viewsData);
$this->view
->expects($this
->atLeastOnce())
->method('get')
->with('base_table')
->willReturn('test_entity_table');
$this->viewsData
->expects($this
->atLeastOnce())
->method('get')
->with('test_entity_table')
->willReturn([
'table' => [
'entity type' => 'test_entity',
],
]);
$access_control_handler = $this
->createMock('Drupal\\Core\\Entity\\EntityAccessControlHandlerInterface');
$this->entityTypeManager
->expects($this
->atLeastOnce())
->method('getAccessControlHandler')
->with('test_entity')
->willReturn($access_control_handler);
$title_storage = $this
->getBaseFieldStorage();
$this->entityFieldManager
->expects($this
->atLeastOnce())
->method('getFieldStorageDefinitions')
->with('test_entity')
->willReturn([
'title' => $title_storage,
]);
$account = $this
->createMock('Drupal\\Core\\Session\\AccountInterface');
$access_control_handler
->expects($this
->atLeastOnce())
->method('fieldAccess')
->with('view', $this
->anything(), $account, NULL, $this
->anything())
->willReturn(TRUE);
$this
->assertTrue($handler
->access($account));
}