View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\contact\Entity\ContactForm;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
class LingotekContactMessageBodyTranslationTest extends LingotekTestBase {
public static $modules = [
'block',
'node',
'field_ui',
'contact',
];
protected $node;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('page_title_block');
ContactForm::create([
'id' => 'contact_message',
'label' => 'Test contact form',
])
->save();
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_test',
'entity_type' => 'contact_message',
'type' => 'text',
]);
$fieldStorage
->save();
FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => 'contact_message',
])
->save();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'contact_message_field');
}
public function testFieldTranslation() {
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/config/regional/config-translation');
$this
->drupalGet('/admin/config/regional/config-translation/contact_message_fields');
$this
->clickLink(t('Translate'));
$this
->clickLink(t('Upload'));
$this
->assertText(t('field_test uploaded successfully'));
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertTrue(array_key_exists('label', $data['field.field.contact_message.contact_message.field_test']));
$this
->assertTrue(array_key_exists('description', $data['field.field.contact_message.contact_message.field_test']));
$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('field_test 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'));
$basepath = \Drupal::request()
->getBasePath();
$this
->assertLinkByHref($basepath . '/admin/structure/contact/manage/contact_message/fields/contact_message.contact_message.field_test/translate/es/edit');
}
}