You are here

public function LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.2.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()
  2. 3.3.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()
  3. 3.4.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()
  4. 3.5.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()
  5. 3.6.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()
  6. 3.7.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()
  7. 3.8.x tests/src/Functional/LingotekInterfaceTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekInterfaceTranslationTest::testAutomatedNotificationInterfaceTranslation()

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

File

tests/src/Functional/LingotekInterfaceTranslationTest.php, line 852

Class

LingotekInterfaceTranslationTest
Tests translating the user interface using the Lingotek form.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testAutomatedNotificationInterfaceTranslation() {

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

  // In Drupal.org CI the module will be at modules/contrib/lingotek.
  // In my local that's modules/lingotek. We need to generate the path and not
  // hardcode it.
  $path = drupal_get_path('module', 'lingotek_interface_translation_test');
  $component = $path;
  $indexOfModuleLink = 2;
  $assert_session = $this
    ->assertSession();

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->goToInterfaceTranslationManagementForm();
  $assert_session
    ->responseContains('lingotek_interface_translation_test');

  // Clicking English must init the upload of content.
  $this
    ->assertLingotekInterfaceTranslationUploadLink($component);
  $this
    ->clickLink('EN', $indexOfModuleLink);

  /** @var \Drupal\lingotek\LingotekInterfaceTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.interface_translation');

  // Assert the content is importing.
  $this
    ->assertIdentical(Lingotek::STATUS_IMPORTING, $translation_service
    ->getSourceStatus($component));
  $this
    ->goToInterfaceTranslationManagementForm();

  // Simulate the notification of content successfully uploaded.
  $url = Url::fromRoute('lingotek.notify', [], [
    'query' => [
      'project_id' => 'test_project',
      'document_id' => 'dummy-document-hash-id',
      'complete' => 'false',
      'type' => 'document_uploaded',
      'progress' => '0',
    ],
  ])
    ->setAbsolute()
    ->toString();
  $request = $this->client
    ->post($url, [
    'cookies' => $this->cookies,
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
    ],
    'http_errors' => FALSE,
  ]);
  $response = json_decode($request
    ->getBody(), TRUE);
  $this
    ->verbose($request);
  $this
    ->assertIdentical([], $response['result']['request_translations'], 'No translations have been requested after notification automatically.');
  $this
    ->goToInterfaceTranslationManagementForm();

  // Assert the content is imported.
  $this
    ->assertIdentical(Lingotek::STATUS_CURRENT, $translation_service
    ->getSourceStatus($component));

  // Assert the target is ready for requesting.
  $this
    ->assertIdentical(Lingotek::STATUS_REQUEST, $translation_service
    ->getTargetStatus($component, 'es'));

  // Request Spanish manually.
  $this
    ->clickLink('ES');

  // Assert the target is pending.
  $this
    ->goToInterfaceTranslationManagementForm();
  $this
    ->assertIdentical(Lingotek::STATUS_PENDING, $translation_service
    ->getTargetStatus($component, 'es'));

  // Simulate the notification of content successfully translated.
  $url = Url::fromRoute('lingotek.notify', [], [
    'query' => [
      'project_id' => 'test_project',
      'document_id' => 'dummy-document-hash-id',
      'locale_code' => 'es-ES',
      'locale' => 'es_ES',
      'complete' => 'true',
      'type' => 'target',
      'progress' => '100',
    ],
  ])
    ->setAbsolute()
    ->toString();
  $request = $this->client
    ->post($url, [
    'cookies' => $this->cookies,
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
    ],
    'http_errors' => FALSE,
  ]);
  $response = json_decode($request
    ->getBody(), TRUE);
  $this
    ->verbose($request);
  $this
    ->assertFalse($response['result']['download'], 'No targets have been downloaded after notification automatically.');
  $this
    ->goToInterfaceTranslationManagementForm();
  $this
    ->assertIdentical(Lingotek::STATUS_READY, $translation_service
    ->getTargetStatus($component, 'es'));

  // Download Spanish manually.
  $this
    ->clickLink('ES');

  // Assert the target is downloaded.
  $this
    ->goToInterfaceTranslationManagementForm();
  $this
    ->assertIdentical(Lingotek::STATUS_CURRENT, $translation_service
    ->getTargetStatus($component, 'es'));
}