You are here

public function LingotekSystemSiteTranslationTest::testLanguageDisabled in Lingotek Translation 8

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

File

src/Tests/LingotekSystemSiteTranslationTest.php, line 134

Class

LingotekSystemSiteTranslationTest
Tests translating a config object.

Namespace

Drupal\lingotek\Tests

Code

public function testLanguageDisabled() {

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

  // Check that the translate tab is in the site information.
  $this
    ->drupalGet('/admin/config/system/site-information');
  $this
    ->clickLink('Translate system information');
  $this
    ->clickLink(t('Upload'));
  $this
    ->assertText(t('System information uploaded successfully'));

  // Check that only the configured fields have been uploaded.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertEqual(1, count($data));
  $this
    ->assertTrue(array_key_exists('system.site', $data));
  $this
    ->assertEqual(2, count($data['system.site']));
  $this
    ->assertTrue(array_key_exists('name', $data['system.site']));
  $this
    ->assertTrue(array_key_exists('slogan', $data['system.site']));
  $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(t('Check upload status'));
  $this
    ->assertText(t('System information status checked successfully'));

  // There are two links for requesting translations, or we can add them
  // manually.
  $this
    ->assertLinkByHref('/admin/config/system/site-information/translate/it/add');
  $this
    ->assertLinkByHref('/admin/config/system/site-information/translate/es/add');
  $this
    ->assertLinkByHref('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/it_IT');
  $this
    ->assertLinkByHref('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/es_AR');

  /** @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/system/site-information');
  $this
    ->clickLink('Translate system information');

  // Italian is not present anymore, but still can add a translation.
  $this
    ->assertLinkByHref('/admin/config/system/site-information/translate/it/add');
  $this
    ->assertLinkByHref('/admin/config/system/site-information/translate/es/add');
  $this
    ->assertNoLinkByHref('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/it_IT');
  $this
    ->assertLinkByHref('/admin/lingotek/config/request/system.site_information_settings/system.site_information_settings/es_AR');
}