public function LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 4.0.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.0.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.1.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.2.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.3.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.4.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.6.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.7.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
- 3.8.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDocumentDeleted()
Test that a notification with a document deleted is responded correctly.
File
- tests/
src/ Functional/ LingotekFieldBodyNotificationCallbackTest.php, line 870
Class
- LingotekFieldBodyNotificationCallbackTest
- Tests translating a content type using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testDocumentDeleted() {
// Add an additional language.
ConfigurableLanguage::createFromLangcode('it')
->save();
// Enable translation for the current entity type and ensure the change is
// picked up.
$this
->saveLingotekConfigTranslationSettings([
'node_fields' => 'automatic',
]);
// Create Article node types.
$type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
node_add_body_field($type);
// 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 config management page.
$this
->goToConfigBulkManagementForm('node_fields');
// All the links are current.
$current_links = $this
->xpath("//a[contains(@class,'language-icon') and contains(@class, 'target-current')]");
$this
->assertEquals(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',
'deleted_by_user_login' => 'user@example.com',
'complete' => 'true',
'type' => 'document_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
->assertSame('Document for entity Body deleted by user@example.com in the TMS.', $response['messages'][0]);
// Go to the bulk config management page.
$this
->goToConfigBulkManagementForm('node_fields');
// Check the right class is added.
$this
->assertSourceStatus('EN', Lingotek::STATUS_UNTRACKED);
$this
->assertTargetStatus('IT', Lingotek::STATUS_UNTRACKED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_UNTRACKED);
// Check that the Target Status is Untracked
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $field_storage */
$field_storage = $this->container
->get('entity_type.manager')
->getStorage('field_config');
// The node cache needs to be reset before reload.
$field_storage
->resetCache();
$entity = $field_storage
->load('node.article.body');
$translation_service = \Drupal::service('lingotek.config_translation');
$this
->assertEmpty($translation_service
->getDocumentId($entity));
$this
->assertEquals(Lingotek::STATUS_UNTRACKED, $translation_service
->getTargetStatus($entity, 'it'));
$this
->assertEquals(Lingotek::STATUS_UNTRACKED, $translation_service
->getTargetStatus($entity, 'es'));
$this
->assertEquals(Lingotek::STATUS_UNTRACKED, $translation_service
->getSourceStatus($entity));
}