function MenuUiTest::testMenuQueryAndFragment

Same name and namespace in other branches
  1. 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuQueryAndFragment()
  2. 8.9.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuQueryAndFragment()
  3. 10 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 657

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testMenuQueryAndFragment() : void {
    $this->drupalLogin($this->adminUser);
    // Make a path with query and fragment on.
    $path = '/test-page?arg1=value1&arg2=value2';
    $item = $this->addMenuLink('', $path);
    // Check that the path has both the query and fragment.
    $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
    $this->assertSession()
        ->fieldValueEquals('link[0][uri]', $path);
    // Now change the path to something without query and fragment.
    $path = '/test-page';
    $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
    $this->submitForm([
        'link[0][uri]' => $path,
    ], 'Save');
    $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
    $this->assertSession()
        ->fieldValueEquals('link[0][uri]', $path);
    // 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->assertSession()
        ->fieldValueEquals('link[0][uri]', $path);
    $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
    $this->submitForm([], 'Save');
    $this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
    $this->assertSession()
        ->fieldValueEquals('link[0][uri]', $path);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.