Skip to content

Commit

Permalink
add integration test testUpdateSubmission
Browse files Browse the repository at this point in the history
Signed-off-by: Timotheus Pokorra <[email protected]>
  • Loading branch information
tpokorra committed Jan 9, 2025
1 parent ca947b5 commit 19cd709
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/Integration/Api/ApiV3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private function setTestForms() {
'state' => 0,
'is_anonymous' => false,
'submit_multiple' => false,
'allow_edit' => true,
'show_expiration' => false,
'last_updated' => 123456789,
'submission_message' => 'Back to website',
Expand Down Expand Up @@ -164,6 +165,7 @@ private function setTestForms() {
'state' => 0,
'is_anonymous' => false,
'submit_multiple' => false,
'allow_edit' => true,
'show_expiration' => false,
'last_updated' => 123456789,
'submission_message' => '',
Expand Down Expand Up @@ -201,6 +203,7 @@ private function setTestForms() {
'state' => 0,
'is_anonymous' => false,
'submit_multiple' => false,
'allow_edit' => true,
'show_expiration' => false,
'last_updated' => 123456789,
'submission_message' => '',
Expand Down Expand Up @@ -1349,6 +1352,85 @@ public function testNewSubmission() {
], $data['submissions'][0]);
}

/**
* @dataProvider dataNewSubmission
*/
public function testUpdateSubmission() {

$uploadedFileResponse = $this->http->request('PUT',
"api/v3/forms/{$this->testForms[0]['id']}/submissions/files/{$this->testForms[0]['questions'][2]['id']}",
[
'multipart' => [
[
'name' => 'files[]',
'contents' => 'hello world2',
'filename' => 'test2.txt'
]
]
]);

$data = $this->OcsResponse2Data($uploadedFileResponse);
$uploadedFileId = $data[0]['uploadedFileId'];

$resp = $this->http->request('PUT', "api/v3/forms/{$this->testForms[0]['id']}/submissions/{$this->testForms[0]['submissions'][0]['id']}", [
'json' => [
'answers' => [
$this->testForms[0]['questions'][0]['id'] => ['ShortAnswer!2'],
$this->testForms[0]['questions'][1]['id'] => [
$this->testForms[0]['questions'][1]['options'][1]['id']
],
$this->testForms[0]['questions'][2]['id'] => [['uploadedFileId' => $uploadedFileId]]
]
]
]);
$data = $this->OcsResponse2Data($resp);

$this->assertEquals(200, $resp->getStatusCode());

// Check stored submissions
$resp = $this->http->request('GET', "api/v3/forms/{$this->testForms[0]['id']}/submissions");
$data = $this->OcsResponse2Data($resp);

// Check Ids
foreach ($data['submissions'][0]['answers'] as $aIndex => $answer) {
$this->assertEquals($data['submissions'][0]['id'], $answer['submissionId']);
unset($data['submissions'][0]['answers'][$aIndex]['id']);
unset($data['submissions'][0]['answers'][$aIndex]['submissionId']);

if (isset($answer['fileId'])) {
$this->assertIsNumeric($answer['fileId'], 'fileId should be numeric.');
$this->assertGreaterThan(0, $answer['fileId'], 'fileId should be greater than 0.');
unset($data['submissions'][0]['answers'][$aIndex]['fileId']);
}
}
unset($data['submissions'][0]['id']);
// Check general behaviour of timestamp (Insert in the last 10 seconds)
$this->assertTrue(time() - $data['submissions'][0]['timestamp'] < 10);
unset($data['submissions'][0]['timestamp']);

$this->assertEquals([
'userId' => 'test',
'userDisplayName' => 'Test Displayname',
'formId' => $this->testForms[0]['id'],
'answers' => [
[
'questionId' => $this->testForms[0]['questions'][0]['id'],
'text' => 'ShortAnswer2!',
'fileId' => null,
],
[
'questionId' => $this->testForms[0]['questions'][1]['id'],
'text' => 'Option 2',
'fileId' => null,
],
[
'questionId' => $this->testForms[0]['questions'][2]['id'],
'text' => 'test2.txt',
],
]
], $data['submissions'][0]);
}

public function dataDeleteSingleSubmission() {
$submissionsExpected = $this->dataGetSubmissions()['getSubmissions']['expected'];
array_splice($submissionsExpected['submissions'], 0, 1);
Expand Down

0 comments on commit 19cd709

Please sign in to comment.