function LocalActionTest::testLocalAction

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::testLocalAction()
  2. 10 core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::testLocalAction()
  3. 11.x core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::testLocalAction()

Tests appearance of local actions.

File

core/modules/system/tests/src/Functional/Menu/LocalActionTest.php, line 40

Class

LocalActionTest
Tests local actions derived from router and added/altered via hooks.

Namespace

Drupal\Tests\system\Functional\Menu

Code

public function testLocalAction() {
    $this->drupalGet('menu-test-local-action');
    // Ensure that both menu and route based actions are shown.
    $this->assertLocalAction([
        [
            Url::fromRoute('menu_test.local_action4'),
            'My dynamic-title action',
        ],
        [
            Url::fromRoute('menu_test.local_action4'),
            Html::escape("<script>alert('Welcome to the jungle!')</script>"),
        ],
        [
            Url::fromRoute('menu_test.local_action4'),
            Html::escape("<script>alert('Welcome to the derived jungle!')</script>"),
        ],
        [
            Url::fromRoute('menu_test.local_action2'),
            'My hook_menu action',
        ],
        [
            Url::fromRoute('menu_test.local_action3'),
            'My YAML discovery action',
        ],
        [
            Url::fromRoute('menu_test.local_action5'),
            'Title override',
        ],
    ]);
    // Test a local action title that changes based on a config value.
    $this->drupalGet(Url::fromRoute('menu_test.local_action6'));
    $this->assertLocalAction([
        [
            Url::fromRoute('menu_test.local_action5'),
            'Original title',
        ],
    ]);
    // Verify the expected cache tag in the response headers.
    $header_values = explode(' ', $this->drupalGetHeader('x-drupal-cache-tags'));
    $this->assertContains('config:menu_test.links.action', $header_values, "Found 'config:menu_test.links.action' cache tag in header");
    
    /** @var \Drupal\Core\Config\Config $config */
    $config = $this->container
        ->get('config.factory')
        ->getEditable('menu_test.links.action');
    $config->set('title', 'New title');
    $config->save();
    $this->drupalGet(Url::fromRoute('menu_test.local_action6'));
    $this->assertLocalAction([
        [
            Url::fromRoute('menu_test.local_action5'),
            'New title',
        ],
    ]);
}

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