You are here

public function LingotekNodeTranslationTest::testLanguageDisabled in Lingotek Translation 8

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

File

src/Tests/LingotekNodeTranslationTest.php, line 243

Class

LingotekNodeTranslationTest
Tests translating a node.

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);

  // Create a node.
  $edit = array();
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));
  $this->node = Node::load(1);

  // Check that only the configured fields have been uploaded.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertUploadedDataFieldCount($data, 2);
  $this
    ->assertTrue(isset($data['title'][0]['value']));
  $this
    ->assertEqual(1, count($data['body'][0]));
  $this
    ->assertTrue(isset($data['body'][0]['value']));
  $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.');

  // Check that the translate tab is in the node.
  $this
    ->drupalGet('node/1');
  $this
    ->clickLink('Translate');

  // The document should have been automatically uploaded, so let's check
  // the upload status.
  $this
    ->clickLink('Check Upload Status');
  $this
    ->assertText('The import for node Llamas are cool is complete.');

  // There are two links for requesting translations, or we can add them
  // manually.
  $this
    ->assertLinkByHref('/admin/lingotek/entity/add_target/dummy-document-hash-id/it_IT');
  $this
    ->assertLinkByHref('/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX');
  $this
    ->assertLinkByHref('/node/1/translations/add/en/it');
  $this
    ->assertLinkByHref('/node/1/translations/add/en/es');

  /** @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('node/1/translations');

  // Italian is not present anymore, but still can add a translation.
  $this
    ->assertNoLinkByHref('/admin/lingotek/entity/add_target/dummy-document-hash-id/it_IT');
  $this
    ->assertLinkByHref('/admin/lingotek/entity/add_target/dummy-document-hash-id/es_MX');
  $this
    ->assertLinkByHref('/node/1/translations/add/en/it');
  $this
    ->assertLinkByHref('/node/1/translations/add/en/es');
}