diff --git a/core/modules/rest/src/Tests/Views/ExcludedFieldTokenTest.php b/core/modules/rest/src/Tests/Views/ExcludedFieldTokenTest.php index ae997ab..2a910fe 100644 --- a/core/modules/rest/src/Tests/Views/ExcludedFieldTokenTest.php +++ b/core/modules/rest/src/Tests/Views/ExcludedFieldTokenTest.php @@ -17,11 +17,6 @@ class ExcludedFieldTokenTest extends ViewTestBase { /** - * @var \Drupal\user\Entity\User|false - */ - protected $adminUser; - - /** * @var \Drupal\views\ViewExecutable */ protected $view; @@ -53,8 +48,14 @@ protected function setUp() { ViewTestData::createTestViews(get_class($this), ['rest_test_views']); - $this->setAdminUser(); - $this->createTestNodes(); + // Create some test content. + for ($i = 1; $i <= 10; $i++) { + Node::create([ + 'type' => 'article', + 'title' => 'Article test ' . $i, + ])->save(); + } + $this->enableViewsTestModule(); $this->view = Views::getView('test_excluded_field_token_display'); @@ -68,48 +69,20 @@ public function testExcludedTitleTokenDisplay() { $actual_json = $this->drupalGetWithFormat($this->view->getPath(), 'json'); $this->assertResponse(200); - $expected = $this->getExpectedOutput(); - $this->assertIdentical($actual_json, $expected); - } - - /** - * Creates test nodes for the exported view. - */ - protected function createTestNodes() { - for ($i = 1; $i <= 10; $i++) { - Node::create([ - 'type' => 'article', - 'title' => 'Article test ' . $i, - ])->save(); - } - } - - /** - * Creates an admin user. - */ - protected function setAdminUser() { - $this->adminUser = $this->drupalCreateUser(array(), NULL, TRUE); + $expected = [ + ['nothing' => 'Article test 10'], + ['nothing' => 'Article test 9'], + ['nothing' => 'Article test 8'], + ['nothing' => 'Article test 7'], + ['nothing' => 'Article test 6'], + ['nothing' => 'Article test 5'], + ['nothing' => 'Article test 4'], + ['nothing' => 'Article test 3'], + ['nothing' => 'Article test 2'], + ['nothing' => 'Article test 1'], + ]; + $this->assertIdentical($actual_json, json_encode($expected)); } - /** - * Generates a JSON with the results of the executed view. - * - * @return string - */ - private function getExpectedOutput() { - $this->executeView($this->view); - $expected = []; - foreach ($this->view->result as $rowIndex => $row) { - $expected_row = []; - foreach ($this->view->field as $id => $field) { - if (empty($field->options['exclude'])) { - $expected_row[$id] = $this->view->getStyle()->getField($rowIndex, $id)->__toString(); - } - } - $expected[] = $expected_row; - } - - return json_encode($expected); - } }