public function ParagraphsConfigTest::testContentTranslationForm

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

Tests content translation form translatability constraints messages.

File

paragraphs/tests/src/Functional/WidgetStable/ParagraphsConfigTest.php, line 73

Class

ParagraphsConfigTest
Tests paragraphs configuration.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

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');

  // 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::createFromLangcode('de')
    ->save();

  // Enable translation for paragraphed content type.
  $edit = [
    'entity_types[node]' => TRUE,
    'settings[node][paragraphed_test][translatable]' => TRUE,
    'settings[node][paragraphed_test][fields][field_paragraphs]' => 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.field_paragraphs');
  $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][field_paragraphs]' => 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.field_paragraphs');
  $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.
  if ($this
    ->coreVersion('10.2')) {
    $this
      ->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
    $selected_group = [
      'new_storage_type' => 'reference',
    ];
    $this
      ->submitForm($selected_group, 'Change field group');
    $edit = [
      'group_field_options_wrapper' => 'field_ui:entity_reference:node',
      'label' => 'new_no_field_paragraphs',
      'field_name' => 'new_no_field_paragraphs',
    ];
    $this
      ->submitForm($edit, 'Continue');
  }
  else {
    $this
      ->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
    $edit = [
      'new_storage_type' => 'field_ui:entity_reference:node',
      'label' => 'new_no_field_paragraphs',
      'field_name' => 'new_no_field_paragraphs',
    ];
    $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');
}