You are here

public function LingotekFieldBodyTranslationTest::testLanguageDisabled in Lingotek Translation 8

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

File

src/Tests/LingotekFieldBodyTranslationTest.php, line 147

Class

LingotekFieldBodyTranslationTest
Tests translating a field.

Namespace

Drupal\lingotek\Tests

Code

public function testLanguageDisabled() {

  // 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.
  $this
    ->assertLinkByHref('/admin/lingotek/config/request/node_fields/node.article.body/it_IT');
  $this
    ->assertLinkByHref('/admin/lingotek/config/request/node_fields/node.article.body/es_MX');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/article/fields/node.article.body/translate/it/add');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/article/fields/node.article.body/translate/es/add');

  /** @var 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.
  $this
    ->assertNoLinkByHref('/admin/lingotek/config/request/node_fields/node.article.body/it_IT');
  $this
    ->assertLinkByHref('/admin/lingotek/config/request/node_fields/node.article.body/es_MX');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/article/fields/node.article.body/translate/it/add');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/article/fields/node.article.body/translate/es/add');
}