View source
<?php
namespace Drupal\Tests\views\Kernel;
use Drupal\views\Views;
class BasicTest extends ViewsKernelTestBase {
public static $testViews = [
'test_view',
'test_simple_argument',
];
public function testSimpleResultSet() {
$view = Views::getView('test_view');
$view
->setDisplay();
$this
->executeView($view);
$this
->assertCount(5, $view->result, 'The number of returned rows match.');
$this
->assertIdenticalResultset($view, $this
->dataSet(), [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
}
public function testSimpleFiltering() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('filters', [
'age' => [
'operator' => '<',
'value' => [
'value' => '28',
'min' => '',
'max' => '',
],
'group' => '0',
'exposed' => FALSE,
'expose' => [
'operator' => FALSE,
'label' => '',
],
'id' => 'age',
'table' => 'views_test_data',
'field' => 'age',
'relationship' => 'none',
],
]);
$this
->executeView($view);
$dataset = [
[
'id' => 1,
'name' => 'John',
'age' => 25,
],
[
'id' => 2,
'name' => 'George',
'age' => 27,
],
[
'id' => 4,
'name' => 'Paul',
'age' => 26,
],
];
$this
->assertCount(3, $view->result, 'The number of returned rows match.');
$this
->assertIdenticalResultSet($view, $dataset, [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
}
public function testSimpleArgument() {
$view = Views::getView('test_simple_argument');
$view
->setArguments([
27,
]);
$this
->executeView($view);
$dataset = [
[
'id' => 2,
'name' => 'George',
'age' => 27,
],
];
$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',
]);
$view = Views::getView('test_simple_argument');
$this
->executeView($view);
$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',
]);
}
}