Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/API_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ Returns the requested question and options of the given form (without submission
| _formId_ | Integer | ID of the form |
| _questionId_ | Integer | ID of the question |
- Response: An object of the requested question including options.
A deleted question gets a **Not Found** response.

```
"data": {
Expand Down
3 changes: 2 additions & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public function getQuestions(int $formId): DataResponse {
* @return DataResponse<Http::STATUS_OK, FormsQuestion, array{}>
* @throws OCSBadRequestException Question doesn\'t belong to given Form
* @throws OCSForbiddenException User has no permissions to get this form
* @throws OCSNotFoundException Question doesn\'t exist
* @throws OCSNotFoundException Could not find form
*
* 200: the requested question
Expand All @@ -469,7 +470,7 @@ public function getQuestion(int $formId, int $questionId): DataResponse {
}

$question = $this->formsService->getQuestion($questionId);
if ($question === null) {
if ($question === null || $question['order'] === 0) {
throw new OCSNotFoundException('Question doesn\'t exist');
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,23 @@ public function testUpdateFormRejectsInvalidConfirmationEmailQuestionId(string $
$this->apiController->updateForm(1, ['confirmationEmailQuestionId' => 7]);
}

public function testGetDeletedQuestion(): void {
$form = new Form();
$form->setId(1);
$this->formMapper->method('findById')
->with(1)
->willReturn($form);
$this->formsService->method('hasUserAccess')
->with($form)
->willReturn(true);
$this->formsService->method('getQuestion')
->with(2)
->willReturn(['id' => 2, 'formId' => 1, 'order' => 0, 'text' => 'Deleted', 'extraSettings' => []]);

$this->expectException(OCSNotFoundException::class);
$this->apiController->getQuestion(1, 2);
}

public function testUpdateQuestionRejectsTypeChange(): void {
$form = new Form();
$form->setId(1);
Expand Down
Loading