WebformExampleCompositeTest.php in Webform 8.5
File
modules/webform_example_composite/tests/src/Functional/WebformExampleCompositeTest.php
View source
<?php
namespace Drupal\Tests\webform_example_composite\Functional;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformExampleCompositeTest extends WebformBrowserTestBase {
public static $modules = [
'webform_example_composite',
];
public function testWebformExampleComposite() {
$webform = Webform::load('webform_example_composite');
$this
->drupalGet('/webform/webform_example_composite');
$this
->assertRaw('<label for="edit-webform-example-composite-first-name">First name</label>');
$this
->assertFieldById('edit-webform-example-composite-first-name');
$this
->assertRaw('<label for="edit-webform-example-composite-last-name">Last name</label>');
$this
->assertFieldById('edit-webform-example-composite-last-name');
$this
->assertRaw('<label for="edit-webform-example-composite-date-of-birth">Date of birth</label>');
$this
->assertFieldById('edit-webform-example-composite-date-of-birth');
$this
->assertRaw('<label for="edit-webform-example-composite-gender">Gender</label>');
$this
->assertFieldById('edit-webform-example-composite-gender');
$edit = [
'webform_example_composite[first_name]' => 'John',
'webform_example_composite[last_name]' => 'Smith',
'webform_example_composite[gender]' => 'Male',
'webform_example_composite[date_of_birth]' => '1910-01-01',
'webform_example_composite_multiple[items][0][first_name]' => 'Jane',
'webform_example_composite_multiple[items][0][last_name]' => 'Doe',
'webform_example_composite_multiple[items][0][gender]' => 'Female',
'webform_example_composite_multiple[items][0][date_of_birth]' => '1920-12-01',
];
$sid = $this
->postSubmission($webform, $edit);
$webform_submission = WebformSubmission::load($sid);
$this
->assertEqual($webform_submission
->getElementData('webform_example_composite'), [
'first_name' => 'John',
'last_name' => 'Smith',
'gender' => 'Male',
'date_of_birth' => '1910-01-01',
]);
$this
->assertEqual($webform_submission
->getElementData('webform_example_composite_multiple'), [
[
'first_name' => 'Jane',
'last_name' => 'Doe',
'gender' => 'Female',
'date_of_birth' => '1920-12-01',
],
]);
}
}