diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 999f447..4dde31a 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -470,7 +470,13 @@ public function toString() { return $this->unroutedUrlAssembler()->assemble($this->getUri(), $this->getOptions()); } - return $this->urlGenerator()->generateFromRoute($this->getRouteName(), $this->getRouteParameters(), $this->getOptions()); + try { + return $this->urlGenerator()->generateFromRoute($this->getRouteName(), $this->getRouteParameters(), $this->getOptions()); + } + catch (\Exception $e) { + debug($e->getMessage()); + return ''; + } } /** diff --git a/core/modules/node/src/Tests/NodeViewTest.php b/core/modules/node/src/Tests/NodeViewTest.php index 18f7133..01a640d 100644 --- a/core/modules/node/src/Tests/NodeViewTest.php +++ b/core/modules/node/src/Tests/NodeViewTest.php @@ -26,13 +26,13 @@ public function testHtmlHeadLinks() { $this->drupalGet($node->getSystemPath()); $result = $this->xpath('//link[@rel = "version-history"]'); - $this->assertEqual($result[0]['href'], Url::fromUri("base://node/{$node->id()}/revisions")->toString()); + $this->assertEqual($result[0]['href'], $node->url('version-history')); $result = $this->xpath('//link[@rel = "edit-form"]'); - $this->assertEqual($result[0]['href'], Url::fromUri("base://node/{$node->id()}/edit")->toString()); + $this->assertEqual($result[0]['href'], $node->url('edit-form')); $result = $this->xpath('//link[@rel = "canonical"]'); - $this->assertEqual($result[0]['href'], Url::fromUri("base://node/{$node->id()}")->toString()); + $this->assertEqual($result[0]['href'], $node->url()); } } diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php index 9f453d9..4ad8020 100644 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ b/core/modules/rest/src/Tests/RESTTestBase.php @@ -92,7 +92,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) $curl_options = array( CURLOPT_HTTPGET => TRUE, CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options), + CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type), ); @@ -103,7 +103,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) CURLOPT_HTTPGET => FALSE, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $body, - CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options), + CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: ' . $mime_type, @@ -117,7 +117,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $body, - CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options), + CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: ' . $mime_type, @@ -131,7 +131,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_POSTFIELDS => $body, - CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options), + CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array( 'Content-Type: ' . $mime_type, @@ -144,7 +144,7 @@ protected function httpRequest($path, $method, $body = NULL, $mime_type = NULL) $curl_options = array( CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'DELETE', - CURLOPT_URL => $this->container->get('url_generator')->generateFromPath($path, $options), + CURLOPT_URL => Url::fromUri('base://' . $path, $options)->toString(), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array('X-CSRF-Token: ' . $token), ); diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php index 807e177..1674dd0 100644 --- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php @@ -21,7 +21,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase { * * @var array */ - public static $modules = array('block', 'search_extra_type'); + public static $modules = array('block', 'search_extra_type', 'test_page_test'); /** * User who can search and administer search. diff --git a/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php b/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php index 789687f..2b023a9 100644 --- a/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php +++ b/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php @@ -23,7 +23,7 @@ class SearchKeywordsConditionsTest extends SearchTestBase { * * @var array */ - public static $modules = array('comment', 'search_extra_type'); + public static $modules = array('comment', 'search_extra_type', 'test_page_test'); protected function setUp() { parent::setUp(); diff --git a/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml index d87bc3d..caea321 100644 --- a/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml +++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.info.yml @@ -4,5 +4,3 @@ description: 'Support module for Search module testing.' package: Testing version: VERSION core: 8.x -dependencies: - - views \ No newline at end of file diff --git a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php index 633a870..fc358d0 100644 --- a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php +++ b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\UrlGeneratorTrait; +use Drupal\Core\Url; use Drupal\search\Plugin\ConfigurableSearchPluginBase; /** @@ -60,7 +61,7 @@ public function execute() { } return array( array( - 'link' => $this->url('view.frontpage.page_1'), + 'link' => Url::fromRoute('test_page_test.test_page')->toString(), 'type' => 'Dummy result type', 'title' => 'Dummy title', 'snippet' => SafeMarkup::set("Dummy search snippet to display. Keywords: {$this->keywords}\n\nConditions: " . print_r($this->searchParameters, TRUE)), diff --git a/core/modules/serialization/src/Tests/EntityResolverTest.php b/core/modules/serialization/src/Tests/EntityResolverTest.php index 92242fd..e87b69b 100644 --- a/core/modules/serialization/src/Tests/EntityResolverTest.php +++ b/core/modules/serialization/src/Tests/EntityResolverTest.php @@ -32,6 +32,9 @@ class EntityResolverTest extends NormalizerTestBase { protected function setUp() { parent::setUp(); + $this->installSchema('system', 'router'); + \Drupal::service('router.builder')->rebuild(); + // Create the test field storage. entity_create('field_storage_config', array( 'entity_type' => 'entity_test_mulrev', @@ -69,7 +72,7 @@ function testUuidEntityResolver() { ), $field_uri => array( array( - 'href' => Url::fromUri('base://entity/entity_test_mulrev/' . $entity->id())->toString(), + 'href' => $entity->url(), ), ), ), @@ -77,7 +80,7 @@ function testUuidEntityResolver() { $field_uri => array( array( '_links' => array( - 'self' => Url::fromUri('base://entity/entity_test_mulrev/' . $entity->id())->toString(), + 'self' => $entity->url(), ), 'uuid' => array( array( diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php index 7aa353f..910e809 100644 --- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Url; use Drupal\node\Entity\NodeType; /** @@ -23,13 +24,23 @@ class BreadcrumbTest extends MenuTestBase { * * @var array */ - public static $modules = array('menu_test', 'block'); + public static $modules = ['menu_test', 'block', 'node']; /** * Test paths in the Standard profile. */ protected $profile = 'standard'; + /** + * @var \Drupal\user\UserInterface + */ + protected $admin_user; + + /** + * @var \Drupal\user\UserInterface + */ + protected $web_user; + protected function setUp() { parent::setUp(); @@ -51,105 +62,132 @@ protected function setUp() { */ function testBreadCrumbs() { // Prepare common base breadcrumb elements. - $home = array('' => 'Home'); - $admin = $home + array('admin' => t('Administration')); - $config = $admin + array('admin/config' => t('Configuration')); + $home = [['url' => Url::fromRoute(''), 'title' => 'Home']]; + $admin = $home + [1 => [ + 'url' => Url::fromRoute('system.admin'), + 'title' => t('Administration'), + ]]; + $config = $admin + [2 => [ + 'url' => Url::fromRoute('system.admin_config'), + 'title' => t('Configuration'), + ]]; $type = 'article'; // Verify Taxonomy administration breadcrumbs. - $trail = $admin + array( - 'admin/structure' => t('Structure'), - ); - $this->assertBreadcrumb('admin/structure/taxonomy', $trail); - - $trail += array( - 'admin/structure/taxonomy' => t('Taxonomy'), - ); - $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags', $trail); - $trail += array( - 'admin/structure/taxonomy/manage/tags' => t('Tags'), - ); - $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/overview', $trail); - $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/add', $trail); + $trail = $admin + [2 => [ + 'url' => Url::fromRoute('system.admin_structure'), + 'title' => t('Structure'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('taxonomy.vocabulary_list'), $trail); + + $trail += [3 => [ + 'url' => Url::fromRoute('taxonomy.vocabulary_list'), + 'title' => t('Taxonomy'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => 'tags']), $trail); + $trail += [4 => [ + 'url' => Url::fromRoute('entity.taxonomy_vocabulary.edit_form', ['taxonomy_vocabulary' => 'tags']), + 'title' => t('Tags'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('entity.taxonomy_vocabulary.overview_form', ['taxonomy_vocabulary' => 'tags']), $trail); + $this->assertBreadcrumb(Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => 'tags']), $trail); // Verify Menu administration breadcrumbs. - $trail = $admin + array( - 'admin/structure' => t('Structure'), - ); - $this->assertBreadcrumb('admin/structure/menu', $trail); - - $trail += array( - 'admin/structure/menu' => t('Menus'), - ); - $this->assertBreadcrumb('admin/structure/menu/manage/tools', $trail); - - $trail += array( - 'admin/structure/menu/manage/tools' => t('Tools'), - ); - $this->assertBreadcrumb("admin/structure/menu/link/node.add_page/edit", $trail); - $this->assertBreadcrumb('admin/structure/menu/manage/tools/add', $trail); + $trail = $admin + [2 => [ + 'url' => Url::fromRoute('system.admin_structure'), + 'title' => t('Structure'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('menu_ui.overview_page'), $trail); + + $trail += [3 => [ + 'url' => Url::fromRoute('menu_ui.overview_page'), + 'title' => t('Menus'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('entity.menu.edit_form', ['menu' => 'tools']), $trail); + + $trail += [4 => [ + 'url' => Url::fromRoute('entity.menu.edit_form', ['menu' => 'tools']), + 'title' => t('Tools'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('menu_ui.link_edit', ['menu_link_plugin' => 'node.add_page']), $trail); + $this->assertBreadcrumb(Url::fromRoute('entity.menu.add_link_form', ['menu' => 'tools']), $trail); // Verify Node administration breadcrumbs. - $trail = $admin + array( - '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( - "admin/structure/types/manage/$type" => t('Article'), - ); - $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'), - ); - $this->assertBreadcrumb("admin/structure/types/manage/$type/display/teaser", $trail_teaser); - $this->assertBreadcrumb("admin/structure/types/manage/$type/delete", $trail); - $trail += array( - "admin/structure/types/manage/$type/fields" => t('Manage fields'), - ); - $this->assertBreadcrumb("admin/structure/types/manage/$type/fields/node.$type.body", $trail); + $trail = $admin + [2 => + [ + 'url' => Url::fromRoute('system.admin_structure'), + 'title' => t('Structure'), + ], + 3 => [ + 'url' => Url::fromRoute('node.overview_types'), + 'title' => t('Content types'), + ], + ]; + $this->assertBreadcrumb(Url::fromRoute('node.type_add'), $trail); + $this->assertBreadcrumb(Url::fromRoute('entity.node_type.edit_form', ['node_type' => $type]), $trail); + $trail += [4 => [ + 'url' => Url::fromRoute('entity.node_type.edit_form', ['node_type' => $type]), + 'title' => t('Article'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('field_ui.overview_node'), $trail); + $this->assertBreadcrumb(Url::fromRoute('field_ui.display_overview_node'), $trail); + $trail_teaser = $trail + [5 => [ + 'url' => Url::fromRoute('field_ui.display_overview_node'), + 'title' => t('Manage display'), + ]]; + + + $this->assertBreadcrumb(Url::fromRoute('field_ui.display_overview_view_mode_node', ['view_mode' => 'teaser']), $trail_teaser); + $this->assertBreadcrumb(Url::fromRoute('entity.node_type.delete_form', ['node_type' => $type]), $trail); + $trail += [6 => [ + 'url' => Url::fromRoute('field_ui.overview_node'), + 'title' => t('Manage fields'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('field_ui.field_edit_node', ['field_config' => "node.$type.body"]), $trail); // Verify Filter text format administration breadcrumbs. $filter_formats = filter_formats(); $format = reset($filter_formats); $format_id = $format->id(); - $trail = $config + array( - 'admin/config/content' => t('Content authoring'), - ); - $this->assertBreadcrumb('admin/config/content/formats', $trail); - - $trail += array( - 'admin/config/content/formats' => t('Text formats and editors'), - ); - $this->assertBreadcrumb('admin/config/content/formats/add', $trail); - $this->assertBreadcrumb("admin/config/content/formats/manage/$format_id", $trail); + $trail = $config + [3 => [ + 'url' => Url::fromRoute('system.admin_config_content'), + 'title' => t('Content authoring'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('filter.admin_overview'), $trail); + + $trail += [4 => [ + 'url' => Url::fromRoute('filter.admin_overview'), + 'title' => t('Text formats and editors'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('filter.format_add'), $trail); + $this->assertBreadcrumb(Url::fromRoute('entity.filter_format.edit_form', ['filter_format' => $format_id]), $trail); // @todo Remove this part once we have a _title_callback, see // https://drupal.org/node/2076085. - $trail += array( - "admin/config/content/formats/manage/$format_id" => $format->label(), - ); - $this->assertBreadcrumb("admin/config/content/formats/manage/$format_id/disable", $trail); + $trail += [5 => [ + 'url' => Url::fromRoute('entity.filter_format.edit_form', ['filter_format' => $format_id]), + 'title' => $format->label(), + ]]; + $this->assertBreadcrumb(Url::fromRoute('entity.filter_format.disable', ['filter_format' => $format_id]), $trail); // Verify node breadcrumbs (without menu link). $node1 = $this->drupalCreateNode(); $nid1 = $node1->id(); $trail = $home; - $this->assertBreadcrumb("node/$nid1", $trail); + $this->assertBreadcrumb($node1->urlInfo(), $trail); // Also verify that the node does not appear elsewhere (e.g., menu trees). $this->assertNoLink($node1->getTitle()); // Also verify that the node does not appear elsewhere (e.g., menu trees). $this->assertNoLink($node1->getTitle()); - $trail += array( - "node/$nid1" => $node1->getTitle(), - ); - $this->assertBreadcrumb("node/$nid1/edit", $trail); + $trail += [1 => [ + 'url' => $node1->urlInfo(), + 'title' => $node1->getTitle(), + ]]; + $this->assertBreadcrumb($node1->urlInfo('edit-form'), $trail); // Verify that breadcrumb on node listing page contains "Home" only. $trail = array(); - $this->assertBreadcrumb('node', $trail); + $this->assertBreadcrumb(Url::fromRoute('view.frontpage.page_1'), $trail); // Verify node breadcrumbs (in menu). // Do this separately for Main menu and Tools menu, since only the @@ -197,17 +235,20 @@ function testBreadCrumbs() { $edit = array( 'menu[menu_parent]' => $link->getMenuName() . ':' . $link->getPluginId(), ); - $this->drupalPostForm('node/' . $parent->id() . '/edit', $edit, t('Save and keep published')); - $expected = array( - "node" => $link->getTitle(), - ); + $this->drupalPostForm($parent->url('edit-form'), $edit, t('Save and keep published')); + $expected = [1 => [ + 'url' => Url::fromRoute('view.frontpage.page_1'), + 'title' => $link->getTitle(), + ]]; $trail = $home + $expected; - $tree = $expected + array( - 'node/' . $parent->id() => $parent->menu['title'], - ); - $trail += array( - 'node/' . $parent->id() => $parent->menu['title'], - ); + $tree = $expected + [2 => [ + 'url' => $parent->urlInfo(), + 'title' => $parent->menu['title'], + ]]; + $trail += [2 => [ + 'url' => $parent->urlInfo(), + 'title' => $parent->menu['title'], + ]]; // Add a taxonomy term/tag to last node, and add a link for that term to the // Tools menu. @@ -261,6 +302,7 @@ function testBreadCrumbs() { // Logout the user because we want to check the active class as well, which // is just rendered as anonymous user. $this->drupalLogout(); + $i = 0; foreach ($tags as $name => $data) { $term = $data['term']; /** @var \Drupal\menu_link_content\MenuLinkContentInterface $link */ @@ -268,10 +310,12 @@ function testBreadCrumbs() { $url = $link->getUrlObject(); $link_path = $url->getInternalPath(); - $tree += array( - $link_path => $link->getTitle(), - ); - $this->assertBreadcrumb($link_path, $trail, $term->getName(), $tree); + $tree += [$i++ => [ + 'url' => $url, + 'title' => $link->getTitle(), + ]]; + debug(array_keys($tree)); + $this->assertBreadcrumb($url, $trail, $term->getName(), $tree); $this->assertEscaped($parent->getTitle(), 'Tagged node found.'); // Additionally make sure that this link appears only once; i.e., the @@ -286,9 +330,10 @@ function testBreadCrumbs() { // Next iteration should expect this tag as parent link. // Note: Term name, not link name, due to taxonomy_term_page(). - $trail += array( - $link_path => $term->getName(), - ); + $trail += [$i => [ + 'url' => $url, + 'title' => $term->getName(), + ]]; } // Verify breadcrumbs on user and user/%. @@ -299,22 +344,23 @@ function testBreadCrumbs() { )); // Verify breadcrumb on front page. - $this->assertBreadcrumb('', array()); + $this->assertBreadcrumb(Url::fromRoute(''), array()); // Verify breadcrumb on user pages (without menu link) for anonymous user. $trail = $home; - $this->assertBreadcrumb('user', $trail, t('Log in')); - $this->assertBreadcrumb('user/' . $this->admin_user->id(), $trail, $this->admin_user->getUsername()); + $this->assertBreadcrumb(Url::fromRoute('user.page'), $trail, t('Log in')); + $this->assertBreadcrumb($this->admin_user->urlInfo(), $trail, $this->admin_user->getUsername()); // Verify breadcrumb on user pages (without menu link) for registered users. $this->drupalLogin($this->admin_user); $trail = $home; - $this->assertBreadcrumb('user', $trail, $this->admin_user->getUsername()); - $this->assertBreadcrumb('user/' . $this->admin_user->id(), $trail, $this->admin_user->getUsername()); - $trail += array( - 'user/' . $this->admin_user->id() => $this->admin_user->getUsername(), - ); - $this->assertBreadcrumb('user/' . $this->admin_user->id() . '/edit', $trail, $this->admin_user->getUsername()); + $this->assertBreadcrumb(Url::fromRoute('user.page'), $trail, $this->admin_user->getUsername()); + $this->assertBreadcrumb($this->admin_user->urlInfo(), $trail, $this->admin_user->getUsername()); + $trail += [1 => [ + 'url' => $this->admin_user->urlInfo(), + 'title' => $this->admin_user->getUserName(), + ]]; + $this->assertBreadcrumb($this->admin_user->urlInfo('edit-form'), $trail, $this->admin_user->getUsername()); // Create a second user to verify breadcrumb on user pages again. $this->web_user = $this->drupalCreateUser(array( @@ -325,19 +371,21 @@ function testBreadCrumbs() { // Verify correct breadcrumb and page title on another user's account pages. $trail = $home; - $this->assertBreadcrumb('user/' . $this->admin_user->id(), $trail, $this->admin_user->getUsername()); - $trail += array( - 'user/' . $this->admin_user->id() => $this->admin_user->getUsername(), - ); - $this->assertBreadcrumb('user/' . $this->admin_user->id() . '/edit', $trail, $this->admin_user->getUsername()); + $this->assertBreadcrumb($this->admin_user->urlInfo(), $trail, $this->admin_user->getUsername()); + $trail += [1 => [ + 'url' => $this->admin_user->urlInfo(), + 'title' => $this->admin_user->getUsername(), + ]]; + $this->assertBreadcrumb($this->admin_user->urlInfo('edit-form'), $trail, $this->admin_user->getUsername()); // Verify correct breadcrumb and page title when viewing own user account. $trail = $home; - $this->assertBreadcrumb('user/' . $this->web_user->id(), $trail, $this->web_user->getUsername()); - $trail += array( - 'user/' . $this->web_user->id() => $this->web_user->getUsername(), - ); - $this->assertBreadcrumb('user/' . $this->web_user->id() . '/edit', $trail, $this->web_user->getUsername()); + $this->assertBreadcrumb($this->web_user->urlInfo(), $trail, $this->web_user->getUsername()); + $trail += [1 => [ + 'url' => $this->web_user->urlInfo(), + 'title' => $this->web_user->getUsername(), + ]]; + $this->assertBreadcrumb($this->web_user->urlInfo('edit-form'), $trail, $this->web_user->getUsername()); // Create an only slightly privileged user being able to access site reports // but not administration pages. @@ -350,17 +398,20 @@ function testBreadCrumbs() { // page title, and that the breadcrumb is just the Home link (because the // user is not able to access "Administer". $trail = $home; - $this->assertBreadcrumb('admin', $trail, t('Access denied')); + $this->assertBreadcrumb(Url::fromRoute('system.admin'), $trail, t('Access denied')); $this->assertResponse(403); // Since the 'admin' path is not accessible, we still expect only the Home // link. - $this->assertBreadcrumb('admin/reports', $trail, t('Reports')); + $this->assertBreadcrumb(Url::fromRoute('system.admin_reports'), $trail, t('Reports')); $this->assertNoResponse(403); // Since the Reports page is accessible, that will show. - $trail += array('admin/reports' => t('Reports')); - $this->assertBreadcrumb('admin/reports/dblog', $trail, t('Recent log messages')); + $trail += [1 => [ + 'url' => Url::fromRoute('system.admin_reports'), + 'title' => t('Reports'), + ]]; + $this->assertBreadcrumb(Url::fromRoute('dblog.overview'), $trail, t('Recent log messages')); $this->assertNoResponse(403); // Ensure that the breadcrumb is safe against XSS. diff --git a/core/modules/system/src/Tests/Menu/MenuTestBase.php b/core/modules/system/src/Tests/Menu/MenuTestBase.php index 4cb9fda..89c3fe3 100644 --- a/core/modules/system/src/Tests/Menu/MenuTestBase.php +++ b/core/modules/system/src/Tests/Menu/MenuTestBase.php @@ -35,7 +35,7 @@ */ protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, array $tree = array(), $last_active = TRUE) { if (isset($goto)) { - $this->drupalGet($goto); + $this->drupalGet((string) $goto); } $this->assertBreadcrumbParts($trail); @@ -63,14 +63,12 @@ protected function assertBreadcrumbParts($trail) { $pass = TRUE; // There may be more than one breadcrumb on the page. If $trail is empty // this test would go into an infinite loop, so we need to check that too. + $expected_titles = []; while ($trail && !empty($parts)) { - foreach ($trail as $path => $title) { - if ($path == '') { - $url = Url::fromRoute('')->toString(); - } - else { - $url = Url::fromUri('base://' . $path)->toString(); - } + foreach ($trail as $trail_parts) { + $title = $trail_parts['title']; + $expected_titles[] = $title; + $url = $trail_parts['url']->toString(); $part = array_shift($parts); $pass = ($pass && $part['href'] === $url && $part['text'] === String::checkPlain($title)); } @@ -79,7 +77,7 @@ protected function assertBreadcrumbParts($trail) { $pass = ($pass && empty($parts)); $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', array( - '%parts' => implode(' » ', $trail), + '%parts' => implode(' » ', $expected_titles), '@path' => $this->getUrl(), ))); } @@ -97,19 +95,21 @@ protected function assertBreadcrumbParts($trail) { */ protected function assertMenuActiveTrail($tree, $last_active) { end($tree); - $active_link_path = key($tree); - $active_link_title = array_pop($tree); + $active_link_url = current($tree)['url']->toString(); + $active_link_title = current($tree)['title']; $xpath = ''; + $expected_titles = []; if ($tree) { $i = 0; - foreach ($tree as $link_path => $link_title) { + foreach ($tree as $tree_element) { $part_xpath = (!$i ? '//' : '/following-sibling::ul/descendant::'); $part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]'; $part_args = array( ':class' => 'active-trail', - ':href' => Url::fromUri('base://' . $link_path)->toString(), - ':title' => $link_title, + ':href' => $tree_element['url']->toString(), + ':title' => $tree_element['title'], ); + $expected_titles[] = $tree_element['title']; $xpath .= $this->buildXPathQuery($part_xpath, $part_args); $i++; } @@ -127,13 +127,15 @@ protected function assertMenuActiveTrail($tree, $last_active) { $args = array( ':class-trail' => 'active-trail', ':class-active' => 'active', - ':href' => Url::fromUri('base://' . $active_link_path)->toString(), + ':href' => $active_link_url, ':title' => $active_link_title, ); + debug($xpath); + debug($args); $elements = $this->xpath($xpath, $args); $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', array( '%title' => $active_link_title, - '%tree' => implode(' » ', $tree), + '%tree' => implode(' » ', $expected_titles), ))); } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml index 8d1283b..888262d 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml +++ b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml @@ -20,6 +20,14 @@ entity.entity_test_mul.delete_form: requirements: _access: 'TRUE' +entity.entity_test_mulrev.canonical: + path: '/entity/{entity_test_mulrev}' + defaults: + _entity_view: 'entity_test_mulrev.full' + _title: 'Test full view mode' + requirements: + _access: 'TRUE' + entity.entity_test_mulrev.delete_form: path: '/entity_test/delete/entity_test_mulrev/{entity_test_mulrev}' defaults: diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php index b5fc86f..027df27 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php @@ -38,7 +38,7 @@ * "bundle" = "type" * }, * links = { - * "canonical" = "entity.entity_test_mulrev.edit_form", + * "canonical" = "entity.entity_test_mulrev.canonical", * "delete-form" = "entity.entity_test_mulrev.delete_form", * "edit-form" = "entity.entity_test_mulrev.edit_form" * } diff --git a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php b/core/modules/views/src/Tests/Plugin/ExposedFormTest.php index 0de8695..06e5351 100644 --- a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php +++ b/core/modules/views/src/Tests/Plugin/ExposedFormTest.php @@ -131,7 +131,8 @@ public function testExposedFormRender() { $this->assertFieldByXpath('//form/@id', $this->getExpectedExposedFormId($view), 'Expected form ID found.'); - $expected_action = Url::fromUri('base://' . $view->display_handler->getUrl())->toString(); + $view->setDisplay('page_1'); + $expected_action = $view->display_handler->getUrlInfo()->toString(); $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.'); } diff --git a/core/modules/views/src/Tests/Wizard/BasicTest.php b/core/modules/views/src/Tests/Wizard/BasicTest.php index 173deb6..7011233 100644 --- a/core/modules/views/src/Tests/Wizard/BasicTest.php +++ b/core/modules/views/src/Tests/Wizard/BasicTest.php @@ -75,8 +75,8 @@ function testViewsWizardAndListing() { $this->assertText($node2->label()); // Check if we have the feed. - $this->assertLinkByHref(Url::fromUri('base://' . $view2['page[feed_properties][path]'])); - $elements = $this->cssSelect('link[href="' . Url::fromUri('base://' . $view2['page[feed_properties][path]'], ['absolute' => TRUE])->toString() . '"]'); + $this->assertLinkByHref(Url::fromRoute('view.' . $view2['id'] . '.feed_1')->toString()); + $elements = $this->cssSelect('link[href="' . Url::fromRoute('view.' . $view2['id'] . '.feed_1', [], ['absolute' => TRUE])->toString() . '"]'); $this->assertEqual(count($elements), 1, 'Feed found.'); $this->drupalGet($view2['page[feed_properties][path]']); $this->assertRaw('drupalGet('admin/structure/views'); $this->assertText($view2['label']); $this->assertText($view2['description']); - $this->assertLinkByHref(Url::fromUri('base://' . $view2['page[path]'])->toString()); + $this->assertLinkByHref(Url::fromRoute('view.' . $view2['id'] . '.page_1')->toString()); // The view should not have a REST export display. $this->assertNoText('REST export', 'If only the page option was enabled in the wizard, the resulting view does not have a REST export display.'); @@ -126,7 +126,7 @@ function testViewsWizardAndListing() { $this->drupalGet('admin/structure/views'); $this->assertText($view3['label']); $this->assertText($view3['description']); - $this->assertLinkByHref(Url::fromUri('base://' . $view3['page[path]'])->toString()); + $this->assertLinkByHref(Url::fromRoute('view.' . $view3['id'] . '.page_1')->toString()); // The view should not have a REST export display. $this->assertNoText('REST export', 'If only the page and block options were enabled in the wizard, the resulting view does not have a REST export display.');