function FieldOrLanguageJoinTest::testLanguageBundleConditions
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/Plugin/FieldOrLanguageJoinTest.php \Drupal\Tests\views\Kernel\Plugin\FieldOrLanguageJoinTest::testLanguageBundleConditions()
- 8.9.x core/modules/views/tests/src/Kernel/Plugin/FieldOrLanguageJoinTest.php \Drupal\Tests\views\Kernel\Plugin\FieldOrLanguageJoinTest::testLanguageBundleConditions()
- 10 core/modules/views/tests/src/Kernel/Plugin/FieldOrLanguageJoinTest.php \Drupal\Tests\views\Kernel\Plugin\FieldOrLanguageJoinTest::testLanguageBundleConditions()
Tests the adding of conditions by the join plugin.
File
-
core/
modules/ views/ tests/ src/ Kernel/ Plugin/ FieldOrLanguageJoinTest.php, line 133
Class
- FieldOrLanguageJoinTest
- Tests the "field OR language" join plugin.
Namespace
Drupal\Tests\views\Kernel\PluginCode
public function testLanguageBundleConditions() : void {
// Setup a simple join and test the result sql.
$view = Views::getView('test_view');
$view->initDisplay();
$view->initQuery();
// Set the various options on the join object with only a langcode
// condition.
$configuration = [
'table' => 'node__field_tags',
'left_table' => 'views_test_data',
'left_field' => 'nid',
'field' => 'entity_id',
'extra' => [
[
'left_field' => 'langcode',
'field' => 'langcode',
],
],
];
$join_info = $this->buildJoin($view, $configuration, 'node__field_tags');
$this->assertStringContainsString('AND (node__field_tags.langcode = views_test_data.langcode)', $join_info['condition']);
array_unshift($configuration['extra'], [
'field' => 'deleted',
'value' => 0,
'numeric' => TRUE,
]);
$join_info = $this->buildJoin($view, $configuration, 'node__field_tags');
$this->assertStringContainsString('AND (node__field_tags.langcode = views_test_data.langcode)', $join_info['condition']);
// Replace the language condition with a bundle condition.
$configuration['extra'][1] = [
'field' => 'bundle',
'value' => [
'page',
],
];
$join_info = $this->buildJoin($view, $configuration, 'node__field_tags');
$this->assertStringContainsString('AND (node__field_tags.bundle = :views_join_condition_1)', $join_info['condition']);
// Now re-add a language condition to make sure the bundle and language
// conditions are combined with an OR.
$configuration['extra'][] = [
'left_field' => 'langcode',
'field' => 'langcode',
];
$join_info = $this->buildJoin($view, $configuration, 'node__field_tags');
$this->assertStringContainsString('AND (node__field_tags.bundle = :views_join_condition_1 OR node__field_tags.langcode = views_test_data.langcode)', $join_info['condition']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.