You are here

public function RenderElementTypesTest::testLingotekTargetStatuses in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  2. 4.0.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  3. 3.0.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  4. 3.1.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  5. 3.2.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  6. 3.3.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  7. 3.4.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  8. 3.5.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  9. 3.7.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()
  10. 3.8.x tests/src/Functional/Render/Element/RenderElementTypesTest.php \Drupal\Tests\lingotek\Functional\Render\Element\RenderElementTypesTest::testLingotekTargetStatuses()

Tests #type 'lingotek_source_statuses'.

File

tests/src/Functional/Render/Element/RenderElementTypesTest.php, line 106

Class

RenderElementTypesTest
Tests the markup of lingotek render element types passed to \Drupal::service('renderer')->render().

Namespace

Drupal\Tests\lingotek\Functional\Render\Element

Code

public function testLingotekTargetStatuses() {
  $basepath = \Drupal::request()
    ->getBasePath();

  /** @var \Drupal\node\NodeInterface $entity */
  $entity = Node::create([
    'id' => 1,
    'title' => 'Llamas are cool',
    'type' => 'article',
  ]);
  $entity
    ->save();

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $this
    ->drupalGet('/lingotek_form_test/lingotek_translation_statuses/node/1');
  $this
    ->assertSession()
    ->responseContains('lingotek/css/base.css');

  // Assert there are no language icons as there's nothing to display yet.
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//div[contains(@class, "region-content")]/span[contains(@class, "language-icon")]');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//div[contains(@class, "region-content")]/a[contains(@class, "language-icon")]');
  $translation_service
    ->setTargetStatus($entity, 'es', Lingotek::STATUS_UNTRACKED);
  $this
    ->drupalGet('/lingotek_form_test/lingotek_translation_statuses/node/1');
  $this
    ->assertSession()
    ->responseContains('lingotek/css/base.css');
  $link = $this
    ->xpath("//span[@class='language-icon target-untracked' and @title='Spanish - Translation exists, but it is not being tracked by Lingotek' and text()='ES']");
  $this
    ->assertEqual(count($link), 1, 'Span exists.');
  $translation_service
    ->setDocumentId($entity, 'test-document-id');
  $translation_service
    ->setTargetStatus($entity, 'es', Lingotek::STATUS_REQUEST);
  $translation_service
    ->setTargetStatus($entity, 'de', Lingotek::STATUS_PENDING);
  $translation_service
    ->setTargetStatus($entity, 'ca', Lingotek::STATUS_READY);
  $this
    ->drupalGet('/lingotek_form_test/lingotek_translation_statuses/node/1');
  $this
    ->assertTargetAction("Check translation status", "{$basepath}/admin/lingotek/entity/check_target/test-document-id/de_DE?destination={$basepath}/lingotek_form_test/lingotek_translation_statuses/node/1");
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/de_DE");
  $this
    ->assertTargetAction("Request translation", "{$basepath}/admin/lingotek/entity/add_target/test-document-id/es_ES?destination={$basepath}/lingotek_form_test/lingotek_translation_statuses/node/1");
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/ca_ES");
  $this
    ->assertTargetAction("Download translation", "{$basepath}/admin/lingotek/entity/download/test-document-id/ca_ES?destination={$basepath}/lingotek_form_test/lingotek_translation_statuses/node/1");
  $this
    ->assertSession()
    ->responseContains('lingotek/css/base.css');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/entity/download/test-document-id/ca_ES?destination=" . $basepath . "/lingotek_form_test/lingotek_translation_statuses/node/1' and @class='language-icon target-ready' and @title='Catalan - Ready for Download' and text()='CA']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/entity/check_target/test-document-id/de_DE?destination=" . $basepath . "/lingotek_form_test/lingotek_translation_statuses/node/1' and @class='language-icon target-pending' and @title='German - In-progress' and text()='DE']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/entity/add_target/test-document-id/es_ES?destination=" . $basepath . "/lingotek_form_test/lingotek_translation_statuses/node/1' and @class='language-icon target-request' and @title='Spanish - Request translation' and text()='ES']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $translation_service
    ->setTargetStatus($entity, 'es', Lingotek::STATUS_INTERMEDIATE);
  $translation_service
    ->setTargetStatus($entity, 'de', Lingotek::STATUS_CURRENT);
  $translation_service
    ->setTargetStatus($entity, 'ca', Lingotek::STATUS_EDITED);
  $this
    ->drupalGet('/lingotek_form_test/lingotek_translation_statuses/node/1');
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/de_DE");
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/es_ES");
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/ca_ES");
  $this
    ->assertSession()
    ->responseContains('lingotek/css/base.css');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/test-document-id/ca_ES' and @target='_blank' and @class='language-icon target-edited' and @title='Catalan - Not current' and text()='CA']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/test-document-id/de_DE' and @target='_blank' and @class='language-icon target-current' and @title='German - Current' and text()='DE']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/workbench/test-document-id/es_ES' and @target='_blank' and @class='language-icon target-intermediate' and @title='Spanish - In-progress (interim translation downloaded)' and text()='ES']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $translation_service
    ->setTargetStatus($entity, 'es', Lingotek::STATUS_ERROR);
  $this
    ->drupalGet('/lingotek_form_test/lingotek_translation_statuses/node/1');
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/de_DE");
  $this
    ->assertTargetAction("Retry request", "{$basepath}/admin/lingotek/entity/add_target/test-document-id/es_ES?destination={$basepath}/lingotek_form_test/lingotek_translation_statuses/node/1");
  $this
    ->assertTargetAction("Retry download", "{$basepath}/admin/lingotek/entity/download/test-document-id/es_ES?destination={$basepath}/lingotek_form_test/lingotek_translation_statuses/node/1");
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/ca_ES");
  $this
    ->assertSession()
    ->responseContains('lingotek/css/base.css');
  $link = $this
    ->xpath("//a[@href='{$basepath}/admin/lingotek/entity/download/test-document-id/es_ES?destination=" . $basepath . "/lingotek_form_test/lingotek_translation_statuses/node/1' and @class='language-icon target-error' and @title='Spanish - Error' and text()='ES']");
  $this
    ->assertEqual(count($link), 1, 'Link exists.');
  $translation_service
    ->setTargetStatus($entity, 'es', Lingotek::STATUS_DISABLED);
  $this
    ->drupalGet('/lingotek_form_test/lingotek_translation_statuses/node/1');
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/de_DE");
  $this
    ->assertNoTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/es_ES");
  $this
    ->assertTargetAction("Open in Lingotek Workbench", "{$basepath}/admin/lingotek/workbench/test-document-id/ca_ES");
  $this
    ->assertSession()
    ->responseContains('lingotek/css/base.css');
  $link = $this
    ->xpath("//span[@class='language-icon target-disabled' and @title='Spanish - Disabled' and text()='ES']");
  $this
    ->assertEqual(count($link), 1, 'Span exists.');
}