function ArgumentDefaultTest::testArgumentDefaultQueryParameter

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

Tests the query parameter default argument.

File

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

Class

ArgumentDefaultTest
Tests pluggable argument_default for views.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testArgumentDefaultQueryParameter() : void {
    $view = Views::getView('test_argument_default_query_param');
    $request = Request::create(Url::fromUri('internal:/whatever', [
        'absolute' => TRUE,
    ])->toString());
    // Check the query parameter default argument fallback value.
    $view->setRequest($request);
    $view->initHandlers();
    $this->assertEquals('all', $view->argument['type']
        ->getDefaultArgument());
    // Check the query parameter default argument with a value.
    $request->query
        ->add([
        'the_node_type' => 'page',
    ]);
    $view->setRequest($request);
    $view->initHandlers();
    $this->assertEquals('page', $view->argument['type']
        ->getDefaultArgument());
}

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