function ArgumentDefaultTest::testArgumentDefaultFixed

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultFixed()
  2. 8.9.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultFixed()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php \Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultFixed()

Tests fixed default argument.

File

core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php, line 119

Class

ArgumentDefaultTest
Tests pluggable argument_default for views.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testArgumentDefaultFixed() : void {
    $random = $this->randomMachineName();
    $view = Views::getView('test_argument_default_fixed');
    $view->setDisplay();
    $options = $view->display_handler
        ->getOption('arguments');
    $options['null']['default_argument_options']['argument'] = $random;
    $view->display_handler
        ->overrideOption('arguments', $options);
    $view->initHandlers();
    $this->assertEquals($random, $view->argument['null']
        ->getDefaultArgument(), 'Fixed argument should be used by default.');
    // Make sure that a normal argument provided is used
    $random_string = $this->randomMachineName();
    $view->executeDisplay('default', [
        $random_string,
    ]);
    $this->assertEquals($random_string, $view->args[0], 'Provided argument should be used.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.