You are here

public function WebformElementCheckboxTest::testCheckboxValue in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Functional/Element/WebformElementCheckboxTest.php \Drupal\Tests\webform\Functional\Element\WebformElementCheckboxTest::testCheckboxValue()

Tests checkbox value element.

File

tests/src/Functional/Element/WebformElementCheckboxTest.php, line 24

Class

WebformElementCheckboxTest
Tests for webform checkbox element.

Namespace

Drupal\Tests\webform\Functional\Element

Code

public function testCheckboxValue() {
  $this
    ->drupalLogin($this->rootUser);
  $webform = Webform::load('test_element_checkbox');

  // Check submitted values.
  $edit = [
    'checkbox' => TRUE,
    'checkbox_raw' => TRUE,
    'checkbox_return_value' => 'custom_return_value',
    'checkbox_return_value_raw' => 'custom_return_value_raw',
  ];
  $sid = $this
    ->postSubmission($webform, $edit);
  $this
    ->assertRaw("checkbox: 1\ncheckbox_raw: 1\ncheckbox_return_value: custom_return_value\ncheckbox_return_value_raw: custom_return_value_raw");

  // Check display of value and raw.
  $this
    ->drupalGet('/admin/structure/webform/manage/test_element_checkbox/submission/' . $sid);
  $this
    ->assertPattern('#<label>checkbox</label>\\s+Yes\\s+</div>#');
  $this
    ->assertPattern('#<label>checkbox_raw</label>\\s+1\\s+</div>#');
  $this
    ->assertPattern('#<label>checkbox_return_value</label>\\s+Yes\\s+</div>#');
  $this
    ->assertPattern('#<label>checkbox_return_value_raw</label>\\s+custom_return_value_raw\\s+</div>#');
}