View source
<?php
namespace Drupal\Tests\webform\Functional\Variant;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformVariantApplyTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_variant_randomize',
'test_variant_multiple',
];
public function testVariantApply() {
$webform = $this
->loadWebform('test_variant_randomize');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform/manage/test_variant_randomize/variants/apply');
$this
->assertRaw('Apply variant to the <em class="placeholder">Test: Variant randomize</em> webform?');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/variants/apply');
$this
->assertRaw('>Apply the selected variants to the <em class="placeholder">Test: Variant multiple</em> webform?');
$this
->assertEqual(2, $webform
->getVariants()
->count());
$this
->drupalGet('/webform/test_variant_randomize');
$this
->assertRaw('{X}');
$this
->drupalGet('/webform/test_variant_randomize', [
'query' => [
'letter' => 'a',
],
]);
$this
->assertNoRaw('{X}');
$this
->assertRaw('[A]');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_randomize/variants/apply', [
'query' => [
'variant_id' => 'c',
],
]);
$this
->assertResponse(403);
$this
->drupalGet('/admin/structure/webform/manage/test_variant_randomize/variants/apply', [
'query' => [
'variant_id' => 'a',
],
]);
$this
->assertResponse(200);
$this
->drupalGet('/admin/structure/webform/manage/test_variant_randomize/variants/apply', [
'query' => [
'variant_id' => 'a',
],
]);
$this
->assertElementNotPresent('#edit-variants-letter');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_randomize/variants/apply');
$this
->assertElementPresent('#edit-variants-letter');
$edit = [
'delete' => 'none',
];
$this
->drupalPostForm('/admin/structure/webform/manage/test_variant_randomize/variants/apply', $edit, 'Apply', [
'query' => [
'variant_id' => 'a',
],
]);
$webform = $this
->reloadWebform('test_variant_randomize');
$this
->drupalGet('/webform/test_variant_randomize');
$this
->assertNoRaw('{X}');
$this
->assertRaw('[A]');
$this
->assertTrue($webform
->getVariants()
->has('a'));
$this
->assertEqual(2, $webform
->getVariants()
->count());
$variant = $webform
->getVariant('b');
$variant
->disable();
$webform
->save();
$edit = [
'delete' => 'none',
];
$this
->drupalPostForm('/admin/structure/webform/manage/test_variant_randomize/variants/apply', $edit, 'Apply', [
'query' => [
'variant_id' => 'b',
],
]);
$webform = $this
->reloadWebform('test_variant_randomize');
$this
->assertNoRaw('{X}');
$this
->assertRaw('[B]');
$this
->assertTrue($webform
->getVariants()
->has('b'));
$this
->assertEqual(2, $webform
->getVariants()
->count());
$edit = [
'delete' => 'selected',
];
$this
->drupalPostForm('/admin/structure/webform/manage/test_variant_randomize/variants/apply', $edit, 'Apply', [
'query' => [
'variant_id' => 'a',
],
]);
$webform = $this
->reloadWebform('test_variant_randomize');
$this
->drupalGet('/webform/test_variant_randomize');
$this
->assertNoRaw('{X}');
$this
->assertRaw('[A]');
$this
->assertFalse($webform
->getVariants()
->has('a'));
$this
->assertEqual(1, $webform
->getVariants()
->count());
$edit = [
'delete' => 'all',
];
$this
->drupalPostForm('/admin/structure/webform/manage/test_variant_randomize/variants/apply', $edit, 'Apply', [
'query' => [
'variant_id' => 'b',
],
]);
$webform = $this
->reloadWebform('test_variant_randomize');
$this
->drupalGet('/webform/test_variant_randomize');
$this
->assertNoRaw('{X}');
$this
->assertRaw('[B]');
$this
->assertFalse($webform
->getVariants()
->has('b'));
$this
->assertEqual(0, $webform
->getVariants()
->count());
}
}