You are here

public function WebformSubmissionViewTest::testView in Webform 6.x

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

Tests view submissions.

File

tests/src/Functional/WebformSubmissionViewTest.php, line 44

Class

WebformSubmissionViewTest
Tests for webform submission view as HTML, YAML, and plain text.

Namespace

Drupal\Tests\webform\Functional

Code

public function testView() {
  $admin_submission_user = $this
    ->drupalCreateUser([
    'administer webform submission',
  ]);

  /**************************************************************************/
  $account = User::load(1);
  $webform_element = Webform::load('test_element');
  $sid = $this
    ->postSubmission($webform_element);
  $submission = WebformSubmission::load($sid);
  $this
    ->drupalLogin($admin_submission_user);
  $this
    ->drupalGet('/admin/structure/webform/manage/test_element/submission/' . $submission
    ->id());

  // Check displayed values.
  $elements = [
    'hidden' => '{hidden}',
    'value' => '{value}',
    'textarea' => "{textarea line 1}<br />\n{textarea line 2}",
    'empty' => '{Empty}',
    'textfield' => '{textfield}',
    'select' => 'one',
    'select_multiple' => 'one, two',
    'checkbox' => 'Yes',
    'checkboxes' => 'one, two',
    'radios' => 'Yes',
    'email' => '<a href="mailto:example@example.com">example@example.com</a>',
    'number' => '1',
    'range' => '1',
    'tel' => '<a href="tel:999-999-9999">999-999-9999</a>',
    'url' => '<a href="http://example.com">http://example.com</a>',
    'color' => '<font color="#ffffcc">█</font> #ffffcc',
    'weight' => '0',
    'date' => 'Tuesday, August 18, 2009',
    'datetime' => 'Tuesday, August 18, 2009 - 4:00 PM',
    'datelist' => 'Tuesday, August 18, 2009 - 4:00 PM',
    'dollars' => '$100.00',
    'text_format' => '<p>The quick brown fox jumped over the lazy dog.</p>',
    'entity_autocomplete_user' => '<a href="' . $account
      ->toUrl()
      ->setAbsolute(TRUE)
      ->toString() . '" hreflang="en">admin</a>',
    'language_select' => 'English (en)',
  ];
  foreach ($elements as $label => $value) {
    $this
      ->assertRaw("<label>{$label}</label>" . PHP_EOL . "        {$value}", new FormattableMarkup('Found @label: @value', [
      '@label' => $label,
      '@value' => $value,
    ]));
  }

  // Check details element.
  $this
    ->assertRaw('<summary role="button" aria-controls="test_element--standard_elements" aria-expanded="true" aria-pressed="true">Standard Elements</summary>');

  // Check empty details element removed.
  $this
    ->assertNoRaw('Markup Elements');
}