You are here

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

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

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

File

tests/src/Functional/LingotekNodeTranslationTest.php, line 443

Class

LingotekNodeTranslationTest
Tests translating a node.

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

  // Create a node.
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $this
    ->saveAndPublishNodeForm($edit);
  $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, 3);
  $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
    ->assertLingotekRequestTranslationLink('it_IT');
  $this
    ->assertLingotekRequestTranslationLink('es_MX');
  $assert_session
    ->linkByHrefExists('/node/1/translations/add/en/it');
  $assert_session
    ->linkByHrefExists('/node/1/translations/add/en/es');

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

  // Italian is not present anymore, but still can add a translation.
  $this
    ->assertNoLingotekRequestTranslationLink('it_IT');
  $this
    ->assertLingotekRequestTranslationLink('es_MX');
  $assert_session
    ->linkByHrefExists('/node/1/translations/add/en/it');
  $assert_session
    ->linkByHrefExists('/node/1/translations/add/en/es');
}