WebformVariantElementTest.php in Webform 8.5
File
tests/src/Functional/Variant/WebformVariantElementTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Variant;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\Entity\Webform;
class WebformVariantElementTest extends WebformBrowserTestBase {
public static $modules = [
'block',
'webform',
'webform_ui',
'webform_test_variant',
];
protected static $testWebforms = [
'test_variant_multiple',
];
protected function setUp() {
parent::setUp();
$this
->placeBlocks();
}
public function testVariantElement() {
$variant_user = $this
->drupalCreateUser([
'administer webform',
'edit webform variants',
]);
$admin_user = $this
->drupalCreateUser([
'administer webform',
]);
$this
->drupalLogin($variant_user);
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add');
$this
->assertLink('Variant');
$this
->drupalLogin($admin_user);
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add');
$this
->assertNoLink('Variant');
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add/webform_variant');
$this
->assertResponse(200);
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add/webform_variant');
$this
->assertRaw('<option value="override">Override</option>');
$this
->assertNoRaw('<option value="test">Test</option>');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/element/add/webform_variant');
$this
->assertRaw('<option value="override">Override</option>');
$this
->assertRaw('<option value="test">Test</option>');
$this
->drupalLogin($variant_user);
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add/webform_variant');
$this
->assertRaw("After clicking 'Save', the 'Variants' manage tab will be displayed. Use the 'Variants' manage tab to add and remove variants.");
$this
->assertNoText('Add and remove variants using the Variants manage tab.');
$this
->drupalGet('/admin/structure/webform/manage/contact');
$this
->assertNoLink('Variants');
$edit = [
'key' => 'variant',
'properties[title]' => '{variant_title}',
'properties[variant]' => 'override',
];
$this
->drupalPostForm('/admin/structure/webform/manage/contact/element/add/webform_variant', $edit, 'Save');
$this
->drupalGet('/admin/structure/webform/manage/contact');
$this
->assertLink('Variants');
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add/webform_variant');
$this
->assertNoRaw("After clicking 'Save', the 'Variants' manage tab will be displayed. Use the 'Variants' manage tab to add and remove variants.");
$this
->assertText('Add and remove variants using the Variants manage tab.');
$this
->drupalLogin($admin_user);
$this
->drupalGet('/admin/structure/webform/manage/contact/element/add/webform_variant');
$this
->assertNoText('Add and remove variants using the Variants manage tab.');
$this
->drupalGet('/admin/structure/webform/manage/contact');
$this
->assertNoLink('Variants');
$this
->drupalGet('/admin/structure/webform/manage/test_variant_multiple/element/letter/edit');
$this
->assertNoRaw('<option value="override">Override</option>');
$this
->assertRaw('Override');
$this
->assertRaw('This variant is currently in-use. The variant type cannot be changed.');
$webform = Webform::load('test_variant_multiple');
$this
->assertEqual(2, $webform
->getVariants(NULL, NULL, 'letter')
->count());
$webform
->deleteElement('letter');
$webform
->save();
$this
->assertEqual(0, $webform
->getVariants(NULL, NULL, 'letter')
->count());
}
}