You are here

public function WebformElementSubmissionViewsReplaceTest::testSubmissionViewsReplace in Webform 8.5

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

Test webform submission views replace element.

File

tests/src/Functional/Element/WebformElementSubmissionViewsReplaceTest.php, line 29

Class

WebformElementSubmissionViewsReplaceTest
Tests for webform submission views replace element.

Namespace

Drupal\Tests\webform\Functional\Element

Code

public function testSubmissionViewsReplace() {

  // Check rendering.
  $this
    ->drupalGet('/webform/test_element_submission_views_r');
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-global-global-routes" id="edit-webform-submission-views-replace-global-global-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-global-webform-routes" id="edit-webform-submission-views-replace-global-webform-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-global-node-routes" id="edit-webform-submission-views-replace-global-node-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');

  // Check that the webform replace element is hidden.
  $this
    ->assertNoRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-webform-routes" id="edit-webform-submission-views-replace-webform-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertNoRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-node-routes" id="edit-webform-submission-views-replace-node-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');

  // Check processing clears hidden webform_submission_views_replace.
  $this
    ->drupalPostForm('/webform/test_element_submission_views_r', [], 'Submit');
  $this
    ->assertRaw("webform_submission_views_replace_global:\n  global_routes:\n    - entity.webform_submission.collection\n  webform_routes:\n    - entity.webform.results_submissions\n  node_routes:\n    - entity.node.webform.results_submissions\nwebform_submission_views_replace: {  }");

  // Clear default_submission_views_replace.
  \Drupal::configFactory()
    ->getEditable('webform.settings')
    ->set('settings.default_submission_views_replace', [
    'global_routes' => [],
    'webform_routes' => [],
    'node_routes' => [],
  ])
    ->save();

  // Check that the webform replace element is visible.
  $this
    ->drupalGet('/webform/test_element_submission_views_r');
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-webform-routes" id="edit-webform-submission-views-replace-webform-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-webform-submission-views-replace-node-routes" id="edit-webform-submission-views-replace-node-routes--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');

  // Check processing with webform replace element is visible.
  $this
    ->drupalPostForm('/webform/test_element_submission_views_r', [], 'Submit');
  $this
    ->assertRaw("webform_submission_views_replace_global:\n  global_routes:\n    - entity.webform_submission.collection\n  webform_routes:\n    - entity.webform.results_submissions\n  node_routes:\n    - entity.node.webform.results_submissions\nwebform_submission_views_replace:\n  webform_routes:\n    - entity.webform.results_submissions\n  node_routes:\n    - entity.node.webform.results_submissions");
}