You are here

public function ChineseBulkTranslationTest::testNodeTranslationUsingLinks in Lingotek Translation 8

Tests that a node can be translated using the links on the management page.

File

src/Tests/ChineseBulkTranslationTest.php, line 70

Class

ChineseBulkTranslationTest
Tests translating into chinese locales.

Namespace

Drupal\lingotek\Tests

Code

public function testNodeTranslationUsingLinks() {

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

  // Create a node.
  $edit = array();
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_profile'] = 'manual';
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));
  $this
    ->goToContentBulkManagementForm();
  $basepath = \Drupal::request()
    ->getBasePath();

  // Clicking English must init the upload of content.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');

  // And we cannot request yet a translation.
  $this
    ->assertNoLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->clickLink('EN');

  // There is a link for checking status.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');

  // And we can already request a translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->clickLink('EN');
  $this
    ->assertText('The import for node Llamas are cool is complete.');

  // Request the German (AT) translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/add_target/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->clickLink('ZH');
  $this
    ->assertText("Locale 'zh_CN' was added as a translation target for node Llamas are cool.");

  // Check that the requested locale is the right one.
  $this
    ->assertIdentical('zh_CN', \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/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->clickLink('ZH');
  $this
    ->assertText('The zh_CN translation for node Llamas are cool is ready for download.');

  // Download the Spanish translation.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/download/dummy-document-hash-id/zh_CN?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->clickLink('ZH');
  $this
    ->assertText('The translation of node Llamas are cool into zh_CN has been downloaded.');

  // Now the link is to the workbench, and it opens in a new tab.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/workbench/dummy-document-hash-id/zh_CN');
  $workbench_link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/dummy-document-hash-id/zh_CN' and @target='_blank']");
  $this
    ->assertEqual(count($workbench_link), 1, 'Workbench links open in a new tab.');
}