You are here

public function LingotekSystemSiteTranslationTest::testSystemSiteTranslation in Lingotek Translation 3.7.x

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

Tests that a node can be translated.

1 call to LingotekSystemSiteTranslationTest::testSystemSiteTranslation()
LingotekSystemSiteTranslationTest::testEditedSystemConfigTranslation in tests/src/Functional/LingotekSystemSiteTranslationTest.php
Tests that a config can be translated after edited.

File

tests/src/Functional/LingotekSystemSiteTranslationTest.php, line 42

Class

LingotekSystemSiteTranslationTest
Tests translating a config object.

Namespace

Drupal\Tests\lingotek\Functional

Code

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

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

  // Ensure it has the expected timestamp for upload
  $timestamp = \Drupal::time()
    ->getRequestTime();
  foreach (LingotekConfigMetadata::loadMultiple() as $metadata) {
    $this
      ->assertEquals($timestamp, $metadata
      ->getLastUploaded());
    $this
      ->assertEmpty($metadata
      ->getLastUpdated());
  }

  // Check that the url used was the right one.
  $uploaded_url = \Drupal::state()
    ->get('lingotek.uploaded_url');
  $this
    ->assertIdentical(NULL, $uploaded_url, 'There was not associated url.');

  // Check that the profile used was the right one.
  $used_profile = \Drupal::state()
    ->get('lingotek.used_profile');
  $this
    ->assertIdentical('manual', $used_profile, 'The manual profile was used.');
  $this
    ->clickLink(t('Check upload status'));
  $this
    ->assertText(t('System information status checked successfully'));

  // Request translation.
  $link = $this
    ->xpath('//a[normalize-space()="Request translation" and contains(@href,"es_AR")]');
  $link[0]
    ->click();
  $this
    ->assertIdentical('es_AR', \Drupal::state()
    ->get('lingotek.added_target_locale'));
  $this
    ->assertText(t('Translation to es_AR requested successfully'));

  // Check translation status.
  $this
    ->clickLink(t('Check Download'));
  $this
    ->assertIdentical('es_AR', \Drupal::state()
    ->get('lingotek.checked_target_locale'));
  $this
    ->assertText(t('Translation to es_AR checked successfully'));
  $this
    ->clickLink('Download');
  $this
    ->assertIdentical('es_AR', \Drupal::state()
    ->get('lingotek.downloaded_locale'));
  $this
    ->assertText(t('Translation to es_AR downloaded successfully'));

  // Check that the edit link is there.
  $basepath = \Drupal::request()
    ->getBasePath();
  $assert_session
    ->linkByHrefExists($basepath . '/admin/config/system/site-information/translate/es/edit');

  // Edit the Spanish translation.
  $this
    ->clickLink('Edit', 1);
  $this
    ->assertFieldByName('translation[config_names][system.site][slogan]', 'Las llamas son muy chulas');

  // The content is translated and published.
  $this
    ->drupalGet('/es/');
  $this
    ->assertText('Las llamas son muy chulas');
}