You are here

public function LingotekFieldBodyTranslationTest::testLanguageDisabled in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  2. 4.0.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  3. 3.0.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  4. 3.1.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  5. 3.2.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  6. 3.3.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  7. 3.5.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  8. 3.6.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  9. 3.7.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()
  10. 3.8.x tests/src/Functional/LingotekFieldBodyTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldBodyTranslationTest::testLanguageDisabled()

Tests that no translation can be requested if the language is disabled.

File

tests/src/Functional/LingotekFieldBodyTranslationTest.php, line 144

Class

LingotekFieldBodyTranslationTest
Tests translating a field.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testLanguageDisabled() {
  $assert_session = $this
    ->assertSession();

  // Add a language.
  $italian = ConfigurableLanguage::createFromLangcode('it')
    ->setThirdPartySetting('lingotek', 'locale', 'it_IT');
  $italian
    ->save();

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet('/admin/config/regional/config-translation');
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'));
  $this
    ->clickLink(t('Upload'));
  $this
    ->assertText(t('Body uploaded successfully'));

  // Check that only the translatable fields have been uploaded.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->verbose(var_export($data, TRUE));
  $this
    ->assertEqual(2, count($data['field.field.node.article.body']));
  $this
    ->assertTrue(array_key_exists('label', $data['field.field.node.article.body']));

  // Cannot use isset, the key exists but we are not providing values, so NULL.
  $this
    ->assertTrue(array_key_exists('description', $data['field.field.node.article.body']));
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // Check that the profile used was the right one.
  $used_profile = \Drupal::state()
    ->get('lingotek.used_profile');
  $this
    ->assertIdentical('automatic', $used_profile, 'The automatic profile was used.');

  // The document should have been automatically uploaded, so let's check
  // the upload status.
  $this
    ->clickLink('Check upload status');
  $this
    ->assertText('Body status checked successfully');

  // There are two links for requesting translations, or we can add them
  // manually.
  $assert_session
    ->linkByHrefExists('/admin/lingotek/config/request/node_fields/node.article.body/it_IT');
  $assert_session
    ->linkByHrefExists('/admin/lingotek/config/request/node_fields/node.article.body/es_MX');
  $assert_session
    ->linkByHrefExists('/admin/structure/types/manage/article/fields/node.article.body/translate/it/add');
  $assert_session
    ->linkByHrefExists('/admin/structure/types/manage/article/fields/node.article.body/translate/es/add');

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
  $lingotek_config = \Drupal::service('lingotek.configuration');
  $lingotek_config
    ->disableLanguage($italian);

  // Check that the translate tab is in the node.
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'));

  // Italian is not present anymore, but still can add a translation.
  $assert_session
    ->linkByHrefNotExists('/admin/lingotek/config/request/node_fields/node.article.body/it_IT');
  $assert_session
    ->linkByHrefExists('/admin/lingotek/config/request/node_fields/node.article.body/es_MX');
  $assert_session
    ->linkByHrefExists('/admin/structure/types/manage/article/fields/node.article.body/translate/it/add');
  $assert_session
    ->linkByHrefExists('/admin/structure/types/manage/article/fields/node.article.body/translate/es/add');
}