You are here

public function LingotekFieldBodyTranslationTest::testFieldTranslation in Lingotek Translation 8

Tests that a node can be translated.

1 call to LingotekFieldBodyTranslationTest::testFieldTranslation()
LingotekFieldBodyTranslationTest::testEditedFieldBodyTranslation in src/Tests/LingotekFieldBodyTranslationTest.php
Tests that a config can be translated after edited.

File

src/Tests/LingotekFieldBodyTranslationTest.php, line 63

Class

LingotekFieldBodyTranslationTest
Tests translating a field.

Namespace

Drupal\lingotek\Tests

Code

public function testFieldTranslation() {

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

  // 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.');
  $this
    ->clickLink(t('Check upload status'));
  $this
    ->assertText('Body status checked successfully');
  $this
    ->clickLink(t('Request translation'));
  $this
    ->assertText(t('Translation to es_MX requested successfully'));
  $this
    ->assertIdentical('es_MX', \Drupal::state()
    ->get('lingotek.added_target_locale'));
  $this
    ->clickLink(t('Check Download'));
  $this
    ->assertText(t('Translation to es_MX status checked successfully'));
  $this
    ->clickLink('Download');
  $this
    ->assertText(t('Translation to es_MX downloaded successfully'));

  // Check that the edit link is there.
  $basepath = \Drupal::request()
    ->getBasePath();
  $this
    ->assertLinkByHref($basepath . '/admin/structure/types/manage/article/fields/node.article.body/translate/es/edit');

  // Check that the values are correct.
  $this
    ->clickLink('Edit', 1);
  $this
    ->assertFieldByName('translation[config_names][field.field.node.article.body][label]', 'Cuerpo');
  $this
    ->assertFieldByName('translation[config_names][field.field.node.article.body][description]', 'Cuerpo del contenido');
}