function ContentTranslationOperationsTest::testOperationTranslateLink

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationOperationsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationOperationsTest::testOperationTranslateLink()
  2. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationOperationsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationOperationsTest::testOperationTranslateLink()
  3. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationOperationsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationOperationsTest::testOperationTranslateLink()

Tests that the operation "Translate" is displayed in the content listing.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationOperationsTest.php, line 78

Class

ContentTranslationOperationsTest
Tests the content translation operations available in the content listing.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function testOperationTranslateLink() : void {
    $node = $this->drupalCreateNode([
        'type' => 'article',
        'langcode' => 'es',
    ]);
    // Verify no translation operation links are displayed for users without
    // permission.
    $this->drupalLogin($this->baseUser1);
    $this->drupalGet('admin/content');
    $this->assertSession()
        ->linkByHrefNotExists('node/' . $node->id() . '/translations');
    $this->drupalLogout();
    // Verify there's a translation operation link for users with enough
    // permissions.
    $this->drupalLogin($this->baseUser2);
    $this->drupalGet('admin/content');
    $this->assertSession()
        ->linkByHrefExists('node/' . $node->id() . '/translations');
    // Ensure that an unintended misconfiguration of permissions does not open
    // access to the translation form, see https://www.drupal.org/node/2558905.
    $this->drupalLogout();
    user_role_change_permissions(Role::AUTHENTICATED_ID, [
        'create content translations' => TRUE,
        'access content' => FALSE,
    ]);
    $this->drupalLogin($this->baseUser1);
    $this->drupalGet($node->toUrl('drupal:content-translation-overview'));
    $this->assertSession()
        ->statusCodeEquals(403);
    // Ensure that the translation overview is also not accessible when the user
    // has 'access content', but the node is not published.
    user_role_change_permissions(Role::AUTHENTICATED_ID, [
        'create content translations' => TRUE,
        'access content' => TRUE,
    ]);
    $node->setUnpublished()
        ->save();
    $this->drupalGet($node->toUrl('drupal:content-translation-overview'));
    $this->assertSession()
        ->statusCodeEquals(403);
    $this->drupalLogout();
    // Ensure the 'Translate' local task does not show up anymore when disabling
    // translations for a content type.
    $node->setPublished()
        ->save();
    user_role_change_permissions(Role::AUTHENTICATED_ID, [
        'administer content translation' => TRUE,
        'administer languages' => TRUE,
    ]);
    $this->drupalPlaceBlock('local_tasks_block');
    $this->drupalLogin($this->baseUser2);
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()
        ->linkByHrefExists('node/' . $node->id() . '/translations');
    static::disableBundleTranslation('node', 'article');
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()
        ->linkByHrefNotExists('node/' . $node->id() . '/translations');
}

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