function LocalTasksTest::testLocalTaskBlockUrl

Same name in other branches
  1. 10 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::testLocalTaskBlockUrl()

Tests local task block URLs for entities with path aliases.

File

core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php, line 309

Class

LocalTasksTest
Tests local tasks derived from router and added/altered via hooks.

Namespace

Drupal\Tests\system\Functional\Menu

Code

public function testLocalTaskBlockUrl() : void {
    // Install the necessary modules for the test.
    \Drupal::service('module_installer')->install([
        'path',
        'taxonomy',
    ]);
    $this->drupalCreateContentType([
        'type' => 'article',
    ]);
    $vocab = $this->createVocabulary([
        'vid' => 'tags',
    ]);
    $web_user = $this->drupalCreateUser([
        'create article content',
        'edit own article content',
        'create url aliases',
        'create terms in tags',
        'edit terms in tags',
    ]);
    // Create node and taxonomy term entities with path aliases.
    $entities = [
        'node' => $this->drupalCreateNode([
            'type' => 'article',
            'path' => [
                'alias' => '/original-node-alias',
            ],
            'uid' => $web_user->id(),
        ]),
        'term' => $this->createTerm($vocab, [
            'path' => [
                'alias' => '/original-term-alias',
            ],
            'uid' => $web_user->id(),
        ]),
    ];
    $this->drupalLogin($web_user);
    // Test the local task block URLs for both node and term entities.
    foreach ($entities as $entity_type => $entity) {
        $this->drupalGet($entity->toUrl());
        $this->assertSameLocalTaskUrl('/original-' . $entity_type . '-alias');
        $this->drupalGet($entity->toUrl('edit-form'));
        $new_alias = '/original-' . $entity_type . '-alias-updated';
        $edit = [
            'path[0][alias]' => $new_alias,
        ];
        $this->submitForm($edit, 'Save');
        $this->assertSameLocalTaskUrl($new_alias);
        $this->drupalGet($entity->toUrl('edit-form'));
        $this->assertSameLocalTaskUrl($new_alias);
    }
}

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