View source
<?php
namespace Drupal\Tests\webform\Functional\Variant;
use Drupal\Core\Url;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\Entity\Webform;
class WebformVariantOperationsTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_variant_multiple',
];
public function testVariantOperations() {
$webform = Webform::load('test_variant_multiple');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_variant_multiple');
$this
->assertRaw('{X}');
$this
->assertRaw('{0}');
$this
->drupalGet('/webform/test_variant_multiple', [
'query' => [
'letter' => 'a',
'number' => '1',
],
]);
$this
->assertRaw('[A]');
$this
->assertRaw('[1]');
$prepopulate_options = [
'query' => [
'letter' => 'a',
],
];
$route_parameters = [
'webform' => $webform
->id(),
];
$route_options = [
'query' => [
'variant_id' => 'a',
],
];
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants');
$this
->assertLinkByHref($webform
->toUrl('canonical', $prepopulate_options)
->toString());
$this
->assertLinkByHref($webform
->toUrl('test-form', $prepopulate_options)
->toString());
$this
->assertLinkByHref(Url::fromRoute('entity.webform.variant.apply_form', $route_parameters, $route_options)
->toString());
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants/view');
$this
->assertOption('edit-variants-letter', 'a');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants/apply', $route_options);
$this
->assertOption('edit-variants-letter', 'a');
$this
->assertOptionSelected('edit-variants-letter', 'a');
$letter_a_variant_plugin = $webform
->getVariant('a');
$letter_a_variant_plugin
->disable();
$webform
->save();
$this
->drupalGet('/webform/test_variant_multiple', [
'query' => [
'letter' => 'a',
'number' => '1',
],
]);
$this
->assertNoRaw('[A]');
$this
->assertRaw('{X}');
$this
->assertRaw('[1]');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants');
$this
->assertNoLinkByHref($webform
->toUrl('canonical', $prepopulate_options)
->toString());
$this
->assertNoLinkByHref($webform
->toUrl('test-form', $prepopulate_options)
->toString());
$this
->assertLinkByHref(Url::fromRoute('entity.webform.variant.apply_form', $route_parameters, $route_options)
->toString());
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants/view');
$this
->assertNoOption('edit-variants-letter', 'a');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants/apply', $route_options);
$this
->assertOption('edit-variants-letter', 'a');
$this
->assertOptionSelected('edit-variants-letter', 'a');
$letter_a_variant_plugin
->enable();
$letter_element = $webform
->getElementDecoded('letter');
$letter_element['#prepopulate'] = FALSE;
$webform
->setElementProperties('letter', $letter_element);
$webform
->save();
$this
->drupalGet('/webform/test_variant_multiple', [
'query' => [
'letter' => 'a',
'number' => '1',
],
]);
$this
->assertNoRaw('[A]');
$this
->assertRaw('{X}');
$this
->drupalGet('/webform/test_variant_multiple', [
'query' => [
'_webform_variant[letter]' => 'a',
'number' => '1',
],
]);
$this
->assertRaw('[A]');
$this
->assertNoRaw('{X}');
$this
->assertRaw('[1]');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants');
$this
->assertRaw('>A<');
$this
->assertRaw('>B<');
$webform
->deleteElement('letter');
$webform
->save();
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants');
$this
->assertNoRaw('>A<');
$this
->assertNoRaw('>B<');
}
}