public function LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 4.0.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.0.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.1.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.2.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.3.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.4.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.5.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.6.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
- 3.8.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testIncompletePhaseNotificationWithNoInterimNodeTranslation()
Tests that a node reacts to incomplete target and phase notifications and does not download interim translations based on the settings.
File
- tests/src/ Functional/ LingotekNodeNotificationCallbackTest.php, line 289 
Class
- LingotekNodeNotificationCallbackTest
- Tests translating a node using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testIncompletePhaseNotificationWithNoInterimNodeTranslation() {
  // 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]'] = 'automatic';
  $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();
  $this
    ->clickLink('ES');
  // Ensure we won't get a completed document because there are phases pending.
  \Drupal::state()
    ->set('lingotek.document_completion', 40);
  // Simulate the notification of content ready to download.
  $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' => 'phase',
      'progress' => '50',
    ],
  ])
    ->setAbsolute()
    ->toString();
  $request = $this->client
    ->post($url, [
    'cookies' => $this->cookies,
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
    ],
    'http_errors' => FALSE,
  ]);
  $response = (string) $request
    ->getBody();
  $this
    ->assertSame(Response::HTTP_ACCEPTED, $request
    ->getStatusCode());
  $this
    ->assertSame('It works, but nothing to look here.', $response);
  $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'));
  // 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' => '50',
    ],
  ])
    ->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'], 'Spanish language has not been downloaded after notification automatically, as it is interim.');
  $this
    ->assertEqual($response['messages'][0], 'Interim downloads are disabled, so no download for target es_ES happened in document dummy-document-hash-id.', 'Spanish language has not been downloaded after notification automatically, as it is interim.');
  $node = $this
    ->resetStorageCachesAndReloadNode();
  // Assert the target is pending.
  $this
    ->assertIdentical(Lingotek::STATUS_PENDING, $content_translation_service
    ->getTargetStatus($node, 'es'));
}