@@ -256,12 +256,7 @@ public function dataGetForm() {
256
256
];
257
257
}
258
258
259
- /**
260
- * @dataProvider dataGetForm
261
- *
262
- * @param array $expected
263
- */
264
- public function testGetForm (array $ expected ) {
259
+ private function prepareFormTest (bool $ withUserMock ) {
265
260
// The form
266
261
$ form = new Form ();
267
262
$ form ->setId (42 );
@@ -283,13 +278,15 @@ public function testGetForm(array $expected) {
283
278
284
279
// User & Group Formatting
285
280
$ user = $ this ->createMock (IUser::class);
286
- $ user ->expects ($ this ->once ())
287
- ->method ('getDisplayName ' )
288
- ->willReturn ('Some User ' );
289
- $ this ->userManager ->expects ($ this ->once ())
290
- ->method ('get ' )
291
- ->with ('someUser ' )
292
- ->willReturn ($ user );
281
+ if ($ withUserMock ) {
282
+ $ user ->expects ($ this ->once ())
283
+ ->method ('getDisplayName ' )
284
+ ->willReturn ('Some User ' );
285
+ $ this ->userManager ->expects ($ this ->once ())
286
+ ->method ('get ' )
287
+ ->with ('someUser ' )
288
+ ->willReturn ($ user );
289
+ }
293
290
294
291
// Questions
295
292
$ question1 = new Question ();
@@ -339,6 +336,30 @@ public function testGetForm(array $expected) {
339
336
$ share ->setShareWith ('someUser ' );
340
337
$ share ->setPermissions ([Constants::PERMISSION_SUBMIT ]);
341
338
339
+ $ answerEntity = new Answer ();
340
+ $ answerEntity ->setId (1 );
341
+ $ answerEntity ->setSubmissionId (12 );
342
+ $ answerEntity ->setFileId (112 );
343
+ $ answerEntity ->setQuestionId (1 );
344
+ $ answerEntity ->setText ('Option 1 ' );
345
+ $ answer2Entity = new Answer ();
346
+ $ answer2Entity ->setId (2 );
347
+ $ answer2Entity ->setSubmissionId (12 );
348
+ $ answer2Entity ->setQuestionId (2 );
349
+ $ answer2Entity ->setText ('London ' );
350
+ $ answers = [ $ answerEntity , $ answer2Entity ];
351
+
352
+ return [$ form , $ user , $ share , $ answers ];
353
+ }
354
+
355
+ /**
356
+ * @dataProvider dataGetForm
357
+ *
358
+ * @param array $expected
359
+ */
360
+ public function testGetForm (array $ expected ) {
361
+ [$ form , $ user , $ share , $ answers ] = $ this ->prepareFormTest (true );
362
+
342
363
$ this ->shareMapper ->expects ($ this ->any ())
343
364
->method ('findByForm ' )
344
365
->with (42 )
@@ -439,83 +460,15 @@ public function dataGetFormWithAnswers() {
439
460
* @param array $expected
440
461
*/
441
462
public function testGetFormAllowEditWithAnswers (array $ expected ) {
463
+ [$ form , $ user , $ share , $ answers ] = $ this ->prepareFormTest (false );
464
+
442
465
// The form, with AllowEdit
443
- $ form = new Form ();
444
- $ form ->setId (42 );
445
- $ form ->setState (0 ); // default => 0 means active
446
- $ form ->setHash ('abcdefg ' );
447
- $ form ->setTitle ('Form 1 ' );
448
- $ form ->setDescription ('Description Text ' );
449
- $ form ->setOwnerId ('currentUser ' );
450
- $ form ->setCreated (123456789 );
451
- $ form ->setAccess ([
452
- 'permitAllUsers ' => false ,
453
- 'showToAllUsers ' => false ,
454
- ]);
455
- $ form ->setExpires (0 );
456
- $ form ->setIsAnonymous (false );
457
466
$ form ->setSubmitMultiple (false );
458
467
$ form ->setAllowEdit (true );
459
- $ form ->setShowExpiration (false );
460
- $ form ->setLastUpdated (123456789 );
461
468
462
469
$ submission = new Submission ();
463
470
$ submission ->setId (12 );
464
471
465
- // Questions
466
- $ question1 = new Question ();
467
- $ question1 ->setId (1 );
468
- $ question1 ->setFormId (42 );
469
- $ question1 ->setOrder (1 );
470
- $ question1 ->setType ('dropdown ' );
471
- $ question1 ->setIsRequired (false );
472
- $ question1 ->setExtraSettings ([
473
- 'shuffleOptions ' => true
474
- ]);
475
- $ question1 ->setText ('Question 1 ' );
476
- $ question1 ->setDescription ('This is our first question. ' );
477
- $ question2 = new Question ();
478
- $ question2 ->setId (2 );
479
- $ question2 ->setFormId (42 );
480
- $ question2 ->setOrder (2 );
481
- $ question2 ->setType ('short ' );
482
- $ question2 ->setIsRequired (true );
483
- $ question2 ->setText ('Question 2 ' );
484
- $ question2 ->setDescription ('' );
485
- $ question2 ->setName ('city ' );
486
- $ question2 ->setExtraSettings ([]);
487
- $ this ->questionMapper ->expects ($ this ->once ())
488
- ->method ('findByForm ' )
489
- ->with (42 )
490
- ->willReturn ([$ question1 , $ question2 ]);
491
-
492
- // Options
493
- $ option1 = new Option ();
494
- $ option1 ->setId (1 );
495
- $ option1 ->setQuestionId (1 );
496
- $ option1 ->setText ('Option 1 ' );
497
- $ option2 = new Option ();
498
- $ option2 ->setId (2 );
499
- $ option2 ->setQuestionId (1 );
500
- $ option2 ->setText ('Option 2 ' );
501
- $ this ->optionMapper ->expects ($ this ->any ())
502
- ->method ('findByQuestion ' )
503
- ->with (1 )
504
- ->willReturn ([$ option1 , $ option2 ]);
505
-
506
- $ answerEntity = new Answer ();
507
- $ answerEntity ->setId (1 );
508
- $ answerEntity ->setSubmissionId (12 );
509
- $ answerEntity ->setFileId (112 );
510
- $ answerEntity ->setQuestionId (1 );
511
- $ answerEntity ->setText ('Option 1 ' );
512
- $ answer2Entity = new Answer ();
513
- $ answer2Entity ->setId (2 );
514
- $ answer2Entity ->setSubmissionId (12 );
515
- $ answer2Entity ->setQuestionId (2 );
516
- $ answer2Entity ->setText ('London ' );
517
- $ answers = [ $ answerEntity , $ answer2Entity ];
518
-
519
472
$ this ->submissionMapper ->expects ($ this ->once ())
520
473
->method ('findByFormAndUser ' )
521
474
->with (42 , 'currentUser ' )
@@ -540,87 +493,21 @@ public function testGetFormAllowEditWithAnswers(array $expected) {
540
493
*
541
494
* @param array $expected
542
495
*/
543
- public function testGetFormAllowEditWithoutAnswers (array $ expected ) {
544
- // drop the answers for this test
496
+ public function testGetFormAllowEditWithoutSubmission (array $ expected ) {
497
+ // drop the submissions and answers for this test
545
498
unset($ expected ['answers ' ]);
546
499
unset($ expected ['newSubmission ' ]);
547
500
unset($ expected ['submissionId ' ]);
501
+ [$ form , $ user , $ share , $ answers ] = $ this ->prepareFormTest (false );
548
502
549
503
// 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
504
$ form ->setSubmitMultiple (false );
565
505
$ 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
506
615
507
$ this ->submissionMapper ->expects ($ this ->once ())
616
508
->method ('findByFormAndUser ' )
617
509
->with (42 , 'currentUser ' )
618
- ->willReturn ($ submission );
619
-
620
- $ this ->answerMapper ->expects ($ this ->once ())
621
- ->method ('findBySubmission ' )
622
- ->with (12 )
623
- ->willReturn ($ answers );
510
+ ->willThrowException (new DoesNotExistException ('Test exception ' ));
624
511
625
512
$ this ->submissionMapper ->expects ($ this ->once ())
626
513
->method ('countSubmissions ' )
0 commit comments