public function WebformVariantRandomizeJavaScriptTest::testVariantRandomize in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/FunctionalJavascript/Variant/WebformVariantRandomizeJavaScriptTest.php \Drupal\Tests\webform\FunctionalJavascript\Variant\WebformVariantRandomizeJavaScriptTest::testVariantRandomize()
Test variant randomize.
File
- tests/
src/ FunctionalJavascript/ Variant/ WebformVariantRandomizeJavaScriptTest.php, line 41
Class
- WebformVariantRandomizeJavaScriptTest
- Tests for the webform variant randomize.
Namespace
Drupal\Tests\webform\FunctionalJavascript\VariantCode
public function testVariantRandomize() {
$webform = Webform::load('test_variant_randomize');
$this
->drupalGet('/webform/test_variant_randomize');
// Check that either 'a' or 'b' is persisted.
$saved_variant = $this
->getSavedVariantId();
$this
->assertContains($saved_variant, [
'a',
'b',
]);
// Disable the variant that is saved in the client session.
/** @var \Drupal\webform\Plugin\WebformVariantInterface $variant_plugin */
$variant_plugin = $webform
->getVariant($saved_variant);
$variant_plugin
->disable();
$webform
->save();
// Check that the disabled variant is no longer persisted, but rather
// that the remaining variant is instead.
$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);
// Disable the other variant.
/** @var \Drupal\webform\Plugin\WebformVariantInterface $variant_plugin */
$variant_plugin = $webform
->getVariant($new_saved_variant);
$variant_plugin
->disable();
$webform
->save();
// Check that no variant is now persisted.
$this
->drupalGet('/webform/test_variant_randomize');
$null_variant = $this
->getSavedVariantId();
$this
->assertNull($null_variant);
}