diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php index 787d1c9..ac7af96 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleSerializeTest.php @@ -7,8 +7,6 @@ namespace Drupal\views\Tests\Plugin; -use Drupal\views\Tests\Plugin\PluginTestBase; - /** * Tests the serialize style plugin. * @@ -22,7 +20,14 @@ class StyleSerializeTest extends PluginTestBase { * * @var array */ - public static $modules = array('views_ui', 'node'); + public static $modules = array('views_ui', 'entity_test'); + + /** + * Views used by this test. + * + * @var array + */ + public static $testViews = array('test_serialize_display_field', 'test_serialize_display_entity'); public static function getInfo() { return array( @@ -35,13 +40,14 @@ public static function getInfo() { protected function setUp() { parent::setUp(); + $this->adminUser = $this->drupalCreateUser(array('administer views', 'administer entity_test content', 'access user profiles', 'view test entity')); + + // Save some entity_test entities. for ($i = 1; $i <= 10; $i++) { - $this->drupalCreateNode(); + entity_create('entity_test', array('name' => 'test_' . $i, 'user_id' => $this->adminUser->id()))->save(); } $this->enableViewsTestModule(); - - $this->adminUser = $this->drupalCreateUser(array('administer views', 'bypass node access', 'access user profiles', 'view revisions')); } /** @@ -53,7 +59,7 @@ public function testSerializeResponses() { $view->initDisplay(); $this->executeView($view); - $actual_json = $this->drupalGet('test/serialize/field', array(), array('Content-type: application/json')); + $actual_json = $this->drupalGet('test/serialize/field', array(), array('Accept: application/json')); $this->assertResponse(200); // Test the http Content-type. @@ -81,15 +87,20 @@ public function testSerializeResponses() { $view->initDisplay(); $this->executeView($view); + // Get the serializer service. + $serializer = drupal_container()->get('serializer'); + $expected = array(); foreach ($view->result as $row) { $expected[] = $row->_entity; } - $actual_json = $this->drupalGet('test/serialize/entity', array(), array('Content-type: application/json')); + $expected = $serializer->serialize($expected, 'json'); + + $actual_json = $this->drupalGet('test/serialize/entity', array(), array('Accept: application/json')); $this->assertResponse(200); - $this->assertIdentical($actual_json, json_encode($expected), 'The expected JSON output was found.'); + $this->assertIdentical($actual_json, $expected, 'The expected JSON output was found.'); } /** diff --git a/core/modules/views/tests/views_test_config/config/views.view.test_serialize_display_entity.yml b/core/modules/views/tests/views_test_config/config/views.view.test_serialize_display_entity.yml index f9a3836..7f08074 100644 --- a/core/modules/views/tests/views_test_config/config/views.view.test_serialize_display_entity.yml +++ b/core/modules/views/tests/views_test_config/config/views.view.test_serialize_display_entity.yml @@ -1,4 +1,4 @@ -base_table: node +base_table: entity_test name: test_serialize_display_entity description: '' tag: '' @@ -27,10 +27,10 @@ display: row: type: data_entity sorts: - created: - id: created - table: node - field: created + id: + id: standard + table: entity_test + field: id order: DESC title: 'Test serialize' arguments: { }