You are here

public function ArgumentDefaultTest::testArgumentDefaultQueryParameter in Drupal 9

Same name and namespace in other branches
  1. 8 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 174

Class

ArgumentDefaultTest
Tests pluggable argument_default for views.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testArgumentDefaultQueryParameter() {
  $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());
}