Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / rest / tests / src / Functional / Views / ExcludedFieldTokenTest.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\Views;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\Tests\views\Functional\ViewTestBase;
7 use Drupal\views\Tests\ViewTestData;
8 use Drupal\views\Views;
9
10 /**
11  * Tests the display of an excluded field that is used as a token.
12  *
13  * @group rest
14  * @see \Drupal\rest\Plugin\views\display\RestExport
15  * @see \Drupal\rest\Plugin\views\row\DataFieldRow
16  */
17 class ExcludedFieldTokenTest extends ViewTestBase {
18
19   /**
20    * @var \Drupal\views\ViewExecutable
21    */
22   protected $view;
23
24   /**
25    * The views that are used by this test.
26    *
27    * @var array
28    */
29   public static $testViews = ['test_excluded_field_token_display'];
30
31   /**
32    * The modules that need to be installed for this test.
33    *
34    * @var array
35    */
36   public static $modules = [
37     'entity_test',
38     'rest_test_views',
39     'node',
40     'field',
41   ];
42
43   /**
44    * {@inheritdoc}
45    */
46   protected function setUp($import_test_views = TRUE) {
47     parent::setUp($import_test_views);
48
49     ViewTestData::createTestViews(get_class($this), ['rest_test_views']);
50
51     // Create some test content.
52     for ($i = 1; $i <= 10; $i++) {
53       Node::create([
54         'type' => 'article',
55         'title' => 'Article test ' . $i,
56       ])->save();
57     }
58
59     $this->enableViewsTestModule();
60
61     $this->view = Views::getView('test_excluded_field_token_display');
62     $this->view->setDisplay('rest_export_1');
63   }
64
65   /**
66    * Tests the display of an excluded title field when used as a token.
67    */
68   public function testExcludedTitleTokenDisplay() {
69     $actual_json = $this->drupalGet($this->view->getPath(), ['query' => ['_format' => 'json']]);
70     $this->assertResponse(200);
71
72     $expected = [
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'],
83     ];
84     $this->assertIdentical($actual_json, json_encode($expected));
85   }
86
87 }