public function WebformRestSubmissionTest::testWebformRestPostSubmission in Webform REST 8.2
Same name and namespace in other branches
- 4.x tests/src/Functional/WebformRestSubmissionTest.php \Drupal\Tests\webform_rest\Functional\WebformRestSubmissionTest::testWebformRestPostSubmission()
Test method POST submission resource.
File
- tests/
src/ Functional/ WebformRestSubmissionTest.php, line 57
Class
- WebformRestSubmissionTest
- Test the webform rest endpoints for submissions.
Namespace
Drupal\Tests\webform_rest\FunctionalCode
public function testWebformRestPostSubmission() {
$webform = Webform::load('webform_rest_test');
$this
->drupalLogin($this->rootUser);
$body = [
'webform_id' => 'webform_rest_test',
'first_name' => 'John',
'last_name' => 'Smith',
];
$client = new Client();
$token = $this
->drupalGet("/session/token", [
'query' => [
'_format' => 'hal_json',
],
]);
$response = $this
->request('POST', $this->baseUrl . '/webform_rest/submit?_format=json', [
'body' => Json::encode($body),
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-CSRF-Token' => $token,
],
]);
$created_response = Json::decode((string) $response
->getBody());
$this
->assertResponse(200);
$this
->assertArrayHasKey('sid', $created_response);
$this
->assertNotEmpty($created_response['sid']);
}