function ModuleTest::testViewsPreview

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ModuleTest.php \Drupal\Tests\views\Kernel\ModuleTest::testViewsPreview()
  2. 10 core/modules/views/tests/src/Kernel/ModuleTest.php \Drupal\Tests\views\Kernel\ModuleTest::testViewsPreview()
  3. 11.x core/modules/views/tests/src/Kernel/ModuleTest.php \Drupal\Tests\views\Kernel\ModuleTest::testViewsPreview()

Tests the \Drupal\views\ViewsExecutable::preview() method.

File

core/modules/views/tests/src/Kernel/ModuleTest.php, line 276

Class

ModuleTest
Tests basic functions from the Views module.

Namespace

Drupal\Tests\views\Kernel

Code

public function testViewsPreview() {
    $view = Views::getView('test_argument');
    $result = $view->preview('default');
    $this->assertCount(5, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '0' => 1,
    ]);
    $this->assertCount(1, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '3' => 1,
    ]);
    $this->assertCount(1, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '0' => '1,2',
    ]);
    $this->assertCount(2, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '3' => '1,2',
    ]);
    $this->assertCount(2, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '0' => '1,2',
        '1' => 'John',
    ]);
    $this->assertCount(1, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '3' => '1,2',
        '4' => 'John',
    ]);
    $this->assertCount(1, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '0' => '1,2',
        '1' => 'John,George',
    ]);
    $this->assertCount(2, $result['#view']->result);
    $view = Views::getView('test_argument');
    $result = $view->preview('default', [
        '3' => '1,2',
        '4' => 'John,George',
    ]);
    $this->assertCount(2, $result['#view']->result);
}

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