You are here

function RequestBulkTranslationTest::testBulkSubmitTranslationPreselectTargetLanguage in TMGMT Extension Suite 8

Check target language preselection.

File

src/Tests/RequestBulkTranslationTest.php, line 20

Class

RequestBulkTranslationTest
Class RequestBulkTranslationTest

Namespace

Drupal\tmgmt_extension_suit\Tests

Code

function testBulkSubmitTranslationPreselectTargetLanguage() {
  $settings = [
    'body' => [
      [
        'value' => $this
          ->randomMachineName(32),
        'format' => filter_default_format(),
      ],
    ],
    'title' => $this
      ->randomMachineName(8),
    'type' => 'translatable_node',
    'uid' => \Drupal::currentUser()
      ->id(),
    'langcode' => 'fr',
  ];
  $node = Node::create($settings);
  $node
    ->save();

  // Preselect target languages: later.
  $this
    ->drupalPostForm('admin/tmgmt/sources', [
    'items[1]' => 'item[1]',
    'target_language' => Language::LANGCODE_NOT_SPECIFIED,
  ], t('Request translation in a batch'));
  $this
    ->assertFalse($this
    ->isFieldChecked('edit-target-language-de'));
  $this
    ->assertFalse($this
    ->isFieldChecked('edit-target-language-fr'));
  $this
    ->assertNoField('edit-target-language-en');

  // Preselect target languages: multiple.
  $this
    ->drupalPostForm('admin/tmgmt/sources', [
    'items[1]' => 'item[1]',
    'target_language' => SourceOverviewForm::MULTIPLE,
    'target_languages[en]' => 'en',
    'target_languages[fr]' => 'fr',
  ], t('Request translation in a batch'));
  $this
    ->assertFalse($this
    ->isFieldChecked('edit-target-language-de'));
  $this
    ->assertTrue($this
    ->isFieldChecked('edit-target-language-fr'));
  $this
    ->assertNoField('edit-target-language-en');

  // Preselect target languages: all.
  $this
    ->drupalPostForm('admin/tmgmt/sources', [
    'items[1]' => 'item[1]',
    'target_language' => SourceOverviewForm::ALL,
  ], t('Request translation in a batch'));
  $this
    ->assertTrue($this
    ->isFieldChecked('edit-target-language-de'));
  $this
    ->assertTrue($this
    ->isFieldChecked('edit-target-language-fr'));
  $this
    ->assertNoField('edit-target-language-en');

  // Preselect target languages: single.
  $this
    ->drupalPostForm('admin/tmgmt/sources', [
    'items[1]' => 'item[1]',
    'target_language' => 'de',
  ], t('Request translation in a batch'));
  $this
    ->assertTrue($this
    ->isFieldChecked('edit-target-language-de'));
  $this
    ->assertFalse($this
    ->isFieldChecked('edit-target-language-fr'));
  $this
    ->assertNoField('edit-target-language-en');
}