function ContentTranslationSettingsTest::testFieldTranslatableSettingsUI

Same name and namespace in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationSettingsTest::testFieldTranslatableSettingsUI()
  2. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationSettingsTest::testFieldTranslatableSettingsUI()
  3. 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationSettingsTest::testFieldTranslatableSettingsUI()

Tests that field setting depends on bundle translatability.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php, line 292

Class

ContentTranslationSettingsTest
Tests the content translation settings UI.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function testFieldTranslatableSettingsUI() : void {
  // At least one field needs to be translatable to enable article for
  // translation. Create an extra field to be used for this purpose. We use
  // the UI to test our form alterations.
  $this->fieldUIAddNewField('admin/structure/types/manage/article', 'article_text', 'Test', 'text');
  // Tests that field doesn't have translatable setting if bundle is not
  // translatable.
  $path = 'admin/structure/types/manage/article/fields/node.article.field_article_text';
  $this->drupalGet($path);
  $this->assertSession()
    ->fieldDisabled('edit-translatable');
  $this->assertSession()
    ->pageTextContains('To configure translation for this field, enable language support for this type.');
  // 'Users may translate this field' should be unchecked by default.
  $this->assertSession()
    ->checkboxNotChecked('translatable');
  // Tests that field has translatable setting if bundle is translatable.
  // Note: this field is not translatable when enable bundle translatability.
  $edit = [
    'entity_types[node]' => TRUE,
    'settings[node][article][settings][language][language_alterable]' => TRUE,
    'settings[node][article][translatable]' => TRUE,
    'settings[node][article][fields][field_article_text]' => TRUE,
  ];
  $this->assertSettings('node', 'article', TRUE, $edit);
  $this->drupalGet($path);
  $this->assertSession()
    ->fieldEnabled('edit-translatable');
  $this->assertSession()
    ->checkboxChecked('edit-translatable');
  $this->assertSession()
    ->pageTextNotContains('To enable translation of this field, enable language support for this type.');
}

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