WebformElementCheckboxesTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementCheckboxesTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
class WebformElementCheckboxesTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_checkboxes',
];
public function testCheckboxes() {
$webform = Webform::load('test_element_checkboxes');
$this
->drupalGet('/webform/test_element_checkboxes');
$this
->assertRaw('<div id="edit-checkboxes-buttons" class="js-webform-checkboxes webform-options-display-buttons form-checkboxes"><div class="webform-options-display-buttons-wrapper">');
$this
->assertRaw('<input data-drupal-selector="edit-checkboxes-buttons-yes" class="visually-hidden form-checkbox" type="checkbox" id="edit-checkboxes-buttons-yes" name="checkboxes_buttons[Yes]" value="Yes" />');
$this
->assertRaw('<label class="webform-options-display-buttons-label option" for="edit-checkboxes-buttons-yes">Yes</label>');
$this
->assertRaw('<div id="edit-checkboxes-buttons-horizontal" class="js-webform-checkboxes webform-options-display-buttons webform-options-display-buttons-horizontal form-checkboxes"><div class="webform-options-display-buttons-wrapper">');
$this
->assertRaw('<div id="edit-checkboxes-buttons-vertical" class="js-webform-checkboxes webform-options-display-buttons webform-options-display-buttons-vertical form-checkboxes"><div class="webform-options-display-buttons-wrapper">');
$this
->assertRaw('<label class="webform-options-display-buttons-label option" for="edit-checkboxes-buttons-description-one"><div class="webform-options-display-buttons-title">One</div><div class="webform-options-display-buttons-description description">This is a description</div></label>');
$this
->assertRaw('<div data-custom="custom wrapper data" style="border: red 1px solid" class="one-custom-wrapper-class js-form-item form-item js-form-type-checkbox form-item-checkboxes-options-properties-two js-form-item-checkboxes-options-properties-two">');
$this
->assertRaw('<label data-custom="custom label data" style="border: blue 1px solid" class="one-custom-label-class option" for="edit-checkboxes-options-properties-two">Two</label>');
$this
->assertRaw('<input data-drupal-selector="edit-checkboxes-options-properties-two" data-custom="custom input data" style="border: yellow 1px solid" class="one-custom-class form-checkbox" aria-describedby="edit-checkboxes-options-properties-two--description" type="checkbox" id="edit-checkboxes-options-properties-two" name="checkboxes_options_properties[two]" value="two" />');
$this
->assertRaw('<input data-drupal-selector="edit-checkboxes-other-options-properties-checkboxes-one" disabled="disabled" type="checkbox" id="edit-checkboxes-other-options-properties-checkboxes-one" name="checkboxes_other_options_properties[checkboxes][one]" value="one" class="form-checkbox" />');
$edit = [
'checkboxes_required_conditions[Yes]' => TRUE,
'checkboxes_other_required_conditions[checkboxes][Yes]' => TRUE,
];
$this
->postSubmission($webform, $edit, 'Preview');
$this
->assertNoRaw('<label>checkbox_exclude_empty</label>');
$webform
->setElementProperties('checkbox_exclude_empty', [
'#type' => 'checkbox',
'#title' => 'checkbox_exclude_empty',
]);
$webform
->save();
$edit = [
'checkboxes_required_conditions[Yes]' => TRUE,
'checkboxes_other_required_conditions[checkboxes][Yes]' => TRUE,
];
$this
->postSubmission($webform, $edit, 'Preview');
$this
->assertRaw('<label>checkbox_exclude_empty</label>');
}
}