function MenuUiTest::testMenuQueryAndFragment
Same name in other branches
- 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuQueryAndFragment()
- 10 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuQueryAndFragment()
- 11.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuQueryAndFragment()
Adds and removes a menu link with a query string and fragment.
File
-
core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiTest.php, line 515
Class
- MenuUiTest
- Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the UI.
Namespace
Drupal\Tests\menu_ui\FunctionalCode
public function testMenuQueryAndFragment() {
$this->drupalLogin($this->adminUser);
// Make a path with query and fragment on.
$path = '/test-page?arg1=value1&arg2=value2';
$item = $this->addMenuLink('', $path);
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
$this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
// Now change the path to something without query and fragment.
$path = '/test-page';
$this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', [
'link[0][uri]' => $path,
], t('Save'));
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
$this->assertFieldByName('link[0][uri]', $path, 'Path no longer has query or fragment.');
// Use <front>#fragment and ensure that saving it does not lose its content.
$path = '<front>?arg1=value#fragment';
$item = $this->addMenuLink('', $path);
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
$this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
$this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', [], t('Save'));
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
$this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.