function SelectionTest::testSelectionHandler
Same name in other branches
- 9 core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::testSelectionHandler()
- 10 core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::testSelectionHandler()
- 11.x core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\SelectionTest::testSelectionHandler()
Tests the selection handler.
File
-
core/
modules/ field/ tests/ src/ Kernel/ EntityReference/ Views/ SelectionTest.php, line 87
Class
- SelectionTest
- Tests entity reference selection handler.
Namespace
Drupal\Tests\field\Kernel\EntityReference\ViewsCode
public function testSelectionHandler() {
// Tests the selection handler.
$this->assertResults($this->selectionHandler
->getReferenceableEntities());
// Add a relationship to the view.
$view = Views::getView('test_entity_reference');
$view->setDisplay();
$view->displayHandlers
->get('default')
->setOption('relationships', [
'test_relationship' => [
'id' => 'uid',
'table' => 'node_field_data',
'field' => 'uid',
],
]);
// Add a filter depending on the relationship to the test view.
$view->displayHandlers
->get('default')
->setOption('filters', [
'uid' => [
'id' => 'uid',
'table' => 'users_field_data',
'field' => 'uid',
'relationship' => 'test_relationship',
],
]);
// Set view to distinct so only one row per node is returned.
$query_options = $view->display_handler
->getOption('query');
$query_options['options']['distinct'] = TRUE;
$view->display_handler
->setOption('query', $query_options);
$view->save();
// Tests the selection handler with a relationship.
$this->assertResults($this->selectionHandler
->getReferenceableEntities());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.