WebformVariantRandomizeJavaScriptTest.php in Webform 8.5
File
tests/src/FunctionalJavascript/Variant/WebformVariantRandomizeJavaScriptTest.php
View source
<?php
namespace Drupal\Tests\webform\FunctionalJavascript\Variant;
use Drupal\Tests\webform\FunctionalJavascript\WebformWebDriverTestBase;
use Drupal\webform\Entity\Webform;
class WebformVariantRandomizeJavaScriptTest extends WebformWebDriverTestBase {
protected static $testWebforms = [
'test_variant_randomize',
];
protected function getSavedVariantId() {
$script = <<<JS
(function() {
var key = 'Drupal.webform.test_variant_randomize.variant.letter';
return window.sessionStorage.getItem(key);
})();
JS;
return $this
->getSession()
->evaluateScript($script);
}
public function testVariantRandomize() {
$webform = Webform::load('test_variant_randomize');
$this
->drupalGet('/webform/test_variant_randomize');
$saved_variant = $this
->getSavedVariantId();
$this
->assertContains($saved_variant, [
'a',
'b',
]);
$variant_plugin = $webform
->getVariant($saved_variant);
$variant_plugin
->disable();
$webform
->save();
$this
->drupalGet('/webform/test_variant_randomize');
$new_saved_variant = $this
->getSavedVariantId();
$this
->assertContains($new_saved_variant, [
'a',
'b',
]);
$this
->assertNotEqual($saved_variant, $new_saved_variant);
$variant_plugin = $webform
->getVariant($new_saved_variant);
$variant_plugin
->disable();
$webform
->save();
$this
->drupalGet('/webform/test_variant_randomize');
$null_variant = $this
->getSavedVariantId();
$this
->assertNull($null_variant);
}
}