diff --git a/core/modules/rest/src/Plugin/Derivative/EntityDerivative.php b/core/modules/rest/src/Plugin/Derivative/EntityDerivative.php index 888a724..4655077 100644 --- a/core/modules/rest/src/Plugin/Derivative/EntityDerivative.php +++ b/core/modules/rest/src/Plugin/Derivative/EntityDerivative.php @@ -114,12 +114,16 @@ public function getDerivativeDefinitions($base_plugin_definition) { // @todo remove the try/catch as part of // http://drupal.org/node/2281645 try { - if (($collection = $this->routeBuilder->getCollectionDuringRebuild()) && $route = $collection->get($route_name)) { + if ($collection = $this->routeBuilder->getCollectionDuringRebuild()) { + $route = $collection->get($route_name); } else { $route = $this->routeProvider->getRouteByName($route_name); } - $this->derivatives[$entity_type_id]['uri_paths'][$link_relation] = $route->getPath(); + + if ($route) { + $this->derivatives[$entity_type_id]['uri_paths'][$link_relation] = $route->getPath(); + } } catch (RouteNotFoundException $e) { // If the route does not exist it means we are in a brittle state diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php index 146b056..105df19 100644 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ b/core/modules/rest/src/Tests/RESTTestBase.php @@ -8,7 +8,6 @@ namespace Drupal\rest\Tests; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Url; use Drupal\simpletest\WebTestBase; /** @@ -63,7 +62,7 @@ protected function setUp() { /** * Helper function to issue a HTTP request with simpletest's cURL. * - * @param string $path + * @param string $url * The relative URL, e.g. "entity/node/1" * @param string $method * HTTP method, one of GET, POST, PUT or DELETE. @@ -72,7 +71,7 @@ protected function setUp() { * @param string $mime_type * The MIME type of the transmitted content. */ - protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) { + protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) { if (!isset($mime_type)) { $mime_type = $this->defaultMimeType; } @@ -80,19 +79,14 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) // GET the CSRF token first for writing requests. $token = $this->drupalGet('rest/session/token'); } - - $options = array('absolute' =>TRUE); - switch ($method) { case 'GET': // Set query if there are additional GET parameters. - if (isset($body)) { - $options['query'] = $body; - } + $options = isset($body) ? array('absolute' => TRUE, 'query' => $body) : array('absolute' => TRUE); $curl_options = array( CURLOPT_HTTPGET => TRUE, CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), + CURLOPT_URL => _url($url, $options), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type), ); @@ -103,7 +97,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) CURLOPT_HTTPGET => FALSE, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $body, - CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), + CURLOPT_URL => _url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: ' . $mime_type, @@ -117,7 +111,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $body, - CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), + CURLOPT_URL => _url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: ' . $mime_type, @@ -131,7 +125,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_POSTFIELDS => $body, - CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), + CURLOPT_URL => _url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: ' . $mime_type, @@ -144,7 +138,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) $curl_options = array( CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'DELETE', - CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), + CURLOPT_URL => _url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array('X-CSRF-Token: ' . $token), ); @@ -155,7 +149,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) $headers = $this->drupalGetHeaders(); $headers = implode("\n", $headers); - $this->verbose($method . ' request to: ' . $path . + $this->verbose($method . ' request to: ' . $url . '
Code: ' . curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE) . '
Response headers: ' . $headers . '
Response body: ' . $response); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index f3e9d86..ec190a0 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -26,7 +26,6 @@ use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\Core\Url; use Drupal\block\Entity\Block; use Symfony\Component\HttpFoundation\Request; use Drupal\user\Entity\Role; @@ -1473,22 +1472,13 @@ protected function isInChildSite() { protected function drupalGet($path, array $options = array(), array $headers = array()) { $options['absolute'] = TRUE; - $url = $path; - - // Assume that paths that start with a / are already fully generated - // URL's that are just missing $base_root. - if (isset($path[0]) && $path[0] == '/') { - $url = $GLOBALS['base_root'] . $path; - } // The URL generator service is not necessarily available yet; e.g., in // interactive installer tests. - elseif ($this->container->has('url_generator')) { - if ($this->container->has('url_generator')) { - $url = $this->container->get('url_generator')->generateFromPath($path, $options); - } - else { - $url = $this->getAbsoluteUrl($path); - } + if ($this->container->has('url_generator')) { + $url = $this->container->get('url_generator')->generateFromPath($path, $options); + } + else { + $url = $this->getAbsoluteUrl($path); } // We re-using a CURL connection here. If that connection still has certain @@ -1975,22 +1965,11 @@ protected function drupalProcessAjaxResponse($content, array $ajax_response, arr * * @see WebTestBase::getAjaxPageStatePostData() * @see WebTestBase::curlExec() - * @see \Drupal\Core\Url::fromUri() + * @see _url() */ protected function drupalPost($path, $accept, array $post, $options = array()) { - $options['absolute'] = TRUE; - - // The URL generator service is not necessarily available yet; e.g., in - // interactive installer tests. - if ($this->container->has('url_generator')) { - $url = $this->container->get('url_generator')->generateFromPath($path, $options); - } - else { - $url = $this->getAbsoluteUrl($path); - } - return $this->curlExec(array( - CURLOPT_URL => $url, + CURLOPT_URL => _url($path, $options + array('absolute' => TRUE)), CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $this->serializePostValues($post), CURLOPT_HTTPHEADER => array( diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php index 93a5ded..ab0950c 100644 --- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php @@ -58,8 +58,8 @@ function testBreadCrumbs() { // Verify Taxonomy administration breadcrumbs. $trail = $admin + array( - 'admin/structure' => t('Structure'), - ); + 'admin/structure' => t('Structure'), + ); $this->assertBreadcrumb('admin/structure/taxonomy', $trail); $trail += array( @@ -74,8 +74,8 @@ function testBreadCrumbs() { // Verify Menu administration breadcrumbs. $trail = $admin + array( - 'admin/structure' => t('Structure'), - ); + 'admin/structure' => t('Structure'), + ); $this->assertBreadcrumb('admin/structure/menu', $trail); $trail += array( @@ -91,9 +91,9 @@ function testBreadCrumbs() { // Verify Node administration breadcrumbs. $trail = $admin + array( - 'admin/structure' => t('Structure'), - 'admin/structure/types' => t('Content types'), - ); + 'admin/structure' => t('Structure'), + 'admin/structure/types' => t('Content types'), + ); $this->assertBreadcrumb('admin/structure/types/add', $trail); $this->assertBreadcrumb("admin/structure/types/manage/$type", $trail); $trail += array( @@ -102,8 +102,8 @@ function testBreadCrumbs() { $this->assertBreadcrumb("admin/structure/types/manage/$type/fields", $trail); $this->assertBreadcrumb("admin/structure/types/manage/$type/display", $trail); $trail_teaser = $trail + array( - "admin/structure/types/manage/$type/display" => t('Manage display'), - ); + "admin/structure/types/manage/$type/display" => t('Manage display'), + ); $this->assertBreadcrumb("admin/structure/types/manage/$type/display/teaser", $trail_teaser); $this->assertBreadcrumb("admin/structure/types/manage/$type/delete", $trail); $trail += array( @@ -116,8 +116,8 @@ function testBreadCrumbs() { $format = reset($filter_formats); $format_id = $format->id(); $trail = $config + array( - 'admin/config/content' => t('Content authoring'), - ); + 'admin/config/content' => t('Content authoring'), + ); $this->assertBreadcrumb('admin/config/content/formats', $trail); $trail += array( @@ -203,8 +203,8 @@ function testBreadCrumbs() { ); $trail = $home + $expected; $tree = $expected + array( - 'node/' . $parent->id() => $parent->menu['title'], - ); + 'node/' . $parent->id() => $parent->menu['title'], + ); $trail += array( 'node/' . $parent->id() => $parent->menu['title'], ); diff --git a/core/modules/system/src/Tests/ParamConverter/UpcastingTest.php b/core/modules/system/src/Tests/ParamConverter/UpcastingTest.php index f7a3ab1..95a7eab 100644 --- a/core/modules/system/src/Tests/ParamConverter/UpcastingTest.php +++ b/core/modules/system/src/Tests/ParamConverter/UpcastingTest.php @@ -76,7 +76,7 @@ public function testEntityLanguage() { $translation = $node->addTranslation('de'); $translation->setTitle('Deutscher Titel')->save(); - $this->drupalGet("paramconverter_test/node/" . $node->id() . "/test_language"); + $this->drupalGet("/paramconverter_test/node/" . $node->id() . "/test_language"); $this->assertRaw("English label"); $this->drupalGet("paramconverter_test/node/" . $node->id() . "/test_language", array('language' => $language)); $this->assertRaw("Deutscher Titel"); diff --git a/core/modules/system/src/Tests/Routing/RouterTest.php b/core/modules/system/src/Tests/Routing/RouterTest.php index 59812c0..e328759 100644 --- a/core/modules/system/src/Tests/Routing/RouterTest.php +++ b/core/modules/system/src/Tests/Routing/RouterTest.php @@ -121,7 +121,7 @@ public function testDynamicRoutes() { * Checks that a request with text/html response gets rendered as a page. */ public function testControllerResolutionPage() { - $this->drupalGet('router_test/test10'); + $this->drupalGet('/router_test/test10'); $this->assertRaw('abcde', 'Correct body was found.'); @@ -182,7 +182,7 @@ public function testUserAccount() { public function testControllerResolutionAjax() { // This will fail with a JSON parse error if the request is not routed to // The correct controller. - $this->drupalGetAJAX('router_test/test10'); + $this->drupalGetAJAX('/router_test/test10'); $this->assertEqual($this->drupalGetHeader('Content-Type'), 'application/json', 'Correct mime content type was returned');