function ArgumentDefaultTest::testArgumentDefaultPlugin
Same name in other branches
- 8.9.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultPlugin()
- 10 core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultPlugin()
- 11.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultPlugin()
Tests the argument default test plugin.
See also
\Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest
File
-
core/
modules/ views/ tests/ src/ Functional/ Plugin/ ArgumentDefaultTest.php, line 59
Class
- ArgumentDefaultTest
- Tests pluggable argument_default for views.
Namespace
Drupal\Tests\views\Functional\PluginCode
public function testArgumentDefaultPlugin() {
$view = Views::getView('test_view');
// Add a new argument and set the test plugin for the argument_default.
$options = [
'default_argument_type' => 'argument_default_test',
'default_argument_options' => [
'value' => 'John',
],
'default_action' => 'default',
];
$id = $view->addHandler('default', 'argument', 'views_test_data', 'name', $options);
$view->initHandlers();
$plugin = $view->argument[$id]
->getPlugin('argument_default');
$this->assertInstanceOf(ArgumentDefaultTestPlugin::class, $plugin);
// Check that the value of the default argument is as expected.
$this->assertEquals('John', $view->argument[$id]
->getDefaultArgument(), 'The correct argument default value is returned.');
// Don't pass in a value for the default argument and make sure the query
// just returns John.
$this->executeView($view);
$this->assertEquals('John', $view->argument[$id]
->getValue(), 'The correct argument value is used.');
$expected_result = [
[
'name' => 'John',
],
];
$this->assertIdenticalResultset($view, $expected_result, [
'views_test_data_name' => 'name',
]);
// Pass in value as argument to be sure that not the default value is used.
$view->destroy();
$this->executeView($view, [
'George',
]);
$this->assertEquals('George', $view->argument[$id]
->getValue(), 'The correct argument value is used.');
$expected_result = [
[
'name' => 'George',
],
];
$this->assertIdenticalResultset($view, $expected_result, [
'views_test_data_name' => 'name',
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.