function DisplayTest::testMissingRelationship
Same name in other branches
- 9 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testMissingRelationship()
- 8.9.x core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testMissingRelationship()
- 11.x core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testMissingRelationship()
Tests display validation when a required relationship is missing.
File
-
core/
modules/ views/ tests/ src/ Functional/ Plugin/ DisplayTest.php, line 365
Class
- DisplayTest
- Tests the basic display plugin.
Namespace
Drupal\Tests\views\Functional\PluginCode
public function testMissingRelationship() : void {
$view = Views::getView('test_exposed_relationship_admin_ui');
// Remove the relationship that is not used by other handlers.
$view->removeHandler('default', 'relationship', 'uid_1');
$errors = $view->validate();
// Check that no error message is shown.
$this->assertArrayNotHasKey('default', $errors, 'No errors found when removing unused relationship.');
// Unset cached relationships (see DisplayPluginBase::getHandlers())
unset($view->display_handler->handlers['relationship']);
// Remove the relationship used by other handlers.
$view->removeHandler('default', 'relationship', 'uid');
// Validate display
$errors = $view->validate();
// Check that the error messages are shown.
$this->assertCount(2, $errors['default'], 'Error messages found for required relationship');
$this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', [
'%relationship_name' => 'uid',
'%handler_type' => 'field',
'%handler' => 'User: Last login',
'%display_name' => 'Default',
]), $errors['default'][0]);
$this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', [
'%relationship_name' => 'uid',
'%handler_type' => 'field',
'%handler' => 'User: Created',
'%display_name' => 'Default',
]), $errors['default'][1]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.