public function WebformEntityTranslationTest::testTranslateVariants in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/Functional/WebformEntityTranslationTest.php \Drupal\Tests\webform\Functional\WebformEntityTranslationTest::testTranslateVariants()
Tests webform translate variants.
File
- tests/
src/ Functional/ WebformEntityTranslationTest.php, line 302
Class
- WebformEntityTranslationTest
- Tests for webform translation.
Namespace
Drupal\Tests\webform\FunctionalCode
public function testTranslateVariants() {
// Check English webform.
$this
->drupalGet('/webform/test_translation');
$this
->assertRaw('<label for="edit-textfield">Text field</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Check English webform with test variant.
$this
->drupalGet('/webform/test_translation', [
'query' => [
'variant' => 'test',
],
]);
$this
->assertRaw('<label for="edit-textfield">Text field - Variant</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Check Spanish webform.
$this
->drupalGet('/es/webform/test_translation');
$this
->assertRaw('<label for="edit-textfield">Campo de texto</label>');
$this
->assertRaw('<label for="edit-select-options">Seleccione (opciones)</label>');
// Check Spanish webform with test variant.
$this
->drupalGet('/es/webform/test_translation', [
'query' => [
'variant' => 'test',
],
]);
$this
->assertRaw('<label for="edit-textfield">Campo de texto - Variante</label>');
$this
->assertRaw('<label for="edit-select-options">Seleccione (opciones)</label>');
// Check French (not translated) webform.
$this
->drupalGet('/fr/webform/test_translation');
$this
->assertRaw('<label for="edit-textfield">Text field</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Check French (not translated) webform with test variant.
$this
->drupalGet('/fr/webform/test_translation', [
'query' => [
'variant' => 'test',
],
]);
$this
->assertRaw('<label for="edit-textfield">Text field - Variant</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Remove variant element and variants.
/** @var \Drupal\webform\WebformInterface $webform */
$webform = Webform::load('test_translation');
$variants = $webform
->getVariants();
foreach ($variants as $variant) {
$webform
->deleteWebformVariant($variant);
}
$webform
->deleteElement('variant');
$webform
->save();
// Check English webform.
$this
->drupalGet('/webform/test_translation');
$this
->assertRaw('<label for="edit-textfield">Text field</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Check English webform with test variant.
$this
->drupalGet('/webform/test_translation', [
'query' => [
'variant' => 'test',
],
]);
$this
->assertRaw('<label for="edit-textfield">Text field</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Check Spanish webform.
$this
->drupalGet('/es/webform/test_translation');
$this
->assertRaw('<label for="edit-textfield">Campo de texto</label>');
$this
->assertRaw('<label for="edit-select-options">Seleccione (opciones)</label>');
// Check Spanish webform with test variant.
$this
->drupalGet('/es/webform/test_translation', [
'query' => [
'variant' => 'test',
],
]);
$this
->assertRaw('<label for="edit-textfield">Campo de texto</label>');
$this
->assertRaw('<label for="edit-select-options">Seleccione (opciones)</label>');
// Check French (not translated) webform.
$this
->drupalGet('/fr/webform/test_translation');
$this
->assertRaw('<label for="edit-textfield">Text field</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
// Check French (not translated) webform with test variant.
$this
->drupalGet('/fr/webform/test_translation', [
'query' => [
'variant' => 'test',
],
]);
$this
->assertRaw('<label for="edit-textfield">Text field</label>');
$this
->assertRaw('<label for="edit-select-options">Select (options)</label>');
}