class TranslatorJavascriptTest

Verifies functionality of translator handling.

@group tmgmt

Hierarchy

Expanded class hierarchy of TranslatorJavascriptTest

File

tests/src/FunctionalJavascript/TranslatorJavascriptTest.php, line 13

Namespace

Drupal\Tests\tmgmt\FunctionalJavascript
View source
class TranslatorJavascriptTest extends WebDriverTestBase {
  use TmgmtTestTrait;

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = array(
    'tmgmt',
    'tmgmt_test',
    'node',
    'block',
    'locale',
  );

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  function setUp() : void {
    parent::setUp();

    // Login as admin to be able to set environment variables.
    $this
      ->loginAsAdmin();
    $this
      ->addLanguage('de');
    $this
      ->addLanguage('es');
    $this
      ->addLanguage('el');

    // Login as translation administrator to run these tests.
    $this
      ->loginAsTranslator(array(
      'administer tmgmt',
    ), TRUE);
  }

  /**
   * Test multiple local language with one single remote language.
   */
  public function testMultipleLocalToSingleRemoteMapping() {
    $this
      ->addLanguage('pt-br');
    $this
      ->addLanguage('pt-pt');
    $page = $this
      ->getSession()
      ->getPage();
    $assert_session = $this
      ->assertSession();

    // Add mapping to the file translator.
    $this
      ->drupalGet('admin/tmgmt/translators/manage/test_translator');
    $edit = array(
      'remote_languages_mappings[pt-br]' => 'pt',
      'remote_languages_mappings[pt-pt]' => 'pt',
    );
    $this
      ->submitForm($edit, 'Save');
    $this
      ->drupalGet('admin/tmgmt/translators/manage/test_translator');
    $assert_session
      ->fieldValueEquals('edit-remote-languages-mappings-pt-br', 'pt');

    // Test first local language.
    $job = tmgmt_job_match_item('en', 'pt-br');
    $job
      ->addItem('test_source', 'test', 0);
    $edit = array(
      'target_language' => 'pt-br',
    );
    $this
      ->drupalGet('admin/tmgmt/jobs/' . $job
      ->id());
    $page
      ->selectFieldOption('Target language', 'pt-br');
    $this
      ->assertSession()
      ->elementTextEquals('xpath', '//select[@id="edit-translator"]//option[@value="test_translator"]', 'Test provider');
    $this
      ->submitForm($edit, 'Submit to provider');
    $assert_session
      ->pageTextContains('Portuguese, Brazil');
    $this
      ->assertCount(1, $job
      ->getItems());
    $this
      ->assertNotEmpty($job
      ->getItems()[1]
      ->accepted());
    $this
      ->drupalGet('admin/tmgmt/items/' . 1);
    $assert_session
      ->pageTextContains('pt-br(pt): Text for job item with type ' . $job
      ->getItems()[1]
      ->getItemType() . ' and id ' . $job
      ->getItems()[1]
      ->getItemId() . '.');
    $this
      ->assertEquals('pt-br', $job
      ->getTargetLangcode());

    // Test the other local language.
    $job = tmgmt_job_match_item('en', 'pt-pt');
    $job
      ->addItem('test_source', 'test', 0);
    $this
      ->drupalGet('admin/tmgmt/jobs/' . $job
      ->id());
    $page
      ->selectFieldOption('Target language', 'pt-pt');
    $this
      ->assertSession()
      ->elementTextEquals('xpath', '//select[@id="edit-translator"]//option[@value="test_translator"]', 'Test provider');
    $this
      ->submitForm($edit, 'Submit to provider');
    $assert_session
      ->pageTextContains('Portuguese, Portugal');
    $this
      ->assertCount(1, $job
      ->getItems());
    $this
      ->assertNotEmpty($job
      ->getItems()[2]
      ->accepted());
    $this
      ->drupalGet('admin/tmgmt/items/' . 2);
    $this
      ->assertEquals('pt-pt', $job
      ->getTargetLangcode());
    $assert_session
      ->fieldValueEquals('dummy|deep_nesting[translation]', 'pt-pt(pt): Text for job item with type ' . $job
      ->getItems()[2]
      ->getItemType() . ' and id ' . $job
      ->getItems()[2]
      ->getItemId() . '.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TmgmtTestTrait::$admin_permissions protected property List of permissions used by loginAsAdmin().
TmgmtTestTrait::$admin_user protected property Drupal user object created by loginAsAdmin().
TmgmtTestTrait::$languageWeight protected property The language weight for new languages.
TmgmtTestTrait::$translator_permissions protected property List of permissions used by loginAsTranslator().
TmgmtTestTrait::$translator_user protected property Drupal user object created by loginAsTranslator().
TmgmtTestTrait::addLanguage function Sets the proper environment.
TmgmtTestTrait::assertJobItemLangCodes function Asserts job item language codes.
TmgmtTestTrait::assertTextByXpath protected function Asserts text in the page with an xpath expression.
TmgmtTestTrait::clickLinkWithImageTitle function Clicks on an image link with the provided title attribute.
TmgmtTestTrait::createJob function Creates, saves and returns a translation job.
TmgmtTestTrait::createTranslator function Creates, saves and returns a translator.
TmgmtTestTrait::loginAsAdmin function Will create a user with admin permissions and log it in.
TmgmtTestTrait::loginAsTranslator function Will create a user with translator permissions and log it in.
TranslatorJavascriptTest::$defaultTheme protected property
TranslatorJavascriptTest::$modules protected static property Modules to enable.
TranslatorJavascriptTest::setUp function
TranslatorJavascriptTest::testMultipleLocalToSingleRemoteMapping public function Test multiple local language with one single remote language.