You are here

protected function YamlFormTestTrait::createYamlFormWithSubmissions in YAML Form 8

Create a form with submissions.

Return value

array Array containing the form and submissions.

6 calls to YamlFormTestTrait::createYamlFormWithSubmissions()
YamlFormAccessTest::testAccessRules in src/Tests/YamlFormAccessTest.php
Tests form access rules.
YamlFormResultsExportTest::testExportOptions in src/Tests/YamlFormResultsExportTest.php
Tests export options.
YamlFormSubmissionAccessTest::testAccess in src/Tests/YamlFormSubmissionAccessTest.php
Tests form submission access.
YamlFormSubmissionListBuilderTest::testResults in src/Tests/YamlFormSubmissionListBuilderTest.php
Tests results.
YamlFormSubmissionTest::testYamlFormSubmission in src/Tests/YamlFormSubmissionTest.php
Tests form submission entity.

... See full list

File

src/Tests/YamlFormTestTrait.php, line 311

Class

YamlFormTestTrait
Defines form test trait.

Namespace

Drupal\yamlform\Tests

Code

protected function createYamlFormWithSubmissions() {
  $yamlform = $this
    ->createYamlForm();
  $nodes = $this
    ->getNodes();

  // Create some submissions.
  $names = [
    [
      'George',
      'Washington',
      'Male',
      '1732-02-22',
      $nodes[0],
      [
        'white',
      ],
      [
        'q1' => 1,
        'q2' => 1,
        'q3' => 1,
      ],
      [
        'address' => '{Address}',
        'city' => '{City}',
        'state_province' => 'New York',
        'country' => 'United States',
        'postal_code' => '11111-1111',
      ],
    ],
    [
      'Abraham',
      'Lincoln',
      'Male',
      '1809-02-12',
      $nodes[1],
      [
        'red',
        'white',
        'blue',
      ],
      [
        'q1' => 2,
        'q2' => 2,
        'q3' => 2,
      ],
      [
        'address' => '{Address}',
        'city' => '{City}',
        'state_province' => 'New York',
        'country' => 'United States',
        'postal_code' => '11111-1111',
      ],
    ],
    [
      'Hillary',
      'Clinton',
      'Female',
      '1947-10-26',
      $nodes[2],
      [
        'red',
      ],
      [
        'q1' => 2,
        'q2' => 2,
        'q3' => 2,
      ],
      [
        'address' => '{Address}',
        'city' => '{City}',
        'state_province' => 'New York',
        'country' => 'United States',
        'postal_code' => '11111-1111',
      ],
    ],
  ];
  $sids = [];
  foreach ($names as $name) {
    $edit = [
      'first_name' => $name[0],
      'last_name' => $name[1],
      'sex' => $name[2],
      'dob' => $name[3],
      'node' => $name[4]
        ->label() . ' (' . $name[4]
        ->id() . ')',
    ];
    foreach ($name[5] as $color) {
      $edit["colors[{$color}]"] = $color;
    }
    foreach ($name[6] as $question => $answer) {
      $edit["likert[{$question}]"] = $answer;
    }
    foreach ($name[7] as $composite_key => $composite_value) {
      $edit["address[{$composite_key}]"] = $composite_value;
    }
    $sids[] = $this
      ->postSubmission($yamlform, $edit);
  }

  // Change array keys to index instead of using entity ids.
  $submissions = array_values(YamlFormSubmission::loadMultiple($sids));
  $this
    ->assert($yamlform instanceof YamlForm, 'YamlForm was created');
  $this
    ->assertEqual(count($submissions), 3, 'YamlFormSubmissions were created.');
  return [
    $yamlform,
    $submissions,
  ];
}