function PathWithNodeAccessGrantsTest::testAliasTranslation

Same name in other branches
  1. 11.x core/modules/path/tests/src/Functional/PathWithNodeAccessGrantsTest.php \Drupal\Tests\path\Functional\PathWithNodeAccessGrantsTest::testAliasTranslation()

Tests alias functionality through the admin interfaces.

File

core/modules/path/tests/src/Functional/PathWithNodeAccessGrantsTest.php, line 77

Class

PathWithNodeAccessGrantsTest
Confirm that paths work with node access grants implementations.

Namespace

Drupal\Tests\path\Functional

Code

public function testAliasTranslation() : void {
    // Rebuild the permissions to update 'node_access' table.
    node_access_rebuild();
    $alias = $this->randomMachineName();
    $permissions = [
        'access administration pages',
        'view any unpublished content',
        'use editorial transition create_new_draft',
        'use editorial transition publish',
        'create content translations',
        'create page content',
        'create url aliases',
        'edit any page content',
        'translate any entity',
    ];
    $this->drupalLogin($this->drupalCreateUser($permissions));
    // Create a node, add URL alias and publish it.
    $this->drupalGet('node/add/page');
    $edit['title[0][value]'] = 'test';
    $edit['path[0][alias]'] = '/' . $alias;
    $edit['moderation_state[0][state]'] = 'published';
    $this->submitForm($edit, 'Save');
    // Add french translation.
    $this->drupalGet('node/1/translations');
    $this->clickLink('Add');
    $this->submitForm([
        'moderation_state[0][state]' => 'published',
    ], 'Save (this translation)');
    // Translation should be saved.
    $this->assertSession()
        ->pageTextContains('Basic page test has been updated.');
    // There shouldn't be any validation errors.
    $this->assertSession()
        ->pageTextNotContains("Either the path '/node/1' is invalid or you do not have access to it.");
    // Translation should be saved with the given alias.
    $this->container
        ->get('path_alias.manager')
        ->cacheClear();
    $translation_alias = $this->container
        ->get('path_alias.manager')
        ->getAliasByPath('/node/1', 'fr');
    $this->assertSame('/' . $alias, $translation_alias);
}

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