public function LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested in Lingotek Translation 3.0.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 4.0.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.1.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.2.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.3.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.4.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.5.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.6.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.7.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
- 3.8.x tests/src/Functional/LingotekFieldBodyNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyNotificationCallbackTest::testDisabledLanguagesAreNotRequested()
Tests that there are no automatic requests for disabled languages.
File
- tests/
src/ Functional/ LingotekFieldBodyNotificationCallbackTest.php, line 606
Class
- LingotekFieldBodyNotificationCallbackTest
- Tests translating a content type using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testDisabledLanguagesAreNotRequested() {
// Add a language.
$italian = ConfigurableLanguage::createFromLangcode('it');
$italian
->save();
// Enable translation for the current entity type and ensure the change is
// picked up.
$this
->saveLingotekConfigTranslationSettings([
'node_fields' => 'automatic',
]);
$type1 = \Drupal::entityTypeManager()
->getStorage('node_type')
->create([
'type' => 'article',
'name' => 'Article',
]);
$type1
->save();
node_add_body_field($type1);
$type2 = \Drupal::entityTypeManager()
->getStorage('node_type')
->create([
'type' => 'page',
'name' => 'Page',
]);
$type2
->save();
node_add_body_field($type2);
// Login as admin.
$this
->drupalLogin($this->rootUser);
/** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $config_translation_service */
$config_translation_service = \Drupal::service('lingotek.config_translation');
// Assert the content is importing.
/** @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');
$this
->assertIdentical(Lingotek::STATUS_IMPORTING, $config_translation_service
->getSourceStatus($entity));
// Go to the bulk config management page.
$this
->goToConfigBulkManagementForm('node_fields');
// 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
->assertIdentical([
'it',
'es',
], $response['result']['request_translations'], 'Spanish and Italian languages have been requested after notification automatically.');
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$lingotek_config
->disableLanguage($italian);
// Test with another content.
/** @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.page.body');
// Simulate the notification of content successfully uploaded.
$url = Url::fromRoute('lingotek.notify', [], [
'query' => [
'project_id' => 'test_project',
'document_id' => 'dummy-document-hash-id-1',
'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
->assertIdentical([
'es',
], $response['result']['request_translations'], 'Italian language has not been requested after notification automatically because it is disabled.');
}