Skip to content

Commit 6e2dec4

Browse files
committed
Fixing tests
1 parent dccec31 commit 6e2dec4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/Unit/AnonymousQuestionTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@
1616
*/
1717
class AnonymousQuestionTest extends TestCase
1818
{
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+
1948
/**
2049
* Tests answering a question belonging to an already closed semester
2150
* (which should fail).
@@ -39,6 +68,31 @@ public function test_answering_closed_question(): void
3968
);
4069
}
4170

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+
4296
/**
4397
* Tests answering the same question twice as the same user
4498
* (which should fail).
@@ -48,6 +102,7 @@ public function test_answering_twice(): void
48102
{
49103
$user = User::factory()->hasEducationalInformation()->create();
50104

105+
self::openForm();
51106
$semester = Semester::current(); // gets created if does not already exist
52107
$question = Question::factory()
53108
->for($semester, 'parent')
@@ -70,6 +125,7 @@ public function test_answering_radio(): void
70125
{
71126
$user = User::factory()->hasEducationalInformation()->create();
72127

128+
self::openForm();
73129
$semester = Semester::current();
74130
$question = Question::factory()
75131
->for($semester, 'parent')
@@ -116,6 +172,7 @@ public function test_answering_radio_with_more_options(): void
116172
{
117173
$user = User::factory()->hasEducationalInformation()->create();
118174

175+
self::openForm();
119176
$semester = Semester::current();
120177
$question = Question::factory()
121178
->for($semester, 'parent')
@@ -138,6 +195,7 @@ public function test_voting_checkbox(): void
138195
{
139196
$user = User::factory()->hasEducationalInformation()->create();
140197

198+
self::openForm();
141199
$semester = Semester::current();
142200
$question = Question::factory()
143201
->for($semester, 'parent')
@@ -194,6 +252,7 @@ public function test_voting_checkbox_with_more_options(): void
194252
{
195253
$user = User::factory()->hasEducationalInformation()->create();
196254

255+
self::openForm();
197256
$semester = Semester::current();
198257
$question = Question::factory()
199258
->for($semester, 'parent')

0 commit comments

Comments
 (0)