diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php index a0a8dadb06..cc21f2d370 100644 --- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php @@ -181,7 +181,7 @@ public function testSerializerResponses() { $this->assertIdentical($actual_json, $expected, 'The expected HAL output was found.'); $this->assertCacheTags($expected_cache_tags); - // Change the default format to xml. + // Change the format to xml. $view->setDisplay('rest_export_1'); $view->getDisplay()->setOption('style', array( 'type' => 'serializer', @@ -194,7 +194,7 @@ public function testSerializerResponses() { )); $view->save(); $expected = $serializer->serialize($entities, 'xml'); - $actual_xml = $this->drupalGet('test/serialize/entity'); + $actual_xml = $this->drupalGetWithFormat('test/serialize/entity', 'xml'); $this->assertIdentical($actual_xml, $expected, 'The expected XML output was found.'); $this->assertCacheContexts(['languages:language_interface', 'theme', 'entity_test_view_grants', 'request_format']); @@ -371,10 +371,15 @@ public function testResponseFormatConfiguration() { $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', array(), array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')); - $this->assertHeader('content-type', 'application/json'); - $this->assertResponse(406, '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'); @@ -388,12 +393,6 @@ public function testResponseFormatConfiguration() { $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.'); - // Should return a 406. - $this->drupalGetWithFormat('test/serialize/field', '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 no format, so all of them should be allowed. $this->drupalPostForm($style_options, array('style_options[formats][json]' => '0', 'style_options[formats][xml]' => '0'), t('Apply')); @@ -408,8 +407,8 @@ public function testResponseFormatConfiguration() { $this->assertResponse(200, 'A 200 response was returned when XML was requested'); // Should return a 200. $this->drupalGetWithFormat('test/serialize/field', 'html'); - // We want to show the first format by default, see - // \Drupal\rest\Plugin\views\style\Serializer::render. + // We default to JSON if no format or HTML is provided, see + // \Drupal\rest\Plugin\views\display/RESTExport. $this->assertHeader('content-type', 'application/json'); $this->assertResponse(200, 'A 200 response was returned when HTML was requested.'); } @@ -609,7 +608,7 @@ public function testSerializerViewsUI() { $this->assertResponse(200); // Check if we receive the expected result. $result = $this->xpath('//div[@id="views-live-preview"]/pre'); - $this->assertIdentical($this->drupalGetJSON('test/serialize/field'), (string) $result[0], 'The expected JSON preview output was found.'); + $this->assertIdentical($this->$this->drupalGetWithFormat('test/serialize/field', 'json'), (string) $result[0], 'The expected JSON preview output was found.'); } /** diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 6e81939591..ca8bd430ba 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -413,7 +413,18 @@ public function getDisplayDetails($view, $display) { // Add a link to view the page unless the view is disabled or has no // path. elseif ($view->status() && $view->getExecutable()->displayHandlers->get($display['id'])->hasPath()) { - $path = $view->getExecutable()->displayHandlers->get($display['id'])->getPath(); + // Wrap this in a try/catch as tryng to generate links to some + // routes may throw a NotAcceptableHttpException if they do not + // respond to HTML, such as RESTExports. + try { + // @todo Views should expect and store a leading /. See: + // https://www.drupal.org/node/2423913 + $path = \Drupal::l('/' . $path, Url::fromUserInput('/' . $path)); + } + catch (NotAcceptableHttpException $e) { + $path = '/' . $path; + } + if ($path && (strpos($path, '%') === FALSE)) { if (!parse_url($path, PHP_URL_SCHEME)) { // @todo Views should expect and store a leading /. See: