diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/EmptyLinkPathTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/EmptyLinkPathTest.php new file mode 100644 index 0000000..a00792e --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/EmptyLinkPathTest.php @@ -0,0 +1,70 @@ + 'Menu link with empty path', + 'description' => 'Test handling of empty link path.', + 'group' => 'Menu', + ); + } + + /** + * Test automatic reparenting of menu links. + */ + function testEmptyLinkPath($module = 'menu_test') { + $path = ''; + + // Verify that the path is valid. + $path_is_valid = drupal_valid_path($path); + $this->assertTrue($path_is_valid, '<none> is a valid path.'); + + // Verify that url return an empty string. + $link = url($path); + $this->assertEqual($link, '', 'Url <none> return an empty string.'); + + // Menu link without a path return a span. + $link_title = 'Empty path'; + $link = array( + '#title' => $link_title, + '#href' => $path, + '#below' => array(), + '#localized_options' => array(), + '#attributes' => array() + ); + $menu_link = array( + 'element' => $link + ); + $menu_link_string = theme_menu_link($menu_link); + $expected_link_string = '' . $link_title . ''; + $contains_link = (strpos($menu_link_string, $expected_link_string) !== FALSE); + $this->assertTrue($contains_link, 'Menu link without path return a span.'); + + // Verify that theme_links() also accept path. + $links_string = theme_links(array( + 'links' => array( + array( + 'title' => $link_title, + 'href' => $path + ) + ), + 'attributes' => array(), + 'heading' => array() + )); + $contains_link = (strpos($links_string, $expected_link_string) !== FALSE); + $this->assertTrue($contains_link, 'Function theme_links() accept <none> path.'); + } + +}