You are here

public function LingotekNodeNotificationCallbackTest::testTargetDeleted in Lingotek Translation 3.8.x

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

Test that a notification with a target deleted is responded correctly.

File

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

Class

LingotekNodeNotificationCallbackTest
Tests translating a node using the notification callback.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testTargetDeleted() {

  // Add an additional language.
  ConfigurableLanguage::createFromLangcode('it')
    ->save();

  // 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);

  // 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,
  ]);

  // 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
    ->assertTrue($response['result']['download'], 'Spanish language has been downloaded after notification automatically.');
  $this
    ->assertEquals('Document downloaded.', $response['messages'][0]);

  // 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' => 'it-IT',
      'locale' => 'it_IT',
      '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
    ->assertTrue($response['result']['download'], 'Italian language has been downloaded after notification automatically.');
  $this
    ->assertEquals('Document downloaded.', $response['messages'][0]);

  // Go to the bulk node management page.
  $this
    ->goToContentBulkManagementForm();

  // All the links are current.
  $current_links = $this
    ->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-current')]");
  $this
    ->assertEqual(count($current_links), 2, 'Translation "es_ES" and "it_IT" are current.');

  // Simulate the notification of target deleted.
  $url = Url::fromRoute('lingotek.notify', [], [
    'query' => [
      'project_id' => 'test_project',
      'document_id' => 'dummy-document-hash-id',
      'locale_code' => 'it-IT',
      'locale' => 'it_IT',
      'deleted_by_user_login' => 'user@example.com',
      'complete' => 'true',
      'status' => 'COMPLETE',
      'type' => 'target_deleted',
      'progress' => '100',
    ],
  ])
    ->setAbsolute()
    ->toString();
  $request = $this->client
    ->post($url, [
    'cookies' => $this->cookies,
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
    ],
    'http_errors' => FALSE,
  ]);
  $this
    ->assertEquals(Response::HTTP_OK, $request
    ->getStatusCode());
  $response = json_decode($request
    ->getBody(), TRUE);
  $this
    ->assertEquals('Target it_IT for entity Llamas are cool deleted by user@example.com', $response['messages'][0]);

  // Go to the bulk node management page.
  $this
    ->goToContentBulkManagementForm();

  // Check the right class is added.
  $this
    ->assertTargetStatus('IT', Lingotek::STATUS_DELETED);

  // Check that the Target Status is Untracked
  $node = Node::load(1);
  $content_translation_service = \Drupal::service('lingotek.content_translation');
  $this
    ->assertEquals(Lingotek::STATUS_DELETED, $content_translation_service
    ->getTargetStatus($node, 'it'));
}