You are here

public function ParagraphsConfigTest::testContentTranslationForm in Paragraphs 8

Same name in this branch
  1. 8 tests/src/Functional/WidgetLegacy/ParagraphsConfigTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsConfigTest::testContentTranslationForm()
  2. 8 tests/src/Functional/WidgetStable/ParagraphsConfigTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsConfigTest::testContentTranslationForm()

Tests content translation form translatability constraints messages.

File

tests/src/Functional/WidgetLegacy/ParagraphsConfigTest.php, line 72

Class

ParagraphsConfigTest
Tests paragraphs configuration.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

public function testContentTranslationForm() {
  $this
    ->loginAsAdmin([
    'administer languages',
    'administer content translation',
    'create content translations',
    'translate any entity',
  ]);

  // Check warning message is displayed.
  $this
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->assertSession()
    ->pageTextContains('(* unsupported) Paragraphs fields do not support translation.');
  $this
    ->addParagraphedContentType('paragraphed_test', 'paragraphs_field', 'entity_reference_paragraphs');

  // Check error message is not displayed.
  $this
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->assertSession()
    ->pageTextContains('(* unsupported) Paragraphs fields do not support translation.');
  $this
    ->assertSession()
    ->responseNotContains('<div class="messages messages--error');

  // Add a second language.
  ConfigurableLanguage::create([
    'id' => 'de',
  ])
    ->save();

  // Enable translation for paragraphed content type.
  $edit = [
    'entity_types[node]' => TRUE,
    'settings[node][paragraphed_test][translatable]' => TRUE,
    'settings[node][paragraphed_test][fields][paragraphs_field]' => FALSE,
  ];
  $this
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->submitForm($edit, 'Save configuration');

  // Check error message is still not displayed.
  $this
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->assertSession()
    ->pageTextContains('(* unsupported) Paragraphs fields do not support translation.');
  $this
    ->assertSession()
    ->responseNotContains('<div class="messages messages--error');

  // Check content type field management warning.
  $this
    ->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field');
  $this
    ->assertSession()
    ->pageTextContains('Paragraphs fields do not support translation.');

  // Make the paragraphs field translatable.
  $edit = [
    'entity_types[node]' => TRUE,
    'settings[node][paragraphed_test][translatable]' => TRUE,
    'settings[node][paragraphed_test][fields][paragraphs_field]' => TRUE,
  ];
  $this
    ->drupalGet('admin/config/regional/content-language');
  $this
    ->submitForm($edit, 'Save configuration');

  // Check content type field management error.
  $this
    ->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs_field');
  $this
    ->assertSession()
    ->pageTextContains('Paragraphs fields do not support translation.');
  $this
    ->assertSession()
    ->responseContains('<div class="messages messages--error');

  // Check a not paragraphs translatable field does not display the message.
  $this
    ->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
  $edit = [
    'new_storage_type' => 'field_ui:entity_reference:node',
    'label' => 'new_no_paragraphs_field',
    'field_name' => 'new_no_paragraphs_field',
  ];
  $this
    ->submitForm($edit, 'Save and continue');
  $this
    ->submitForm([], 'Save field settings');
  $this
    ->assertSession()
    ->pageTextNotContains('Paragraphs fields do not support translation.');
  $this
    ->assertSession()
    ->responseNotContains('<div class="messages messages--warning');
}