function DisplayKernelTest::testisIdentifierUnique
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayKernelTest::testisIdentifierUnique()
- 8.9.x core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayKernelTest::testisIdentifierUnique()
- 10 core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayKernelTest::testisIdentifierUnique()
Tests the ::isIdentifierUnique method.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Plugin/ DisplayKernelTest.php, line 121
Class
- DisplayKernelTest
- Drupal unit tests for the DisplayPluginBase class.
Namespace
Drupal\Tests\views\Kernel\PluginCode
public function testisIdentifierUnique() : void {
$view = Views::getView('test_view');
$view->initDisplay();
// Add a handler that doesn't have an Identifier when exposed.
$sorts = [
'name' => [
'id' => 'name',
'field' => 'name',
'table' => 'views_test_data',
'plugin_id' => 'standard',
'order' => 'asc',
'expose' => [
'label' => 'Id',
'field_identifier' => 'name',
],
'exposed' => TRUE,
],
];
// Add a handler that does have an Identifier when exposed.
$filters = [
'id' => [
'field' => 'id',
'id' => 'id',
'table' => 'views_test_data',
'value' => [],
'plugin_id' => 'numeric',
'exposed' => TRUE,
'expose' => [
'operator_id' => '',
'label' => 'Id',
'description' => '',
'identifier' => 'id',
'required' => FALSE,
'remember' => FALSE,
'multiple' => FALSE,
],
],
];
$view->display_handler
->setOption('sorts', $sorts);
$view->display_handler
->setOption('filters', $filters);
$this->assertTrue($view->display_handler
->isIdentifierUnique('some_id', 'some_id'));
$this->assertFalse($view->display_handler
->isIdentifierUnique('some_id', 'id'));
// Check that an exposed filter is able to use the same identifier as an
// exposed sort.
$sorts['name']['expose']['field_identifier'] = 'id';
$view->display_handler->handlers = [];
$view->display_handler
->setOption('sorts', $sorts);
$this->assertTrue($view->display_handler
->isIdentifierUnique('id', 'id'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.