diff --cc core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php index cb9fee24a2,8078eecb02..0000000000 --- a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php +++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php @@@ -200,13 -213,35 +203,35 @@@ class StyleSerializerTest extends ViewT ]); $view->save(); $expected = $serializer->serialize($entities, 'json'); - $actual_json = $this->drupalGetWithFormat('test/serialize/entity', 'json'); + $actual_json = $this->drupalGet('test/serialize/entity', ['query' => ['_format' => 'json']]); $this->assertIdentical($actual_json, $expected, 'The expected JSON output was found.'); $expected = $serializer->serialize($entities, 'xml'); - $actual_xml = $this->drupalGetWithFormat('test/serialize/entity', 'xml'); - $this->assertIdentical($actual_xml, $expected, 'The expected XML output was found.'); + $actual_xml = $this->drupalGet('test/serialize/entity', ['query' => ['_format' => 'xml']]); + $this->assertSame(trim($expected), $actual_xml); } + /** + * Verifies REST export views work on the same path as a page display. + */ + public function testSharedPagePath() { + // Test with no format as well as html explicitly. + $this->drupalGet('test/serialize/shared'); + $this->assertResponse(200); + $this->assertHeader('content-type', 'text/html; charset=UTF-8'); + - $this->drupalGetWithFormat('test/serialize/shared', 'html'); ++ $this->drupalGet('test/serialize/shared', ['query' => ['_format' => 'html']]); + $this->assertResponse(200); + $this->assertHeader('content-type', 'text/html; charset=UTF-8'); + - $this->drupalGetWithFormat('test/serialize/shared', 'json'); ++ $this->drupalGet('test/serialize/shared', ['query' => ['_format' => 'json']]); + $this->assertResponse(200); + $this->assertHeader('content-type', 'application/json'); + - $this->drupalGetWithFormat('test/serialize/shared', 'xml'); ++ $this->drupalGet('test/serialize/shared', ['query' => ['_format' => 'xml']]); + $this->assertResponse(200); + $this->assertHeader('content-type', 'text/xml; charset=UTF-8'); + } + /** * Verifies site maintenance mode functionality. */ @@@ -353,19 -393,18 +383,18 @@@ $this->drupalPostForm($style_options, ['style_options[formats][json]' => 'json'], t('Apply')); $this->drupalPostForm(NULL, [], t('Save')); - // Should return a 200. - // @todo This should be fixed when we have better content negotiation. - $this->drupalGet('test/serialize/field'); - $this->assertHeader('content-type', 'application/json'); - $this->assertResponse(200, 'A 200 response was returned when any format was requested.'); - - // Should return a 200. Emulates a sample Firefox header. + // Should return a 406. Emulates a sample Firefox header. $this->drupalGet('test/serialize/field', [], ['Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8']); - $this->assertHeader('content-type', 'application/json'); - $this->assertResponse(200, 'A 200 response was returned when a browser accept header was requested.'); + $this->assertHeader('content-type', 'text/html; charset=UTF-8'); + $this->assertResponse(406, 'A 406 response was returned when a browser accept header was requested.'); + + // Should return a 406. + $this->drupalGetWithFormat('test/serialize/field', 'html'); + $this->assertHeader('content-type', 'text/html; charset=UTF-8'); + $this->assertResponse(406, 'A 406 response was returned when HTML was requested.'); // Should return a 200. - $this->drupalGetWithFormat('test/serialize/field', 'json'); + $this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']]); $this->assertHeader('content-type', 'application/json'); $this->assertResponse(200, 'A 200 response was returned when JSON was requested.'); $headers = $this->drupalGetHeaders(); @@@ -375,15 -414,9 +404,15 @@@ $this->assertHeader('content-type', 'text/xml; charset=UTF-8'); $this->assertResponse(200, 'A 200 response was returned when XML was requested'); $headers = $this->drupalGetHeaders(); - $this->assertTrue(strpos($headers['content-type'], 'text/xml') !== FALSE, 'The header Content-type is correct.'); + $this->assertSame(['text/xml; charset=UTF-8'], $headers['Content-Type']); + // Should return a 406. + $this->drupalGet('test/serialize/field', ['query' => ['_format' => 'html']]); + // We want to show the first format by default, see + // \Drupal\rest\Plugin\views\style\Serializer::render. + $this->assertHeader('content-type', 'application/json'); + $this->assertResponse(200, 'A 200 response was returned when HTML was requested.'); - // Now configure now format, so all of them should be allowed. + // Now configure no format, so all of them should be allowed. $this->drupalPostForm($style_options, ['style_options[formats][json]' => '0', 'style_options[formats][xml]' => '0'], t('Apply')); // Should return a 200. @@@ -391,15 -424,13 +420,13 @@@ $this->assertHeader('content-type', 'application/json'); $this->assertResponse(200, 'A 200 response was returned when JSON was requested.'); // Should return a 200. - $this->drupalGetWithFormat('test/serialize/field', 'xml'); + $this->drupalGet('test/serialize/field', ['query' => ['_format' => 'xml']]); $this->assertHeader('content-type', 'text/xml; charset=UTF-8'); $this->assertResponse(200, 'A 200 response was returned when XML was requested'); - // Should return a 200. + // Should return a 406 for HTML. - $this->drupalGetWithFormat('test/serialize/field', 'html'); + $this->drupalGet('test/serialize/field', ['query' => ['_format' => 'html']]); - // We want to show the first format by default, see - // \Drupal\rest\Plugin\views\style\Serializer::render. - $this->assertHeader('content-type', 'application/json'); - $this->assertResponse(200, 'A 200 response was returned when HTML was requested.'); + $this->assertHeader('content-type', 'text/html; charset=UTF-8'); + $this->assertResponse(406, 'A 406 response was returned when HTML was requested.'); } /** @@@ -597,8 -628,7 +624,8 @@@ $this->assertResponse(200); // Check if we receive the expected result. $result = $this->xpath('//div[@id="views-live-preview"]/pre'); - $this->assertIdentical($this->drupalGetWithFormat('test/serialize/field', 'json'), (string) $result[0], 'The expected JSON preview output was found.'); + $json_preview = $result[0]->getText(); - $this->assertSame($json_preview, $this->drupalGet('test/serialize/field'), 'The expected JSON preview output was found.'); ++ $this->assertSame($json_preview, $this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']]), 'The expected JSON preview output was found.'); } /**