public function LingotekFieldBodyNotificationCallbackTest::testTargetDeleted in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 4.0.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.0.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.1.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.2.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.3.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.4.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.5.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.6.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
- 3.8.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testTargetDeleted()
Test that a notification with a target deleted is responded correctly.
File
- tests/
src/ Functional/ LingotekFieldBodyNotificationCallbackTest.php, line 733
Class
- LingotekFieldBodyNotificationCallbackTest
- Tests translating a content type using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testTargetDeleted() {
// 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
->assertEqual(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',
'locale_code' => 'it-IT',
'locale' => 'it_IT',
'deleted_by_user_login' => 'user@example.com',
'complete' => 'true',
'status' => 'COMPLETE',
'type' => 'target_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
->assertEquals('Target it_IT for entity Body deleted by user@example.com', $response['messages'][0]);
// Go to the bulk config management page.
$this
->goToConfigBulkManagementForm('node_fields');
// Check the right class is added.
$this
->assertTargetStatus('IT', Lingotek::STATUS_DELETED);
/** @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
->assertEquals(Lingotek::STATUS_DELETED, $translation_service
->getTargetStatus($entity, 'it'));
}