function ContentTranslationSettingsTest::testFieldTranslatableSettingsUI

Same name in other branches
  1. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationSettingsTest::testFieldTranslatableSettingsUI()
  2. 10 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 289

Class

ContentTranslationSettingsTest
Tests the content translation settings UI.

Namespace

Drupal\Tests\content_translation\Functional

Code

public function testFieldTranslatableSettingsUI() {
    // 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.
    $edit = [
        'new_storage_type' => 'text',
        'label' => 'Test',
        'field_name' => 'article_text',
    ];
    $this->drupalGet('admin/structure/types/manage/article/fields/add-field');
    $this->submitForm($edit, 'Save and continue');
    // 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.');
    // 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.