16
16
*/
17
17
class AnonymousQuestionTest extends TestCase
18
18
{
19
+ /**
20
+ * Open the current semester's evaluation form;
21
+ * with start and end dates close to the current time.
22
+ */
23
+ public static function openForm (): void
24
+ {
25
+ app (\App \Http \Controllers \Secretariat \SemesterEvaluationController::class)
26
+ ->updatePeriodicEvent (
27
+ Semester::current (),
28
+ Carbon::now ()->subMinute (1 ),
29
+ Carbon::now ()->addMinute (20 )
30
+ );
31
+ }
32
+
33
+ /**
34
+ * Close the current semester's evaluation form
35
+ * by giving a start date after the current time.
36
+ */
37
+ public static function delayForm (): void
38
+ {
39
+ app (\App \Http \Controllers \Secretariat \SemesterEvaluationController::class)
40
+ ->updatePeriodicEvent (
41
+ Semester::current (),
42
+ Carbon::now ()->addMinute (10 ),
43
+ Carbon::now ()->addMinute (11 )
44
+ );
45
+ }
46
+
47
+
19
48
/**
20
49
* Tests answering a question belonging to an already closed semester
21
50
* (which should fail).
@@ -39,6 +68,31 @@ public function test_answering_closed_question(): void
39
68
);
40
69
}
41
70
71
+ /**
72
+ * Tests answering a question belonging to the current semester
73
+ * but before the start date of the evaluation form
74
+ * (which should fail).
75
+ * @return void
76
+ */
77
+ public function test_answering_not_yet_opened_question (): void
78
+ {
79
+ $ user = User::factory ()->hasEducationalInformation ()->create ();
80
+
81
+ self ::delayForm ();
82
+ $ semester = Semester::current ();
83
+ $ question = Question::factory ()
84
+ ->for ($ semester , 'parent ' )
85
+ ->hasOptions (3 )
86
+ ->create (['opened_at ' => now ()->subDay (), 'closed_at ' => null ]);
87
+
88
+ $ this ->expectException (\Exception::class);
89
+ $ question ->giveAnonymousAnswer (
90
+ $ user ,
91
+ AnswerSheet::createForUser ($ user , $ semester ),
92
+ $ question ->options ->first ()
93
+ );
94
+ }
95
+
42
96
/**
43
97
* Tests answering the same question twice as the same user
44
98
* (which should fail).
@@ -48,6 +102,7 @@ public function test_answering_twice(): void
48
102
{
49
103
$ user = User::factory ()->hasEducationalInformation ()->create ();
50
104
105
+ self ::openForm ();
51
106
$ semester = Semester::current (); // gets created if does not already exist
52
107
$ question = Question::factory ()
53
108
->for ($ semester , 'parent ' )
@@ -70,6 +125,7 @@ public function test_answering_radio(): void
70
125
{
71
126
$ user = User::factory ()->hasEducationalInformation ()->create ();
72
127
128
+ self ::openForm ();
73
129
$ semester = Semester::current ();
74
130
$ question = Question::factory ()
75
131
->for ($ semester , 'parent ' )
@@ -116,6 +172,7 @@ public function test_answering_radio_with_more_options(): void
116
172
{
117
173
$ user = User::factory ()->hasEducationalInformation ()->create ();
118
174
175
+ self ::openForm ();
119
176
$ semester = Semester::current ();
120
177
$ question = Question::factory ()
121
178
->for ($ semester , 'parent ' )
@@ -138,6 +195,7 @@ public function test_voting_checkbox(): void
138
195
{
139
196
$ user = User::factory ()->hasEducationalInformation ()->create ();
140
197
198
+ self ::openForm ();
141
199
$ semester = Semester::current ();
142
200
$ question = Question::factory ()
143
201
->for ($ semester , 'parent ' )
@@ -194,6 +252,7 @@ public function test_voting_checkbox_with_more_options(): void
194
252
{
195
253
$ user = User::factory ()->hasEducationalInformation ()->create ();
196
254
255
+ self ::openForm ();
197
256
$ semester = Semester::current ();
198
257
$ question = Question::factory ()
199
258
->for ($ semester , 'parent ' )
0 commit comments