Skip to content

Commit

Permalink
Added test for insertSubmission in ApiController
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Ilkiv <a.ilkiv.ye@gmail.com>
  • Loading branch information
AIlkiv committed Aug 31, 2023
1 parent 255c908 commit 870ed11
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Expand Up @@ -669,4 +669,67 @@ public function testInsertSubmission_answers() {

$this->apiController->insertSubmission(1, $answers, '');
}

public function testInsertSubmission_formNotFound() {
$exception = $this->createMock(MapperException::class);
$this->formMapper->expects($this->once())
->method('findById')
->with(1)
->willThrowException($exception);
$this->expectException(OCSBadRequestException::class);
$this->apiController->insertSubmission(1, [], '');
}

public function dataForCheckForbiddenException() {
return [
[false, true, true],
[true, true, true],
[true, false, false],
];
}

/**
* @dataProvider dataForCheckForbiddenException()
*/
public function testInsertSubmission_forbiddenException($hasUserAccess, $hasFormExpired, $canSubmit) {
$form = new Form();
$form->setId(1);

$this->formMapper->expects($this->once())
->method('findById')
->with(1)
->willReturn($form);

$this->formAccess($hasUserAccess, $hasFormExpired, $canSubmit);

$this->expectException(OCSForbiddenException::class);

$this->apiController->insertSubmission(1, [], '');
}

public function testInsertSubmission_validateSubmission() {
$form = new Form();
$form->setId(1);

$this->formMapper->expects($this->once())
->method('findById')
->with(1)
->willReturn($form);

$this->formsService->expects($this->once())
->method('getQuestions')
->with(1)
->willReturn([]);

$this->formAccess();

$this->submissionService
->method('validateSubmission')
->willReturn(false);

$this->expectException(OCSBadRequestException::class);

$this->apiController->insertSubmission(1, [], '');
}

}

0 comments on commit 870ed11

Please sign in to comment.