diff --git a/core/lib/Drupal/Core/Routing/MimeTypeMatcher.php b/core/lib/Drupal/Core/Routing/MimeTypeMatcher.php index 36d313f..4624972 100644 --- a/core/lib/Drupal/Core/Routing/MimeTypeMatcher.php +++ b/core/lib/Drupal/Core/Routing/MimeTypeMatcher.php @@ -55,9 +55,13 @@ public function filter(RouteCollection $collection, Request $request) { // _format could be a |-delimited list of supported formats. $supported_formats = array_filter(explode('|', $route->getRequirement('_format'))); - // HTML is the default format if the route does not specify it. + // HTML is the default format if the route does not specify it. We also + // need to add those other weird Drupal AJAX formats here, otherwise we + // would exclude the AJAX routes. + // @todo Figure out why adding "_format: drupal_ajax" to AJAX routes does + // not work. if (empty($supported_formats)) { - $supported_formats = array('html'); + $supported_formats = array('html', 'drupal_ajax', 'drupal_modal', 'drupal_dialog'); } if (in_array($primary_format, $supported_formats)) { @@ -79,7 +83,7 @@ public function filter(RouteCollection $collection, Request $request) { return $somehow_matches; } - throw new NotAcceptableHttpException(); + throw new NotAcceptableHttpException(format_string('No route found for the specified formats @formats.', array('@formats' => implode(' ', $acceptable_mime_types)))); } } diff --git a/core/modules/rest/lib/Drupal/rest/Tests/AuthTest.php b/core/modules/rest/lib/Drupal/rest/Tests/AuthTest.php index 7c40096..7cb1b9a 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/AuthTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/AuthTest.php @@ -48,7 +48,7 @@ public function testRead() { // Try to read the resource as an anonymous user, which should not work. $response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'GET', NULL, $this->defaultMimeType); $this->assertResponse('401', 'HTTP response code is 401 when the request is not authenticated and the user is anonymous.'); - $this->assertText('A fatal error occurred: No authentication credentials provided.'); + $this->assertText('An error occurred: No authentication credentials provided.'); // Create a user account that has the required permissions to read // resources via the REST API, but the request is authenticated diff --git a/core/modules/rest/lib/Drupal/rest/Tests/NodeTest.php b/core/modules/rest/lib/Drupal/rest/Tests/NodeTest.php index 76773df..56b7188 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/NodeTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/NodeTest.php @@ -55,7 +55,7 @@ public function testNodes() { $node = $this->entityCreate('node'); $node->save(); - $this->httpRequest('entity/node/' . $node->id(), 'GET', NULL, $this->defaultMimeType); + $this->httpRequest('node/' . $node->id(), 'GET', NULL, $this->defaultMimeType); $this->assertResponse(200); // Check that a simple PATCH update to the node title works as expected. @@ -76,7 +76,7 @@ public function testNodes() { ), ); $serialized = $this->container->get('serializer')->serialize($data, $this->defaultFormat); - $this->httpRequest('entity/node/' . $node->id(), 'PATCH', $serialized, $this->defaultMimeType); + $this->httpRequest('node/' . $node->id(), 'PATCH', $serialized, $this->defaultMimeType); $this->assertResponse(204); // Reload the node from the DB and check if the title was correctly updated. diff --git a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php index 8d88ab1..25c1425 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php @@ -299,8 +299,11 @@ protected function entityPermissions($entity_type, $operation) { /** * Returns the base URI path of an entity type. * - * @param type $entity_type + * @param string $entity_type + * The entity type. + * * @return string + * The URI path. */ protected function entityBasePath($entity_type) { switch ($entity_type) { diff --git a/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php b/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php index 7eac42e..718f916 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php @@ -61,14 +61,28 @@ public function testRead() { // Try to read the entity with an unsupported mime format. $response = $this->httpRequest($this->entityBasePath($entity_type) . '/' . $entity->id(), 'GET', NULL, 'application/wrongformat'); - $this->assertResponse(200); - // @todo HTML is returned here for nodes. + if ($entity_type == 'entity_test') { + $this->assertResponse(406); + $this->assertEqual($response, 'An error occurred: No route found for the specified formats application/wrongformat.'); + } + if ($entity_type == 'node') { + // Nodes are different because there is always as HTML route which will + // fire if no other format could be found. + $this->assertResponse(200); + } // Try to read an entity that does not exist. $response = $this->httpRequest($this->entityBasePath($entity_type) . '/9999', 'GET', NULL, $this->defaultMimeType); $this->assertResponse(404); - $decoded = drupal_json_decode($response); - $this->assertEqual($decoded['error'], 'An error occurred: Item "node" with ID 9999 not found', 'Response message is correct.'); + if ($entity_type == 'entity_test') { + $decoded = drupal_json_decode($response); + $this->assertEqual($decoded['error'], 'Entity with ID 9999 not found'); + } + if ($entity_type == 'node') { + // Nodes are different because they get upcasted by a route enhancer, + // which throws an exception if the node does not exist. + $this->assertEqual($response, 'Item "node" with ID 9999 not found'); + } // Make sure that field level access works and that the according field is // not available in the response. Only applies to entity_test. @@ -115,7 +129,7 @@ public function testResourceStructure() { $entity->save(); // Read it over the REST API. - $response = $this->httpRequest('entity/node/' . $entity->id(), 'GET', NULL, 'application/json'); + $response = $this->httpRequest('node/' . $entity->id(), 'GET', NULL, 'application/json'); $this->assertResponse('200', 'HTTP response code is correct.'); }