You are here

public function WebformElementHeightTest::testheightElement in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Element/WebformElementHeightTest.php \Drupal\Tests\webform\Functional\Element\WebformElementHeightTest::testheightElement()

Test height element.

File

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

Class

WebformElementHeightTest
Tests for webform height element.

Namespace

Drupal\Tests\webform\Functional\Element

Code

public function testheightElement() {
  $webform = Webform::load('test_element_height');
  $this
    ->drupalGet('/webform/test_element_height');

  // Check height_number_text.
  $this
    ->assertRaw('<input data-drupal-selector="edit-height-number-text-feet" type="number" id="edit-height-number-text-feet" name="height_number_text[feet]" value="5" step="1" min="0" max="8" class="form-number" />');
  $this
    ->assertRaw('<input data-drupal-selector="edit-height-number-text-inches" type="number" id="edit-height-number-text-inches" name="height_number_text[inches]" value="0" step="1" min="0" max="11" class="form-number" />');

  // Check height_select_text.
  $this
    ->assertRaw('<select data-drupal-selector="edit-height-select-text-feet" id="edit-height-select-text-feet" name="height_select_text[feet]" class="form-select"><option value=""></option><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3" selected="selected">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option></select>');
  $this
    ->assertRaw('<select data-drupal-selector="edit-height-select-text-inches" id="edit-height-select-text-inches" name="height_select_text[inches]" class="form-select"><option value=""></option><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4" selected="selected">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option></select>');

  // Check height_number_step.
  $this
    ->assertRaw('<select data-drupal-selector="edit-height-number-step-feet" id="edit-height-number-step-feet" name="height_number_step[feet]" class="form-select"><option value=""></option><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5" selected="selected">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option></select>');
  $this
    ->assertRaw('<select data-drupal-selector="edit-height-number-step-inches" id="edit-height-number-step-inches" name="height_number_step[inches]" class="form-select"><option value=""></option><option value="0.0">0.0</option><option value="0.5" selected="selected">0.5</option><option value="1.0">1.0</option><option value="1.5">1.5</option><option value="2.0">2.0</option><option value="2.5">2.5</option><option value="3.0">3.0</option><option value="3.5">3.5</option><option value="4.0">4.0</option><option value="4.5">4.5</option><option value="5.0">5.0</option><option value="5.5">5.5</option><option value="6.0">6.0</option><option value="6.5">6.5</option><option value="7.0">7.0</option><option value="7.5">7.5</option><option value="8.0">8.0</option><option value="8.5">8.5</option><option value="9.0">9.0</option><option value="9.5">9.5</option><option value="10.0">10.0</option><option value="10.5">10.5</option><option value="11.0">11.0</option></select>');

  // Post a submission.
  $edit = [
    'height_number_empty_required[feet]' => '5',
    'height_number_empty_required[inches]' => '5',
    'height_select_empty_required[feet]' => '5',
    'height_select_empty_required[inches]' => '5',
  ];
  $this
    ->postSubmission($webform, $edit);

  // Check submission data.
  $this
    ->assertRaw("height_number_text: '60'\nheight_number_symbol_required: '50'\nheight_select_text: '40'\nheight_select_text_abbreviate: '30'\nheight_select_symbol_required: '20'\nheight_select_suffix_symbol_required: '10'\nheight_select_suffix_text: '0'\nheight_select_min_max: '120'\nheight_number_step: '60.5'\nheight_number_empty: ''\nheight_select_empty: ''\nheight_number_empty_required: '65'\nheight_select_empty_required: '65'");

  // Check submission display.
  $this
    ->assertPattern('#<label>height_number_text</label>\\s+5 feet\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_number_symbol_required</label>\\s+4″2′\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_select_text</label>\\s+3 feet 4 inches\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_select_text_abbreviate</label>\\s+2 ft 6 in\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_select_symbol_required</label>\\s+1″8′\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_select_suffix_symbol_required</label>\\s+10′\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_select_min_max</label>\\s+10 feet\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_number_step</label>\\s+5 feet 0.5 inches\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_number_empty_required</label>\\s+5 feet 5 inches\\s+</div>#s');
  $this
    ->assertPattern('#<label>height_select_empty_required</label>\\s+5 feet 5 inches\\s+</div>#s');
  $this
    ->assertNoRaw('<label>height_select_suffix_text</label>');
  $this
    ->assertNoRaw('<label>height_number_empty</label>');
  $this
    ->assertNoRaw('<label>height_select_empty</label>');
}