You are here

function ContentTmgmtEntitySourceListTest::testTranslationSubmissions in Translation Management Tool 8

File

sources/content/tests/src/Functional/ContentTmgmtEntitySourceListTest.php, line 188

Class

ContentTmgmtEntitySourceListTest
Tests the user interface for entity translation lists.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

function testTranslationSubmissions() {

  // Simple submission.
  $nid = $this->nodes['article']['en'][0]
    ->id();
  $edit = array();
  $edit["items[{$nid}]"] = 1;
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Request translation'));
  $this
    ->assertSession()
    ->pageTextContains(t('One job needs to be checked out.'));

  // Submission of two entities of the same original language.
  $nid1 = $this->nodes['article']['en'][0]
    ->id();
  $nid2 = $this->nodes['article']['en'][1]
    ->id();
  $edit = array();
  $edit["items[{$nid1}]"] = 1;
  $edit["items[{$nid2}]"] = 1;
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Request translation'));
  $this
    ->assertSession()
    ->pageTextContains(t('One job needs to be checked out.'));

  // Submission of several entities of different original languages.
  $nid1 = $this->nodes['article']['en'][0]
    ->id();
  $nid2 = $this->nodes['article']['en'][1]
    ->id();
  $nid3 = $this->nodes['article']['en'][2]
    ->id();
  $nid4 = $this->nodes['article']['en'][3]
    ->id();
  $nid5 = $this->nodes['article']['de'][0]
    ->id();
  $nid6 = $this->nodes['article']['fr'][0]
    ->id();
  $edit = array();
  $edit["items[{$nid1}]"] = 1;
  $edit["items[{$nid2}]"] = 1;
  $edit["items[{$nid3}]"] = 1;
  $edit["items[{$nid4}]"] = 1;
  $edit["items[{$nid5}]"] = 1;
  $edit["items[{$nid6}]"] = 1;
  $edit['target_language'] = 'it';
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Request translation'));
  $this
    ->assertSession()
    ->pageTextContains(t('@count jobs need to be checked out.', array(
    '@count' => '3',
  )));

  // Submission of several entities of different original languages to multiple
  // target languages.
  $edit = array();
  $edit["items[{$nid1}]"] = 1;
  $edit["items[{$nid2}]"] = 1;
  $edit["items[{$nid3}]"] = 1;
  $edit["items[{$nid4}]"] = 1;
  $edit["items[{$nid5}]"] = 1;
  $edit["items[{$nid6}]"] = 1;
  $edit['target_language'] = '_multiple';
  $edit['target_languages[de]'] = TRUE;
  $edit['target_languages[fr]'] = TRUE;

  // This needs to create 4 jobs:
  // EN => DE
  // EN => FR
  // DE => FR
  // FR => DE
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Request translation'));
  $this
    ->assertSession()
    ->pageTextContains(t('@count jobs need to be checked out.', array(
    '@count' => 4,
  )));

  // Submission of several entities of different original languages to all
  // target languages.
  $edit = array();
  $edit["items[{$nid1}]"] = 1;
  $edit["items[{$nid2}]"] = 1;
  $edit["items[{$nid3}]"] = 1;
  $edit["items[{$nid4}]"] = 1;
  $edit["items[{$nid5}]"] = 1;
  $edit["items[{$nid6}]"] = 1;
  $edit['target_language'] = '_all';

  // This needs to create 9 jobs:
  // EN => DE
  // EN => FR
  // EN => IT
  // DE => FR
  // DE => EN
  // DE => IT
  // FR => DE
  // FR => IT
  // FR => EN
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Request translation'));
  $this
    ->assertSession()
    ->pageTextContains(t('@count jobs need to be checked out.', array(
    '@count' => 9,
  )));

  // Submission of several entities of different original languages to all
  // target languages and force a source language.
  $edit = array();
  $edit["items[{$nid1}]"] = 1;
  $edit["items[{$nid2}]"] = 1;
  $edit["items[{$nid3}]"] = 1;
  $edit["items[{$nid4}]"] = 1;
  $edit["items[{$nid5}]"] = 1;
  $edit["items[{$nid6}]"] = 1;
  $edit['source_language'] = 'fr';
  $edit['target_language'] = '_all';

  // This needs to create 3 jobs.
  // FR => DE
  // FR => IT
  // FR => EN
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Request translation'));
  $this
    ->assertSession()
    ->pageTextContains(t('@count jobs need to be checked out.', array(
    '@count' => 3,
  )));
}