function BasicTest::testSimpleArgument

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/BasicTest.php \Drupal\Tests\views\Kernel\BasicTest::testSimpleArgument()
  2. 8.9.x core/modules/views/tests/src/Kernel/BasicTest.php \Drupal\Tests\views\Kernel\BasicTest::testSimpleArgument()
  3. 11.x 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 103

Class

BasicTest
A basic query test for Views.

Namespace

Drupal\Tests\views\Kernel

Code

public function testSimpleArgument() : void {
    // 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',
    ]);
}

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