public function LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation 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::testAutomatedNotificationNodeTranslation()
- 4.0.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.0.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.1.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.2.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.3.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.4.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.5.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.7.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
- 3.8.x tests/src/Functional/LingotekNodeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekNodeNotificationCallbackTest::testAutomatedNotificationNodeTranslation()
Tests that a node can be translated using the links on the management page.
File
- tests/
src/ Functional/ LingotekNodeNotificationCallbackTest.php, line 90
Class
- LingotekNodeNotificationCallbackTest
- Tests translating a node using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testAutomatedNotificationNodeTranslation() {
// 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();
// 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'));
$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
->assertTrue($response['result']['download'], 'Spanish language has been downloaded after notification automatically.');
$this
->goToContentBulkManagementForm();
$node = $this
->resetStorageCachesAndReloadNode();
// Assert the target is ready.
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
->getTargetStatus($node, 'es'));
$this
->goToContentBulkManagementForm();
}