You are here

WebformElementSubmissionViewsTest.php in Webform 6.x

File

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

namespace Drupal\Tests\webform\Functional\Element;


/**
 * Tests for webform submission views element.
 *
 * @group webform
 */
class WebformElementSubmissionViewsTest extends WebformElementBrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'views',
    'node',
    'webform',
    'webform_node',
  ];

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

  /**
   * Test webform submission views element.
   */
  public function testSubmissionViews() {

    // Check global and webform rendering.
    $this
      ->drupalGet('/webform/test_element_submission_views');
    $this
      ->assertRaw('<th class="webform_submission_views_global-table--name_title_view webform-multiple-table--name_title_view">');
    $this
      ->assertRaw('<th class="webform_submission_views_global-table--global_routes webform-multiple-table--global_routes">');
    $this
      ->assertRaw('<th class="webform_submission_views_global-table--webform_routes webform-multiple-table--webform_routes">');
    $this
      ->assertRaw('<th class="webform_submission_views_global-table--node_routes webform-multiple-table--node_routes">');
    $this
      ->assertRaw('<th class="webform_submission_views-table--name_title_view webform-multiple-table--name_title_view">');
    $this
      ->assertNoRaw('<th class="webform_submission_views-table--global_routes webform-multiple-table--global_routes">');
    $this
      ->assertRaw('<th class="webform_submission_views-table--webform_routes webform-multiple-table--webform_routes">');
    $this
      ->assertRaw('<th class="webform_submission_views-table--node_routes webform-multiple-table--node_routes">');

    // Check name validation.
    $edit = [
      'webform_submission_views_global[items][0][name]' => '',
    ];
    $this
      ->drupalPostForm('/webform/test_element_submission_views', $edit, 'Submit');
    $this
      ->assertRaw('Name is required');

    // Check view validation.
    $edit = [
      'webform_submission_views_global[items][0][view]' => '',
    ];
    $this
      ->drupalPostForm('/webform/test_element_submission_views', $edit, 'Submit');
    $this
      ->assertRaw('View name/display id is required.');

    // Check title validation.
    $edit = [
      'webform_submission_views_global[items][0][title]' => '',
    ];
    $this
      ->drupalPostForm('/webform/test_element_submission_views', $edit, 'Submit');
    $this
      ->assertRaw('Title is required.');

    // Check processing.
    $this
      ->drupalPostForm('/webform/test_element_submission_views', [], 'Submit');
    $this
      ->assertRaw("webform_submission_views_global:\n  admin:\n    view: 'webform_submissions:embed_administer'\n    title: Admin\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:\n  admin:\n    view: 'webform_submissions:embed_administer'\n    title: Admin\n    webform_routes:\n      - entity.webform.results_submissions\n    node_routes:\n      - entity.node.webform.results_submissions");

    // Check processing empty record.
    $edit = [
      'webform_submission_views_global[items][0][name]' => '',
      'webform_submission_views_global[items][0][view]' => '',
      'webform_submission_views_global[items][0][title]' => '',
      'webform_submission_views_global[items][0][global_routes][entity.webform_submission.collection]' => FALSE,
      'webform_submission_views_global[items][0][webform_routes][entity.webform.results_submissions]' => FALSE,
      'webform_submission_views_global[items][0][node_routes][entity.node.webform.results_submissions]' => FALSE,
    ];
    $this
      ->drupalPostForm('/webform/test_element_submission_views', $edit, 'Submit');
    $this
      ->assertNoRaw('Name is required');
    $this
      ->assertNoRaw('View name/display id is required.');
    $this
      ->assertNoRaw('Title is required.');
    $this
      ->assertRaw("webform_submission_views_global: {  }\nwebform_submission_views:\n  admin:\n    view: 'webform_submissions:embed_administer'\n    title: Admin\n    webform_routes:\n      - entity.webform.results_submissions\n    node_routes:\n      - entity.node.webform.results_submissions");

    // Uninstall the webform node module.
    $this->container
      ->get('module_installer')
      ->uninstall([
      'webform_node',
    ]);

    // Check global and webform rendering without node settings.
    $this
      ->drupalGet('/webform/test_element_submission_views');
    $this
      ->assertNoRaw('<th class="webform_submission_views_global-table--node_routes webform-multiple-table--node_routes">');
    $this
      ->assertNoRaw('<th class="webform_submission_views-table--node_routes webform-multiple-table--node_routes">');

    // Check processing removes node settings.
    $this
      ->drupalPostForm('/webform/test_element_submission_views', [], 'Submit');
    $this
      ->assertRaw("webform_submission_views_global:\n  admin:\n    view: 'webform_submissions:embed_administer'\n    title: Admin\n    global_routes:\n      - entity.webform_submission.collection\n    webform_routes:\n      - entity.webform.results_submissions\nwebform_submission_views:\n  admin:\n    view: 'webform_submissions:embed_administer'\n    title: Admin\n    webform_routes:\n      - entity.webform.results_submissions");

    // Uninstall the views module.
    $this->container
      ->get('module_installer')
      ->uninstall([
      'views',
    ]);

    // Check that element is completely hidden.
    $this
      ->drupalGet('/webform/test_element_submission_views');
    $this
      ->assertNoRaw('<th class="webform_submission_views_global-table--name_title_view webform-multiple-table--name_title_view">');
    $this
      ->assertNoRaw('<th class="webform_submission_views-table--name_title_view webform-multiple-table--name_title_view">');

    // Check that value is preserved.
    $this
      ->drupalPostForm('/webform/test_element_submission_views', [], 'Submit');
    $this
      ->assertRaw("webform_submission_views_global: {  }\nwebform_submission_views: {  }");
  }

}

Classes

Namesort descending Description
WebformElementSubmissionViewsTest Tests for webform submission views element.