public function LingotekContentTypeNotificationCallbackTest::testDocumentDeleted in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 4.0.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.0.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.1.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.2.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.3.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.4.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.5.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.6.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
- 3.8.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentDeleted()
Test that a notification with a document deleted is responded correctly.
File
- tests/
src/ Functional/ LingotekContentTypeNotificationCallbackTest.php, line 1451
Class
- LingotekContentTypeNotificationCallbackTest
- 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_type' => 'automatic',
]);
// Create Article node types. We use the form at least once to ensure that
// we don't break anything. E.g. see https://www.drupal.org/node/2645202.
$this
->drupalPostForm('/admin/structure/types/add', [
'type' => 'article',
'name' => 'Article',
], 'Save content 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_type');
// 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 Article deleted by user@example.com in the TMS.', $response['messages'][0]);
// Go to the bulk config management page.
$this
->goToConfigBulkManagementForm('node_type');
// Check the right class is added.
$this
->assertSourceStatus('EN', Lingotek::STATUS_DELETED);
$this
->assertTargetStatus('IT', Lingotek::STATUS_DELETED);
$this
->assertTargetStatus('ES', Lingotek::STATUS_DELETED);
// Check that the Target Status is Untracked
$node_type = NodeType::load('article');
$translation_service = \Drupal::service('lingotek.config_translation');
$this
->assertEmpty($translation_service
->getDocumentId($node_type));
$this
->assertEquals(Lingotek::STATUS_DELETED, $translation_service
->getTargetStatus($node_type, 'it'));
$this
->assertEquals(Lingotek::STATUS_DELETED, $translation_service
->getTargetStatus($node_type, 'es'));
$this
->assertEquals(Lingotek::STATUS_DELETED, $translation_service
->getSourceStatus($node_type));
}