You are here

WebformElementOptionsTest.php in Webform 6.x

Same filename and directory in other branches
  1. 8.5 tests/src/Functional/Element/WebformElementOptionsTest.php

File

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

namespace Drupal\Tests\webform\Functional\Element;


/**
 * Tests for webform element options.
 *
 * @group webform
 */
class WebformElementOptionsTest extends WebformElementBrowserTestBase {

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

  /**
   * Tests options element.
   */
  public function testElementOptions() {

    // Check options maxlength.
    $this
      ->drupalGet('/webform/test_element_options');
    $this
      ->assertRaw('<input class="js-webform-options-sync form-text" data-drupal-selector="edit-webform-options-maxlength-options-items-0-value" type="text" id="edit-webform-options-maxlength-options-items-0-value" name="webform_options_maxlength[options][items][0][value]" value="one" size="60" maxlength="20" placeholder="Enter value…" />');
    $this
      ->assertRaw('<input data-drupal-selector="edit-webform-options-maxlength-options-items-0-text" type="text" id="edit-webform-options-maxlength-options-items-0-text" name="webform_options_maxlength[options][items][0][text]" value="One" size="60" maxlength="20" placeholder="Enter text…" class="form-text" />');

    // Check default value handling.
    $this
      ->drupalPostForm('/webform/test_element_options', [], 'Submit');
    $this
      ->assertRaw("webform_options: {  }\nwebform_options_default_value:\n  one: One\n  two: Two\n  three: Three\nwebform_options_maxlength:\n  one: One\n  two: Two\n  three: Three\nwebform_options_optgroup:\n  'Group One':\n    one: One\n  'Group Two':\n    two: Two\n  'Group Three':\n    three: Three\nwebform_element_options_entity: yes_no\nwebform_element_options_custom:\n  one: One\n  two: Two\n  three: Three");

    // Check default value handling.
    $this
      ->drupalPostForm('/webform/test_element_options', [
      'webform_element_options_custom[options]' => 'yes_no',
    ], 'Submit');
    $this
      ->assertRaw("webform_element_options_custom: yes_no");

    // Check unique option value validation.
    $edit = [
      'webform_options[options][items][0][value]' => 'test',
      'webform_options[options][items][1][value]' => 'test',
    ];
    $this
      ->drupalPostForm('/webform/test_element_options', $edit, 'Submit');
    $this
      ->assertRaw('The <em class="placeholder">Option value</em> \'test\' is already in use. It must be unique.');
  }

}

Classes

Namesort descending Description
WebformElementOptionsTest Tests for webform element options.