public function LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading in Lingotek Translation 3.6.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 4.0.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.0.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.1.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.2.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.3.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.4.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.5.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.7.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
- 3.8.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testDocumentCancelledAfterUploading()
Tests that a document_cancelled callback is handled after document upload.
File
- tests/
src/ Functional/ LingotekNodeNotificationCallbackTest.php, line 2109
Class
- LingotekNodeNotificationCallbackTest
- Tests translating a node using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testDocumentCancelledAfterUploading() {
// 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
->assertIdentical($content_translation_service
->getDocumentId($node), 'dummy-document-hash-id');
// 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([
'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'));
// Simulate the notification of document_cancelled document.
$url = Url::fromRoute('lingotek.notify', [], [
'query' => [
'project_id' => 'test_project',
'document_id' => 'dummy-document-hash-id',
'type' => 'document_cancelled',
],
])
->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['messages'][0], 'Document Llamas are cool cancelled in TMS.');
$this
->goToContentBulkManagementForm();
$node = $this
->resetStorageCachesAndReloadNode();
$this
->assertNull($content_translation_service
->getDocumentId($node));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $content_translation_service
->getSourceStatus($node));
$this
->assertIdentical(Lingotek::STATUS_CANCELLED, $content_translation_service
->getTargetStatus($node, 'es'));
}