WebformRestCompleteSubmissionTest.php in Webform REST 4.x
File
tests/src/Functional/WebformRestCompleteSubmissionTest.php
View source
<?php
namespace Drupal\Tests\webform_rest\Functional;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\Component\Serialization\Json;
class WebformRestCompleteSubmissionTest extends WebformBrowserTestBase {
public static $modules = [
'webform',
'webform_rest',
'webform_rest_test',
];
protected static $testWebforms = [
'webform_rest_test',
];
public function testWebformRestGetCompleteSubmission() {
$this
->drupalLogin($this->rootUser);
$webform = Webform::load('webform_rest_test');
$sid = $this
->postSubmission($webform, [
'first_name' => 'John',
'last_name' => 'Smith',
]);
$webform_submission = WebformSubmission::load($sid);
$uuid = $webform_submission
->uuid();
$result = $this
->drupalGet("/webform_rest/webform_rest_test/complete_submission/{$uuid}", [
'query' => [
'_format' => 'hal_json',
],
]);
$created_response = Json::decode((string) $result);
$this
->assertResponse(200);
$this
->assertRaw('"title":"Test: Webform rest"');
$this
->assertRaw('"first_name":{"#title":"First name"');
$this
->assertRaw('"last_name":{"#title":"Last name"');
$this
->assertArrayHasKey('processed_submission', $created_response);
$this
->assertArrayHasKey('first_name', $created_response['processed_submission']);
$this
->assertArrayHasKey('last_name', $created_response['processed_submission']);
$this
->assertArrayHasKey('value', $created_response['processed_submission']['first_name']);
$this
->assertArrayHasKey('value', $created_response['processed_submission']['last_name']);
$this
->assertEquals('John', $created_response['processed_submission']['first_name']['value']);
$this
->assertEquals('Smith', $created_response['processed_submission']['last_name']['value']);
}
}