Skip to content

Commit d5e4b22

Browse files
committed
add unit test testGetFormAllowEditWithoutAnswers
Signed-off-by: Timotheus Pokorra <[email protected]>
1 parent 968a905 commit d5e4b22

File tree

1 file changed

+98
-3
lines changed

1 file changed

+98
-3
lines changed

tests/Unit/Service/FormsServiceTest.php

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function microtime(bool|float $asFloat = false) {
4444
use OCA\Forms\Db\ShareMapper;
4545
use OCA\Forms\Db\Submission;
4646
use OCA\Forms\Db\SubmissionMapper;
47-
use OCA\Forms\Service\AnswerService;
4847
use OCA\Forms\Service\CirclesService;
4948
use OCA\Forms\Service\ConfigService;
5049
use OCA\Forms\Service\FormsService;
@@ -356,7 +355,7 @@ public function testGetForm(array $expected) {
356355

357356
public function dataGetFormWithAnswers() {
358357
return [
359-
// Just the full form with Answers
358+
// Just the full form with answers for AllowEdit
360359
'one-full-form-with-answers' => [[
361360
'id' => 42,
362361
'state' => 0,
@@ -439,7 +438,7 @@ public function dataGetFormWithAnswers() {
439438
*
440439
* @param array $expected
441440
*/
442-
public function testGetFormWithAnswers(array $expected) {
441+
public function testGetFormAllowEditWithAnswers(array $expected) {
443442
// The form, with AllowEdit
444443
$form = new Form();
445444
$form->setId(42);
@@ -536,6 +535,102 @@ public function testGetFormWithAnswers(array $expected) {
536535
$this->assertEquals($expected, $this->formsService->getForm($form));
537536
}
538537

538+
/**
539+
* @dataProvider dataGetFormWithAnswers
540+
*
541+
* @param array $expected
542+
*/
543+
public function testGetFormAllowEditWithoutAnswers(array $expected) {
544+
// drop the answers for this test
545+
unset($expected['answers']);
546+
unset($expected['newSubmission']);
547+
unset($expected['submissionId']);
548+
549+
// The form, with AllowEdit
550+
$form = new Form();
551+
$form->setId(42);
552+
$form->setState(0); // default => 0 means active
553+
$form->setHash('abcdefg');
554+
$form->setTitle('Form 1');
555+
$form->setDescription('Description Text');
556+
$form->setOwnerId('currentUser');
557+
$form->setCreated(123456789);
558+
$form->setAccess([
559+
'permitAllUsers' => false,
560+
'showToAllUsers' => false,
561+
]);
562+
$form->setExpires(0);
563+
$form->setIsAnonymous(false);
564+
$form->setSubmitMultiple(false);
565+
$form->setAllowEdit(true);
566+
$form->setShowExpiration(false);
567+
$form->setLastUpdated(123456789);
568+
569+
$submission = new Submission();
570+
$submission->setId(12);
571+
572+
// Questions
573+
$question1 = new Question();
574+
$question1->setId(1);
575+
$question1->setFormId(42);
576+
$question1->setOrder(1);
577+
$question1->setType('dropdown');
578+
$question1->setIsRequired(false);
579+
$question1->setExtraSettings([
580+
'shuffleOptions' => true
581+
]);
582+
$question1->setText('Question 1');
583+
$question1->setDescription('This is our first question.');
584+
$question2 = new Question();
585+
$question2->setId(2);
586+
$question2->setFormId(42);
587+
$question2->setOrder(2);
588+
$question2->setType('short');
589+
$question2->setIsRequired(true);
590+
$question2->setText('Question 2');
591+
$question2->setDescription('');
592+
$question2->setName('city');
593+
$question2->setExtraSettings([]);
594+
$this->questionMapper->expects($this->once())
595+
->method('findByForm')
596+
->with(42)
597+
->willReturn([$question1, $question2]);
598+
599+
// Options
600+
$option1 = new Option();
601+
$option1->setId(1);
602+
$option1->setQuestionId(1);
603+
$option1->setText('Option 1');
604+
$option2 = new Option();
605+
$option2->setId(2);
606+
$option2->setQuestionId(1);
607+
$option2->setText('Option 2');
608+
$this->optionMapper->expects($this->any())
609+
->method('findByQuestion')
610+
->with(1)
611+
->willReturn([$option1, $option2]);
612+
613+
$answers = [ ];
614+
615+
$this->submissionMapper->expects($this->once())
616+
->method('findByFormAndUser')
617+
->with(42, 'currentUser')
618+
->willReturn($submission);
619+
620+
$this->answerMapper->expects($this->once())
621+
->method('findBySubmission')
622+
->with(12)
623+
->willReturn($answers);
624+
625+
$this->submissionMapper->expects($this->once())
626+
->method('countSubmissions')
627+
->with(42)
628+
->willReturn(123);
629+
630+
// Run the test
631+
$this->assertEquals($expected, $this->formsService->getForm($form));
632+
}
633+
539634
public function dataGetPartialForm() {
540635
return [
541636
'onePartialOwnedForm' => [[

0 commit comments

Comments
 (0)