You are here

WebformElementCheckboxTest.php in Webform 8.5

Same filename and directory in other branches
  1. 6.x tests/src/Functional/Element/WebformElementCheckboxTest.php

File

tests/src/Functional/Element/WebformElementCheckboxTest.php
View source
<?php

namespace Drupal\Tests\webform\Functional\Element;

use Drupal\webform\Entity\Webform;

/**
 * Tests for webform checkbox element.
 *
 * @group webform
 */
class WebformElementCheckboxTest extends WebformElementBrowserTestBase {

  /**
   * Webforms to load.
   *
   * @var array
   */
  protected static $testWebforms = [
    'test_element_checkbox',
  ];

  /**
   * Tests checkbox value element.
   */
  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>#');
  }

}

Classes

Namesort descending Description
WebformElementCheckboxTest Tests for webform checkbox element.