You are here

public function LingotekNodeNotificationCallbackTest::testProfileRequestTargetOverridesNotificationNodeTranslation in Lingotek Translation 8.2

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

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

File

tests/src/Functional/LingotekNodeNotificationCallbackTest.php, line 745

Class

LingotekNodeNotificationCallbackTest
Tests translating a node using the notification callback.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testProfileRequestTargetOverridesNotificationNodeTranslation() {
  $profile = LingotekProfile::create([
    'id' => 'profile2',
    'label' => 'Profile with overrides',
    'auto_upload' => TRUE,
    'auto_request' => FALSE,
    'auto_download' => TRUE,
    'auto_download_worker' => FALSE,
    'language_overrides' => [
      'es' => [
        'overrides' => 'custom',
        'custom' => [
          'auto_request' => TRUE,
          'auto_download' => FALSE,
        ],
      ],
    ],
  ]);
  $profile
    ->save();
  ConfigurableLanguage::createFromLangcode('de')
    ->save();
  ConfigurableLanguage::createFromLangcode('it')
    ->save();

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

  // Create a node.
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'profile2';
  $this
    ->saveAndPublishNodeForm($edit);

  /** @var \Drupal\node\NodeInterface $node */
  $node = Node::load(1);

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $content_translation_service */
  $content_translation_service = \Drupal::service('lingotek.content_translation');

  // Assert the content is importing.
  $this
    ->assertIdentical(Lingotek::STATUS_IMPORTING, $content_translation_service
    ->getSourceStatus($node));
  $this
    ->goToContentBulkManagementForm();

  // 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
    ->assertIdentical([
    'es',
  ], $response['result']['request_translations'], 'Spanish language has been requested after notification automatically.');
  $this
    ->goToContentBulkManagementForm();
  $node = $this
    ->resetStorageCachesAndReloadNode();

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

  // Assert the target is pending.
  $this
    ->assertIdentical(Lingotek::STATUS_PENDING, $content_translation_service
    ->getTargetStatus($node, 'es'));
  $this
    ->assertIdentical(Lingotek::STATUS_REQUEST, $content_translation_service
    ->getTargetStatus($node, 'de'));
  $this
    ->goToContentBulkManagementForm();

  // 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
    ->assertEmpty($response['result']['download'], 'No translations has been downloaded after notification automatically.');
  $url = Url::fromRoute('lingotek.notify', [], [
    'query' => [
      'project_id' => 'test_project',
      'document_id' => 'dummy-document-hash-id',
      'locale_code' => 'de-DE',
      'locale' => 'de_DE',
      '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
    ->assertEmpty($response['result']['download'], 'No translations has been downloaded after notification automatically.');
  $this
    ->goToContentBulkManagementForm();
  $node = $this
    ->resetStorageCachesAndReloadNode();

  // Assert the target is ready.
  $this
    ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
    ->getTargetStatus($node, 'es'));
  $this
    ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
    ->getTargetStatus($node, 'de'));

  // Go to the bulk node management page and download them.
  $this
    ->goToContentBulkManagementForm();
  $this
    ->clickLink('ES');
  $node = $this
    ->resetStorageCachesAndReloadNode();

  // Assert the target is current.
  $this
    ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
    ->getTargetStatus($node, 'es'));
  $this
    ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
    ->getTargetStatus($node, 'de'));
}