public function LingotekNodeNotificationCallbackTest::testPhaseNotificationNodeTranslation in Lingotek Translation 8
Tests that a node reacts to a phase notification using the links on the management page.
File
- src/
Tests/ LingotekNodeNotificationCallbackTest.php, line 146
Class
- LingotekNodeNotificationCallbackTest
- Tests translating a node using the notification callback.
Namespace
Drupal\lingotek\TestsCode
public function testPhaseNotificationNodeTranslation() {
// Login as admin.
$this
->drupalLogin($this->rootUser);
// Create a node.
$edit = array();
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_profile'] = 'automatic';
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
/** @var NodeInterface $node */
$node = Node::load(1);
/** @var 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();
// Ensure we won't get a completed document because there are phases pending.
\Drupal::state()
->set('lingotek.document_completion', FALSE);
// Simulate the notification of content successfully uploaded.
$request = $this
->drupalPost(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' => '100',
],
]), 'application/json', []);
$response = json_decode($request, true);
$this
->assertTrue($response['result']['download'], 'Spanish language has been downloaded after notification automatically.');
$this
->goToContentBulkManagementForm();
$node_storage = $this->container
->get('entity.manager')
->getStorage('node');
// The node cache needs to be reset before reload.
$node_storage
->resetCache(array(
1,
));
$node = $node_storage
->load(1);
// Assert the content is imported.
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
->getSourceStatus($node));
// Assert the target is intermediate.
$this
->assertIdentical(Lingotek::STATUS_INTERMEDIATE, $content_translation_service
->getTargetStatus($node, 'es'));
// Assert a translation has been downloaded.
$this
->drupalGet('node/1/translations');
$this
->assertLink('Las llamas son chulas');
// There are no phases pending anymore.
\Drupal::state()
->set('lingotek.document_completion', TRUE);
$this
->goToContentBulkManagementForm();
// Simulate the notification of content successfully translated.
$request = $this
->drupalPost(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',
],
]), 'application/json', []);
$response = json_decode($request, true);
$this
->verbose($request);
$this
->assertTrue($response['result']['download'], 'Spanish language has been downloaded after notification automatically.');
$this
->goToContentBulkManagementForm();
$node_storage = $this->container
->get('entity.manager')
->getStorage('node');
// The node cache needs to be reset before reload.
$node_storage
->resetCache(array(
1,
));
$node = $node_storage
->load(1);
// Assert the target is ready.
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
->getTargetStatus($node, 'es'));
$this
->goToContentBulkManagementForm();
}