3 namespace Drupal\rest\Tests\Views;
5 use Drupal\node\Entity\Node;
6 use Drupal\views\Tests\ViewTestBase;
7 use Drupal\views\Tests\ViewTestData;
8 use Drupal\views\Views;
11 * Tests the display of an excluded field that is used as a token.
14 * @see \Drupal\rest\Plugin\views\display\RestExport
15 * @see \Drupal\rest\Plugin\views\row\DataFieldRow
17 class ExcludedFieldTokenTest extends ViewTestBase {
20 * @var \Drupal\views\ViewExecutable
25 * The views that are used by this test.
29 public static $testViews = ['test_excluded_field_token_display'];
32 * The modules that need to be installed for this test.
36 public static $modules = [
46 protected function setUp() {
49 ViewTestData::createTestViews(get_class($this), ['rest_test_views']);
51 // Create some test content.
52 for ($i = 1; $i <= 10; $i++) {
55 'title' => 'Article test ' . $i,
59 $this->enableViewsTestModule();
61 $this->view = Views::getView('test_excluded_field_token_display');
62 $this->view->setDisplay('rest_export_1');
66 * Tests the display of an excluded title field when used as a token.
68 public function testExcludedTitleTokenDisplay() {
69 $actual_json = $this->drupalGetWithFormat($this->view->getPath(), 'json');
70 $this->assertResponse(200);
73 ['nothing' => 'Article test 10'],
74 ['nothing' => 'Article test 9'],
75 ['nothing' => 'Article test 8'],
76 ['nothing' => 'Article test 7'],
77 ['nothing' => 'Article test 6'],
78 ['nothing' => 'Article test 5'],
79 ['nothing' => 'Article test 4'],
80 ['nothing' => 'Article test 3'],
81 ['nothing' => 'Article test 2'],
82 ['nothing' => 'Article test 1'],
84 $this->assertIdentical($actual_json, json_encode($expected));