You are here

public function WebformUiElementPropertiesTest::testElementProperties in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_ui/tests/src/Functional/WebformUiElementPropertiesTest.php \Drupal\Tests\webform_ui\Functional\WebformUiElementPropertiesTest::testElementProperties()

Tests element properties.

File

modules/webform_ui/tests/src/Functional/WebformUiElementPropertiesTest.php, line 50

Class

WebformUiElementPropertiesTest
Tests for webform UI element properties.

Namespace

Drupal\Tests\webform_ui\Functional

Code

public function testElementProperties() {
  $this
    ->drupalLogin($this->rootUser);

  // Loops through all the elements, edits them via the UI, and checks that
  // the element's render array has not been altered.
  // This verifies that the edit element (via UI) form is not unexpectedly
  // altering an element's render array.
  foreach (static::$testWebforms as $webform_id) {

    /** @var \Drupal\webform\WebformInterface $webform_elements */
    $webform_elements = Webform::load($webform_id);
    $original_elements = $webform_elements
      ->getElementsDecodedAndFlattened();
    foreach ($original_elements as $key => $original_element) {
      $this
        ->drupalPostForm('/admin/structure/webform/manage/' . $webform_elements
        ->id() . '/element/' . $key . '/edit', [], 'Save');

      // Must reset the webform entity cache so that the update elements can
      // be loaded.
      \Drupal::entityTypeManager()
        ->getStorage('webform_submission')
        ->resetCache();

      /** @var \Drupal\webform\WebformInterface $webform_elements */
      $webform_elements = Webform::load($webform_id);
      $updated_element = $webform_elements
        ->getElementsDecodedAndFlattened()[$key];
      $this
        ->assertEqual($original_element, $updated_element, "'{$key}'' properties is equal.");
    }
  }
}