You are here

WebformMigrateAssertionsTrait.php in Webform: Migrate 8.2

Same filename and directory in other branches
  1. 8 tests/src/Traits/WebformMigrateAssertionsTrait.php

File

tests/src/Traits/WebformMigrateAssertionsTrait.php
View source
<?php

namespace Drupal\Tests\webform_migrate\Traits;

use Drupal\Core\Entity\EntityInterface;
use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionInterface;

/**
 * Trait for webform migration tests.
 */
trait WebformMigrateAssertionsTrait {

  /**
   * List of node properties whose value shouldn't have to be checked.
   *
   * @var string[]
   */
  protected $webformUnconcernedProperties = [
    'uuid',
  ];

  /**
   * List of webform submission properties which are irrelevant.
   *
   * @var string[]
   */
  protected $webformSubmissionUnconcernedProperties = [
    'uuid',
    'changed',
    'langcode',
    'token',
  ];

  /**
   * Assertions of the webform_3 configuration entity.
   */
  protected function assertWebform3Values() {
    $webform = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform')
      ->load('webform_3');
    assert($webform instanceof WebformInterface);
    $this
      ->assertEquals([
      'uid' => 2,
      'status' => 'open',
      'langcode' => 'en',
      'dependencies' => [],
      'open' => NULL,
      'close' => NULL,
      'weight' => 0,
      'template' => FALSE,
      'archive' => FALSE,
      'id' => 'webform_3',
      'title' => 'A Webform host node with "webform_custom" type',
      'description' => NULL,
      'category' => NULL,
      'elements' => "first_page:\n  '#type': webform_wizard_page\n  '#title': Start\n  title_as_textfield:\n    '#type': textfield\n    '#size': 100\n    '#title': 'Title (as textfield)'\n    '#description': \"Required, no default value, no conditions.\\nIf the title contains <code>fieldset</code>, then a fieldset will appear.\"\n    '#required': true\n  date:\n    '#type': date\n    '#title': 'Date'\n    '#description': \"Optional, no default value, website timezone.\"\n  email:\n    '#type': email\n    '#size': 20\n    '#default_value': '[current-user:mail]'\n    '#title_display': invisible\n    '#title': 'E-mail'\n    '#description': \"No label; user email as default; long format ('Example Name' <name@example.com>) can be used.\"\n  file_attachment:\n    '#type': managed_file\n    '#max_filesize': '2'\n    '#file_extensions': 'gif jpg jpeg png eps txt rtf html pdf doc docx odt ppt pptx odp xls xlsx ods xml ps'\n    '#title': 'File attachment'\n    '#description': \"\"\n  fieldset:\n    '#type': fieldset\n    '#open': true\n    '#title': 'Fieldset'\n    '#description': \"\"\n    '#states':\n      visible:\n        ':input[name=\"title_as_textfield\"]':\n          value:\n            pattern: fieldset\n    hidden_value_5:\n      '#type': hidden\n      '#default_value': 'hidden value of \"hidden_value\"'\n      '#title': 'Hidden value'\n      '#description': \"\"\n    select_multi_nested_5:\n      '#type': select\n      '#options':\n        a: 'Option A'\n        b: 'Option B'\n        'Group A':\n          aa: 'Option AA'\n          ab: 'Option AB'\n        'Group B':\n          ba: 'Option BA'\n          bb: 'Option BB'\n        c: 'Option C'\n      '#multiple': true\n      '#title': 'Select options (multiple, nested)'\n      '#description': \"\"\n  text_markup:\n    '#type': processed_text\n    '#format': full_html\n    '#text': \"Some <strong>text</strong> with <code>filtered_html</code>, displayed only on the form.\"\n    '#title': 'Text markup'\n    '#description': \"\"\n  number:\n    '#type': textfield\n    '#size': 20\n    '#min': 10\n    '#max': 3000\n    '#unique': false\n    '#title': 'Number'\n    '#description': \"An integer between 10 and 3000.\"\n    '#required': true\n  radios:\n    '#type': radios\n    '#options':\n      tuesday: 'Tuesday'\n      wednesday: 'Wednesday'\n      thursday: 'Thursday'\n      friday: 'Friday'\n      saturday: 'Saturday'\n      sunday: 'Sunday'\n    '#default_value': 'wednesday'\n    '#title': 'Radios'\n    '#description': \"Select the best day of the week\"\n    '#required': true\npage_break:\n  '#type': webform_wizard_page\n  '#title': Page break\n  checkboxes:\n    '#type': checkboxes\n    '#options':\n      AF: 'Afghanistan'\n      AX: 'Aland Islands'\n      AL: 'Albania'\n      DZ: 'Algeria'\n      AS: 'American Samoa'\n      AD: 'Andorra'\n      AO: 'Angola'\n      AI: 'Anguilla'\n      AQ: 'Antarctica'\n      AG: 'Antigua and Barbuda'\n      AR: 'Argentina'\n      AM: 'Armenia'\n      AW: 'Aruba'\n      AU: 'Australia'\n      AT: 'Austria'\n      AZ: 'Azerbaijan'\n      ZM: 'Zambia'\n      ZW: 'Zimbabwe'\n    '#multiple': true\n    '#title': 'Checkboxes'\n    '#description': \"Countries you want to travel to (only A and Z)\"\n  textarea:\n    '#type': textarea\n    '#title': 'Textarea'\n    '#description': \"\"\n  time:\n    '#type': webform_time\n    '#time_format': 'H:i'\n    '#step': 60\n    '#title_display': inline\n    '#title': 'Time'\n    '#description': \"\"\n",
      'css' => '',
      'javascript' => '',
      'settings' => [
        'page' => TRUE,
        'page_submit_path' => '',
        'page_confirm_path' => '',
        'wizard_progress_bar' => TRUE,
        'preview' => 0,
        'draft' => '0',
        'draft_auto_save' => FALSE,
        'confirmation_type' => 'page',
        'confirmation_url' => '',
        'confirmation_message' => '',
        'limit_total' => NULL,
        'limit_user' => NULL,
      ],
      'access' => [
        'create' => [
          'roles' => [
            'anonymous',
            'authenticated',
          ],
          'users' => [],
        ],
      ],
      'handlers' => [],
      'variants' => [],
    ], $this
      ->getImportantEntityProperties($webform));
  }

  /**
   * Assertions of the webform_4 configuration entity.
   */
  protected function assertWebform4Values() {
    $webform = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform')
      ->load('webform_4');
    assert($webform instanceof WebformInterface);
    $this
      ->assertEquals([
      'uid' => 1,
      'status' => 'open',
      'langcode' => 'en',
      'dependencies' => [],
      'open' => NULL,
      'close' => NULL,
      'weight' => 0,
      'template' => FALSE,
      'archive' => FALSE,
      'id' => 'webform_4',
      'title' => 'A Webform host node with the default "webform" type',
      'description' => NULL,
      'category' => NULL,
      'elements' => "grid:\n  '#type': webform_likert\n  '#questions':\n    'd7_sitebuild': 'How much you value Drupal 7 in terms of site building capabilities?'\n    'd7_theming': 'How much you value Drupal 7 in terms of theme development?'\n    'd7_backend': 'How much you value Drupal 7 in terms of module development?'\n    'd9_sitebuild': 'How much you value Drupal 8 or Drupal 9 in terms of site building capabilities?'\n    'd9_theming': 'How much you value Drupal 8 or Drupal 9 in terms of theme development?'\n    'd9_backend': 'How much you value Drupal 8 or Drupal 9 in terms of module development?'\n  '#answers':\n    'hard': 'Hard'\n    'neutral': 'Not too hard, but can be easier'\n    'easy': 'Easy'\n  '#title': 'Grid'\n  '#description': \"Please evaluate how Drupal fits your needs\"\n",
      'css' => '',
      'javascript' => '',
      'settings' => [
        'page' => TRUE,
        'page_submit_path' => '',
        'page_confirm_path' => '',
        'wizard_progress_bar' => TRUE,
        'preview' => 0,
        'draft' => '0',
        'draft_auto_save' => FALSE,
        'confirmation_type' => 'page',
        'confirmation_url' => '',
        'confirmation_message' => 'Webform (default "webform" #1) confirmation message',
        'limit_total' => NULL,
        'limit_user' => 1,
      ],
      'access' => [
        'create' => [
          'roles' => [
            'anonymous',
            'authenticated',
          ],
          'users' => [],
        ],
      ],
      'handlers' => [],
      'variants' => [],
    ], $this
      ->getImportantEntityProperties($webform));
  }

  /**
   * Assertions of the webform_5 configuration entity.
   */
  protected function assertWebform5Values() {
    $webform = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform')
      ->load('webform_5');
    assert($webform instanceof WebformInterface);
    $this
      ->assertEquals([
      'uid' => 2,
      'status' => 'open',
      'langcode' => 'en',
      'dependencies' => [],
      'open' => NULL,
      'close' => NULL,
      'weight' => 0,
      'template' => FALSE,
      'archive' => FALSE,
      'id' => 'webform_5',
      'title' => 'Coffee Questionnaire',
      'description' => NULL,
      'category' => NULL,
      'elements' => "brewing_styles:\n  '#type': checkboxes\n  '#options':\n    drip_brew: 'Drip Brew'\n    pour_over: 'Pour Over'\n    cold_brew: 'Cold Brew'\n    espresso: 'Espresso'\n    ristretto: 'Ristretto'\n  '#multiple': true\n  '#title': 'Brewing Styles'\n  '#description': \"Brewing styles you like\"\ndrinks:\n  '#type': checkboxes\n  '#options':\n    espresso: 'Espresso (short black)'\n    double_espresso: 'Double Espresso (doppio)'\n    red_eye: 'Red Eye'\n    black_eye: 'Black Eye'\n    long_black: 'Long Black'\n    macchiato: 'Macchiato'\n    long_macchiato: 'Long Macchiato'\n    cortado: 'Cortado'\n    breve: 'Breve'\n    cappuccino: 'Cappuccino'\n    flat_white: 'Flat White'\n    cafe_latte: 'Cafe Latte'\n    mocha: 'Mocha'\n    vienna: 'Vienna'\n    affogato: 'Affogato'\n    cafe_au_lait: 'Cafe au Lait'\n    iced_coffee: 'Iced Coffee'\n  '#multiple': true\n  '#title': 'Drinks'\n  '#description': \"Please choose the coffee styles you like\"\n  '#required': true\n",
      'css' => '',
      'javascript' => '',
      'settings' => [
        'page' => TRUE,
        'page_submit_path' => '',
        'page_confirm_path' => '',
        'wizard_progress_bar' => TRUE,
        'preview' => 0,
        'draft' => '0',
        'draft_auto_save' => FALSE,
        'confirmation_type' => 'page',
        'confirmation_url' => '',
        'confirmation_message' => '',
        'limit_total' => NULL,
        'limit_user' => 1,
      ],
      'access' => [
        'create' => [
          'roles' => [
            'authenticated',
          ],
          'users' => [],
        ],
      ],
      'handlers' => [
        'email_1' => [
          'id' => 'email',
          'label' => 'Email 1',
          'handler_id' => 'email_1',
          'status' => TRUE,
          'conditions' => [],
          'weight' => 1,
          'settings' => [
            'to_mail' => 'info@drupal7-webform.localhost',
            'from_mail' => 'default',
            'from_name' => 'Coffee Questionnaire',
            'subject' => 'default',
            'body' => 'default',
            'html' => FALSE,
            'attachments' => FALSE,
            'excluded_elements' => [],
            'states' => [
              'completed',
            ],
            'to_options' => [],
            'cc_mail' => '',
            'cc_options' => [],
            'bcc_mail' => '',
            'bcc_options' => [],
            'from_options' => [],
            'ignore_access' => FALSE,
            'exclude_empty' => TRUE,
            'exclude_empty_checkbox' => FALSE,
            'exclude_attachments' => FALSE,
            'twig' => FALSE,
            'debug' => FALSE,
            'reply_to' => '',
            'return_path' => '',
            'sender_mail' => '',
            'sender_name' => '',
            'theme_name' => '',
            'parameters' => [],
          ],
          'notes' => '',
        ],
      ],
      'variants' => [],
    ], $this
      ->getImportantEntityProperties($webform));
  }

  /**
   * Assertions of the webform_submission 1 content entity.
   */
  protected function assertWebformSubmission1Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(1);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'created' => [
        [
          'value' => 1600263958,
        ],
      ],
      'serial' => [
        [
          'value' => 1,
        ],
      ],
      'sid' => [
        [
          'value' => 1,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/3',
        ],
      ],
      'completed' => [
        [
          'value' => 1600263958,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '::1',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_3',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 3,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $data = $webform_submission
      ->getData();
    $this
      ->assertEquals([
      'checkboxes' => [
        'AF',
        'AL',
        'DZ',
        'AQ',
        'AG',
        'AR',
        'AU',
        'ZW',
      ],
      'date' => '2018-10-23',
      'file_attachment' => '1',
      'number' => '11',
      'radios' => 'sunday',
      'textarea' => 'Why I cannot choose Monday as my favorite weekday?',
      'time' => '18:01:00',
      'title_as_textfield' => 'Example submission from an anonymous user',
    ], $data);
  }

  /**
   * Assertions of the webform_submission 2 content entity.
   */
  protected function assertWebformSubmission2Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(2);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'created' => [
        [
          'value' => 1600264081,
        ],
      ],
      'serial' => [
        [
          'value' => 2,
        ],
      ],
      'sid' => [
        [
          'value' => 2,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/3',
        ],
      ],
      'completed' => [
        [
          'value' => 1600264081,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '::1',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_3',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 3,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $data = $webform_submission
      ->getData();
    $this
      ->assertEquals([
      'checkboxes' => [
        0 => 'AQ',
      ],
      'email' => 'me@somewhere.else',
      'file_attachment' => '2',
      'number' => '20',
      'radios' => 'friday',
      'title_as_textfield' => 'Text with fieldset',
      'hidden_value_5' => 'hidden value of "hidden_value"',
      'select_multi_nested_5' => [
        'a',
        'ba',
        'bb',
      ],
    ], $data);
  }

  /**
   * Assertions of the webform_submission 3 content entity.
   */
  protected function assertWebformSubmission3Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(3);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'created' => [
        [
          'value' => 1600327212,
        ],
      ],
      'serial' => [
        [
          'value' => 3,
        ],
      ],
      'sid' => [
        [
          'value' => 3,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/3',
        ],
      ],
      'completed' => [
        [
          'value' => 1600327212,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '172.16.0.166',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_3',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 3,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $data = $webform_submission
      ->getData();
    $this
      ->assertEquals([
      'checkboxes' => [
        'AG',
        'AW',
      ],
      'date' => '2020-09-17',
      'email' => 'another@email.address',
      'file_attachment' => '3',
      'number' => '244',
      'radios' => 'sunday',
      'textarea' => 'FooBarBaz',
      'time' => '09:22:00',
      'title_as_textfield' => 'Submission from an another anonymous user',
    ], $data);
  }

  /**
   * Assertions of the webform_submission 4 content entity.
   */
  protected function assertWebformSubmission4Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(4);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'created' => [
        [
          'value' => 1600327251,
        ],
      ],
      'serial' => [
        [
          'value' => 1,
        ],
      ],
      'sid' => [
        [
          'value' => 4,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/4',
        ],
      ],
      'completed' => [
        [
          'value' => 1600327251,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '172.16.0.166',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_4',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 4,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $data = $webform_submission
      ->getData();
    $this
      ->assertEquals([
      'grid' => [
        'd7_sitebuild' => 'neutral',
        'd7_theming' => 'easy',
        'd7_backend' => 'neutral',
        'd9_sitebuild' => 'neutral',
        'd9_theming' => 'easy',
        'd9_backend' => 'easy',
      ],
    ], $data);
  }

  /**
   * Assertions of the webform_submission 5 content entity.
   */
  protected function assertWebformSubmission5Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(5);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 3,
        ],
      ],
      'created' => [
        [
          'value' => 1600327319,
        ],
      ],
      'serial' => [
        [
          'value' => 1,
        ],
      ],
      'sid' => [
        [
          'value' => 5,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/5',
        ],
      ],
      'completed' => [
        [
          'value' => 1600327319,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '172.16.0.166',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_5',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 5,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $this
      ->assertEquals([
      'brewing_styles' => [
        'espresso',
        'ristretto',
      ],
      'drinks' => [
        'espresso',
        'double_espresso',
        'macchiato',
        'cappuccino',
        'mocha',
        'vienna',
      ],
    ], $webform_submission
      ->getData());
  }

  /**
   * Assertions of the webform_submission 6 content entity.
   */
  protected function assertWebformSubmission6Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(6);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 3,
        ],
      ],
      'created' => [
        [
          'value' => 1600327404,
        ],
      ],
      'serial' => [
        [
          'value' => 2,
        ],
      ],
      'sid' => [
        [
          'value' => 6,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/4',
        ],
      ],
      'completed' => [
        [
          'value' => 1600327404,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '172.16.0.166',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_4',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 4,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $data = $webform_submission
      ->getData();
    $this
      ->assertEquals([
      'grid' => [
        'd7_sitebuild' => 'neutral',
        'd7_theming' => 'easy',
        'd7_backend' => 'neutral',
        'd9_sitebuild' => 'neutral',
        // No answer for "d9_theming".
        'd9_backend' => 'hard',
      ],
    ], $data);
  }

  /**
   * Assertions of the webform_submission 7 content entity.
   */
  protected function assertWebformSubmission7Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(7);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 3,
        ],
      ],
      'created' => [
        [
          'value' => 1600327527,
        ],
      ],
      'serial' => [
        [
          'value' => 4,
        ],
      ],
      'sid' => [
        [
          'value' => 7,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/3',
        ],
      ],
      'completed' => [
        [
          'value' => 1600327527,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '172.16.0.166',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_3',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 3,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $this
      ->assertEquals([
      'checkboxes' => [
        'AQ',
        'AW',
      ],
      'date' => '2020-01-23',
      'email' => 'user@drupal7-webform.localhost',
      'number' => '45',
      'radios' => 'wednesday',
      'textarea' => 'No file was attached.',
      'time' => '20:04:00',
      'title_as_textfield' => "User's submission",
    ], $webform_submission
      ->getData());
  }

  /**
   * Assertions of the webform_submission 8 content entity.
   */
  protected function assertWebformSubmission8Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(8);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 0,
        ],
      ],
      'created' => [
        [
          'value' => 1600328002,
        ],
      ],
      'serial' => [
        [
          'value' => 3,
        ],
      ],
      'sid' => [
        [
          'value' => 8,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/4',
        ],
      ],
      'completed' => [
        [
          'value' => 1600328002,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '::1',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_4',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 4,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $this
      ->assertEquals([
      'grid' => [
        'd7_sitebuild' => 'easy',
        'd7_theming' => 'neutral',
        'd7_backend' => 'hard',
        'd9_sitebuild' => 'hard',
        'd9_theming' => 'neutral',
        'd9_backend' => 'hard',
      ],
    ], $webform_submission
      ->getData());
  }

  /**
   * Assertions of the webform_submission 9 content entity.
   */
  protected function assertWebformSubmission9Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(9);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 2,
        ],
      ],
      'created' => [
        [
          'value' => 1600328929,
        ],
      ],
      'serial' => [
        [
          'value' => 4,
        ],
      ],
      'sid' => [
        [
          'value' => 9,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/4',
        ],
      ],
      'completed' => [
        [
          'value' => 1600328929,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '127.0.0.1',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_4',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 4,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $this
      ->assertEquals([
      'grid' => [
        'd7_sitebuild' => 'easy',
        'd7_theming' => 'easy',
        'd7_backend' => 'neutral',
        'd9_sitebuild' => 'easy',
        'd9_theming' => 'easy',
        'd9_backend' => 'easy',
      ],
    ], $webform_submission
      ->getData());
  }

  /**
   * Assertions of the webform_submission 10 content entity.
   */
  protected function assertWebformSubmission10Values() {
    $webform_submission = $this->container
      ->get('entity_type.manager')
      ->getStorage('webform_submission')
      ->load(10);
    assert($webform_submission instanceof WebformSubmissionInterface);
    $this
      ->assertEquals([
      'uid' => [
        [
          'target_id' => 1,
        ],
      ],
      'created' => [
        [
          'value' => 1600335185,
        ],
      ],
      'serial' => [
        [
          'value' => 2,
        ],
      ],
      'sid' => [
        [
          'value' => 10,
        ],
      ],
      'uri' => [
        [
          'value' => '/node/5',
        ],
      ],
      'completed' => [
        [
          'value' => 1600335185,
        ],
      ],
      'in_draft' => [
        [
          'value' => 0,
        ],
      ],
      'current_page' => [],
      'remote_addr' => [
        [
          'value' => '::1',
        ],
      ],
      'webform_id' => [
        [
          'target_id' => 'webform_5',
        ],
      ],
      'entity_type' => [
        [
          'value' => 'node',
        ],
      ],
      'entity_id' => [
        [
          'value' => 5,
        ],
      ],
      'locked' => [
        [
          'value' => 0,
        ],
      ],
      'sticky' => [
        [
          'value' => 0,
        ],
      ],
      'notes' => [],
    ], $this
      ->getImportantEntityProperties($webform_submission));

    // Webform submission data.
    $data = $webform_submission
      ->getData();
    $this
      ->assertEquals([
      'brewing_styles' => [
        'pour_over',
        'espresso',
      ],
      'drinks' => [
        'macchiato',
        'long_macchiato',
        'cortado',
        'affogato',
      ],
    ], $data);
  }

  /**
   * Filters out unconcerned properties from an entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   An entity instance.
   *
   * @return array
   *   The important entity property values as array.
   */
  protected function getImportantEntityProperties(EntityInterface $entity) {
    $entity_type_id = $entity
      ->getEntityTypeId();
    $exploded = explode('_', $entity_type_id);
    $prop_prefix = count($exploded) > 1 ? $exploded[0] . implode('', array_map('ucfirst', array_slice($exploded, 1))) : $entity_type_id;
    $property_filter_preset_property = "{$prop_prefix}UnconcernedProperties";
    $entity_array = $entity
      ->toArray();
    $unconcerned_properties = property_exists(get_class($this), $property_filter_preset_property) ? $this->{$property_filter_preset_property} : [
      'uuid',
      'langcode',
      'dependencies',
      '_core',
    ];
    foreach ($unconcerned_properties as $item) {
      unset($entity_array[$item]);
    }
    return $entity_array;
  }

}

Traits

Namesort descending Description
WebformMigrateAssertionsTrait Trait for webform migration tests.