View source
<?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
class LingotekConfigObjectTranslationPreSaveHookTest extends LingotekTestBase {
public static $modules = [
'node',
'user',
'lingotek_test_config_object',
];
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('es')
->setThirdPartySetting('lingotek', 'locale', 'es_MX')
->save();
\Drupal::state()
->set('lingotek.uploaded_content_type', 'lingotek_test_config_object');
}
public function testConfigObjectTranslation() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/config/lingotek/lingotek_test_config_object');
$edit = [
'property_1' => 'Llamas feed description',
'property_2' => 'Llamas feed description',
'property_3' => 'Llamas feed description',
'property_4' => 'Llamas feed description',
'property_5' => 'Llamas feed description',
'property_6' => 'Llamas feed description',
];
$this
->submitForm($edit, 'Save configuration');
$this
->goToConfigBulkManagementForm();
$label = "Lingotek Test Config Object";
$enLink = $this
->xpath("//td[contains(text(), :label)]/following-sibling::td//a", [
':label' => $label,
]);
$enLink[0]
->click();
$data = json_decode(\Drupal::state()
->get('lingotek.uploaded_content', '[]'), TRUE);
$this
->assertFalse(isset($data['lingotek_test_config_object.settings']['property_1']));
$this
->assertFalse(isset($data['lingotek_test_config_object.settings']['property_2']));
$this
->assertEqual($data['lingotek_test_config_object.settings']['property_3'], 'Cats feed description');
$this
->assertEqual($data['lingotek_test_config_object.settings']['property_4'], 'Llamas feed description');
$this
->assertEqual($data['lingotek_test_config_object.settings']['property_5'], 'Cats feed description');
$this
->assertEqual($data['lingotek_test_config_object.settings']['property_6'], 'Llamas feed description');
$this
->clickLink('ES');
$this
->clickLink('ES');
$this
->clickLink('ES');
$this
->drupalGet("/admin/config/lingotek/lingotek_test_config_object/translate/es/edit");
$assert_session
->fieldNotExists("translation[config_names][lingotek_test_config_object.settings][property_1]");
$assert_session
->fieldNotExists("translation[config_names][lingotek_test_config_object.settings][property_2]");
$assert_session
->fieldValueEquals("translation[config_names][lingotek_test_config_object.settings][property_3]", 'Perros alimentados descripción');
$assert_session
->fieldValueEquals("translation[config_names][lingotek_test_config_object.settings][property_4]", 'Gatos alimentados descripción');
$assert_session
->fieldValueEquals("translation[config_names][lingotek_test_config_object.settings][property_5]", 'Perros alimentados descripción');
$assert_session
->fieldValueEquals("translation[config_names][lingotek_test_config_object.settings][property_6]", 'Gatos alimentados descripción');
}
}