You are here

function webform_test_submissions_install in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/modules/webform_test_submissions/webform_test_submissions.install \webform_test_submissions_install()

Implements hook_install().

File

tests/modules/webform_test_submissions/webform_test_submissions.install, line 16
Install, update and uninstall functions for the Webform Test Exporter module.

Code

function webform_test_submissions_install() {

  // Create 'webform_test_submissions' content-type.
  if (!NodeType::load('webform_test_submissions')) {
    $node_type = NodeType::create([
      'type' => 'webform_test_submissions',
      'name' => 'Webform Test Submissions',
    ]);
    $node_type
      ->save();
  }

  // Create three 'webform_test_submissions' nodes.
  $nodes = [];
  for ($i = 0; $i < 3; $i++) {
    $node = Node::create([
      'body' => [
        [
          'value' => '{Body}',
          'format' => filter_default_format(),
        ],
      ],
      'title' => 'Node ' . $i,
      'type' => 'webform_test_submissions',
      'uid' => 0,
      'status' => NodeInterface::PUBLISHED,
    ]);
    $node
      ->save();
    $nodes[$i] = $node
      ->id();
  }

  // Create 'webform_test_submissions' submissions.
  $records = [
    [
      'created' => strtotime('2000-01-01'),
      'data' => [
        'first_name' => 'George',
        'last_name' => 'Washington',
        'sex' => 'Male',
        'dob' => '1732-02-22',
        'node' => $nodes[0],
        'colors' => [
          'white',
        ],
        'likert' => [
          'q1' => 1,
          'q2' => 1,
          'q3' => 1,
        ],
        'address' => [
          'address' => 'quotes\' "',
          'city' => 'html <markup>',
          'state_province' => 'New York',
          'country' => 'United States',
          'postal_code' => '11111-1111',
        ],
      ],
    ],
    [
      'created' => strtotime('2001-01-01'),
      'data' => [
        'first_name' => 'Abraham',
        'last_name' => 'Lincoln',
        'sex' => 'Male',
        'dob' => '1809-02-12',
        'node' => $nodes[1],
        'colors' => [
          'red',
          'white',
          'blue',
        ],
        'likert' => [
          'q1' => 2,
          'q2' => 2,
          'q3' => 2,
        ],
        'address' => [
          'address' => '{Address}',
          'city' => '{City}',
          'state_province' => 'New York',
          'country' => 'United States',
          'postal_code' => '11111-1111',
        ],
      ],
    ],
    [
      'created' => strtotime('2002-01-01'),
      'data' => [
        'first_name' => 'Hillary',
        'last_name' => 'Clinton',
        'sex' => 'Female',
        'dob' => '1947-10-26',
        'node' => $nodes[2],
        'colors' => [
          'red',
        ],
        'likert' => [
          'q1' => 2,
          'q2' => 2,
          'q3' => 2,
        ],
        'address' => [
          'address' => '{Address}',
          'city' => '{City}',
          'state_province' => 'New York',
          'country' => 'United States',
          'postal_code' => '11111-1111',
        ],
      ],
    ],
    [
      'created' => strtotime('2002-01-02'),
      'data' => [
        'first_name' => 'quotes\' "',
        'last_name' => 'html <markup>',
        'sex' => 'Female',
        'dob' => '1947-10-26',
        'node' => $nodes[2],
        'colors' => [
          'red',
        ],
        'likert' => [
          'q1' => 2,
          'q2' => 2,
          'q3' => 2,
        ],
        'address' => [
          'address' => '{Address}',
          'city' => '{City}',
          'state_province' => 'New York',
          'country' => 'United States',
          'postal_code' => '11111-1111',
        ],
      ],
    ],
  ];
  foreach ($records as $record) {
    $values = [
      'webform_id' => 'test_submissions',
      'uid' => 0,
    ] + $record;
    WebformSubmission::create($values)
      ->save();
  }
}