You are here

public function LingotekTaxonomyTermLongTitleTranslationTest::testBulkTermTranslationUsingActions in Lingotek Translation 8

Tests that a taxonomy_term can be translated using the actions on the management page.

File

src/Tests/LingotekTaxonomyTermLongTitleTranslationTest.php, line 290

Class

LingotekTaxonomyTermLongTitleTranslationTest
Tests translating a taxonomy term with a very long title that doesn't fit.

Namespace

Drupal\lingotek\Tests

Code

public function testBulkTermTranslationUsingActions() {

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);

  // Add a language.
  ConfigurableLanguage::createFromLangcode('de')
    ->setThirdPartySetting('lingotek', 'locale', 'de_AT')
    ->save();
  $bundle = $this->vocabulary
    ->id();
  $edit = [
    "taxonomy_term[{$bundle}][enabled]" => 1,
    "taxonomy_term[{$bundle}][profiles]" => 'manual',
    "taxonomy_term[{$bundle}][fields][name]" => 1,
    "taxonomy_term[{$bundle}][fields][description]" => 1,
  ];
  $this
    ->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');

  // Create a term.
  $edit = array();
  $edit['name[0][value]'] = 'Llamas are cool';
  $edit['description[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $this
    ->drupalPostForm("admin/structure/taxonomy/manage/{$bundle}/add", $edit, t('Save'));
  $this
    ->goToContentBulkManagementForm('taxonomy_term');
  $basepath = \Drupal::request()
    ->getBasePath();

  // I can init the upload of content.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/taxonomy_term/1?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
  $edit = [
    'table[1]' => TRUE,
    // Taxonomy_term 1.
    'operation' => 'upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // I can check current status.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
  $edit = [
    'table[1]' => TRUE,
    // Taxonomy_term 1.
    'operation' => 'check_upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // Request the German (AT) translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
  $edit = [
    'table[1]' => TRUE,
    // Taxonomy_term 1.
    'operation' => 'request_translation:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.added_target_locale'));

  // Check status of the Spanish translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/check_target/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
  $edit = [
    'table[1]' => TRUE,
    // Taxonomy_term 1.
    'operation' => 'check_translation:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.checked_target_locale'));

  // Download the Spanish translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/de_AT?destination=' . $basepath . '/admin/lingotek/manage/taxonomy_term');
  $edit = [
    'table[1]' => TRUE,
    // Taxonomy_term 1.
    'operation' => 'download:de',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // Download translation. It must fail with a useful error message.
  $this
    ->assertText('The download for taxonomy_term Llamas are cool failed because of the length of one field translation value: name.');
  $this
    ->assertIdentical('de_AT', \Drupal::state()
    ->get('lingotek.downloaded_locale'));
}