You are here

public function BasicTest::testSimpleArgument in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/BasicTest.php \Drupal\Tests\views\Kernel\BasicTest::testSimpleArgument()

Tests simple argument.

File

core/modules/views/tests/src/Kernel/BasicTest.php, line 101

Class

BasicTest
A basic query test for Views.

Namespace

Drupal\Tests\views\Kernel

Code

public function testSimpleArgument() {

  // Execute with a view
  $view = Views::getView('test_simple_argument');
  $view
    ->setArguments([
    27,
  ]);
  $this
    ->executeView($view);

  // Build the expected result.
  $dataset = [
    [
      'id' => 2,
      'name' => 'George',
      'age' => 27,
    ],
  ];

  // Verify the result.
  $this
    ->assertCount(1, $view->result, 'The number of returned rows match.');
  $this
    ->assertIdenticalResultSet($view, $dataset, [
    'views_test_data_name' => 'name',
    'views_test_data_age' => 'age',
  ]);

  // Test "show all" if no argument is present.
  $view = Views::getView('test_simple_argument');
  $this
    ->executeView($view);

  // Build the expected result.
  $dataset = $this
    ->dataSet();
  $this
    ->assertCount(5, $view->result, 'The number of returned rows match.');
  $this
    ->assertIdenticalResultSet($view, $dataset, [
    'views_test_data_name' => 'name',
    'views_test_data_age' => 'age',
  ]);
}