public function LingotekFieldOptionsTranslationTest::testFieldTranslation in Lingotek Translation 3.6.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 4.0.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.0.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.1.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.2.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.3.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.4.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.5.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.7.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
- 3.8.x tests/src/Functional/LingotekFieldOptionsTranslationTest.php \Drupal\Tests\lingotek\Functional\LingotekFieldOptionsTranslationTest::testFieldTranslation()
Tests that a field can be translated.
File
- tests/
src/ Functional/ LingotekFieldOptionsTranslationTest.php, line 56
Class
- LingotekFieldOptionsTranslationTest
- Tests translating a options field.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testFieldTranslation() {
$assert_session = $this
->assertSession();
// 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'), 1);
$this
->clickLink(t('Upload'));
$this
->assertText(t('Options 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.field_options']));
$this
->assertTrue(array_key_exists('description', $data['field.field.node.article.field_options']));
$this
->assertTrue(array_key_exists('settings.allowed_values.0.label', $data['field.storage.node.field_options']));
$this
->assertTrue(array_key_exists('settings.allowed_values.1.label', $data['field.storage.node.field_options']));
$this
->assertEqual('Options', $data['field.field.node.article.field_options']['label']);
$this
->assertEqual('Zero', $data['field.storage.node.field_options']['settings.allowed_values.0.label']);
$this
->assertEqual('One', $data['field.storage.node.field_options']['settings.allowed_values.1.label']);
// 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('Options 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();
$assert_session
->linkByHrefExists($basepath . '/admin/structure/types/manage/article/fields/node.article.field_options/translate/es/edit');
// Check that the values are correct.
$this
->clickLink('Edit', 1);
$this
->assertFieldByName('translation[config_names][field.field.node.article.field_options][label]', 'Opciones');
$this
->assertFieldByName('translation[config_names][field.field.node.article.field_options][description]', 'Descripción del campo');
$this
->assertFieldByName('translation[config_names][field.storage.node.field_options][settings][allowed_values][0][label]', 'Cero');
$this
->assertFieldByName('translation[config_names][field.storage.node.field_options][settings][allowed_values][1][label]', 'Uno');
}