View source
<?php
namespace Drupal\Tests\rest\Functional\Views;
use Drupal\node\Entity\Node;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
class FieldCounterTest extends ViewTestBase {
protected $view;
public static $testViews = [
'test_field_counter_display',
];
protected $defaultTheme = 'stark';
public static $modules = [
'entity_test',
'rest_test_views',
'node',
'field',
];
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), [
'rest_test_views',
]);
for ($i = 1; $i <= 10; $i++) {
Node::create([
'type' => 'article',
'title' => 'Article test ' . $i,
])
->save();
}
$this
->enableViewsTestModule();
$this->view = Views::getView('test_field_counter_display');
$this->view
->setDisplay('rest_export_1');
}
public function testExcludedTitleTokenDisplay() {
$actual_json = $this
->drupalGet($this->view
->getPath(), [
'query' => [
'_format' => 'json',
],
]);
$this
->assertSession()
->statusCodeEquals(200);
$expected = [
[
'counter' => '1',
],
[
'counter' => '2',
],
[
'counter' => '3',
],
[
'counter' => '4',
],
[
'counter' => '5',
],
[
'counter' => '6',
],
[
'counter' => '7',
],
[
'counter' => '8',
],
[
'counter' => '9',
],
[
'counter' => '10',
],
];
$this
->assertIdentical($actual_json, json_encode($expected));
}
}