Skip to content

Commit 3c1839d

Browse files
committed
PeriodicEventTest.php
1 parent 0664c44 commit 3c1839d

File tree

2 files changed

+207
-79
lines changed

2 files changed

+207
-79
lines changed

tests/Feature/EvaluationFormTest.php

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
use App\Http\Controllers\Secretariat\SemesterEvaluationController;
66
use App\Models\EducationalInformation;
7-
use App\Models\EventTrigger;
7+
use App\Models\PeriodicEvents\PeriodicEvent;
88
use App\Models\PersonalInformation;
99
use App\Models\Semester;
10+
use App\Models\SemesterEvaluation;
1011
use App\Models\User;
1112
use Illuminate\Foundation\Testing\RefreshDatabase;
1213
use Illuminate\Support\Facades\Config;
@@ -19,8 +20,6 @@
1920
*/
2021
class EvaluationFormTest extends TestCase
2122
{
22-
use RefreshDatabase;
23-
2423
/**
2524
* Helper function to create a user that has not filled in their status for the next semester.
2625
*/
@@ -40,7 +39,7 @@ private function createUser(): User
4039
*/
4140
private function assertFormAvailable()
4241
{
43-
$this->assertTrue(SemesterEvaluationController::isEvaluationAvailable());
42+
$this->assertTrue(SemesterEvaluation::isActive());
4443

4544
$response = $this->get('/secretariat/evaluation');
4645
$response->assertStatus(200);
@@ -55,7 +54,7 @@ private function assertFormAvailable()
5554
*/
5655
private function assertFormDoesNotAvailable()
5756
{
58-
$this->assertFalse(SemesterEvaluationController::isEvaluationAvailable());
57+
$this->assertFalse(SemesterEvaluation::isActive());
5958

6059
$response = $this->get('/secretariat/evaluation');
6160
$response->assertStatus(302);
@@ -66,78 +65,4 @@ private function assertFormDoesNotAvailable()
6665
$response->assertSessionMissing('message');
6766
}
6867

69-
/**
70-
* available < now() && now() < deadline
71-
*/
72-
public function testFormAccessible()
73-
{
74-
$this->createUser();
75-
76-
EventTrigger::find(EventTrigger::DEACTIVATE_STATUS_SIGNAL)->update(['date' => now()->addDays(1)]);
77-
EventTrigger::find(EventTrigger::SEMESTER_EVALUATION_AVAILABLE)->update(['date' => Semester::next()->getEndDate()->subMonth()]);
78-
Config::set('custom.semester_evaluation_deadline', null);
79-
80-
$this->assertFormAvailable();
81-
}
82-
83-
/**
84-
* if the deadline has not been updated, use the system_deadline
85-
*/
86-
public function testFormAvailableWithOldDeadline()
87-
{
88-
$this->createUser();
89-
90-
EventTrigger::find(EventTrigger::DEACTIVATE_STATUS_SIGNAL)->update(['date' => now()->addDays(2)]);
91-
EventTrigger::find(EventTrigger::SEMESTER_EVALUATION_AVAILABLE)->update(['date' => Semester::next()->getEndDate()->subMonth()]);
92-
Config::set('custom.semester_evaluation_deadline', Semester::previous()->getEndDate()->subDays(1));
93-
94-
$this->assertFormAvailable();
95-
}
96-
97-
98-
/**
99-
* available > now()
100-
*/
101-
public function testFormDoesNotAvailableYet()
102-
{
103-
$this->createUser();
104-
105-
EventTrigger::find(EventTrigger::DEACTIVATE_STATUS_SIGNAL)->update(['date' => now()->addDays(3)]);
106-
EventTrigger::find(EventTrigger::SEMESTER_EVALUATION_AVAILABLE)->update(['date' => now()->addDays(1)]);
107-
Config::set('custom.semester_evaluation_deadline', now()->addDays(2));
108-
109-
$this->assertFormDoesNotAvailable();
110-
}
111-
112-
113-
114-
/**
115-
* deadline < now()
116-
*/
117-
public function testDeadlinePassed()
118-
{
119-
$this->createUser();
120-
121-
EventTrigger::find(EventTrigger::DEACTIVATE_STATUS_SIGNAL)->update(['date' => now()->addDays(3)]);
122-
EventTrigger::find(EventTrigger::SEMESTER_EVALUATION_AVAILABLE)->update(['date' => now()->subDays(2)]);
123-
Config::set('custom.semester_evaluation_deadline', now()->subDays(1));
124-
125-
$this->assertFormDoesNotAvailable();
126-
127-
}
128-
/**
129-
* custom deadline < now()
130-
*/
131-
public function testCustomDeadlinePassed()
132-
{
133-
$this->createUser();
134-
135-
EventTrigger::find(EventTrigger::DEACTIVATE_STATUS_SIGNAL)->update(['date' => now()->addDays(3)]);
136-
EventTrigger::find(EventTrigger::SEMESTER_EVALUATION_AVAILABLE)->update(['date' => now()->addDays(5)]);
137-
Config::set('custom.semester_evaluation_deadline', now()->subDays(1));
138-
139-
$this->assertFormDoesNotAvailable();
140-
141-
}
142-
14368
}

tests/Feature/PeriodicEventTest.php

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Http\Controllers\Auth\ApplicationController;
6+
use App\Http\Controllers\Secretariat\SemesterEvaluationController;
7+
use App\Models\PeriodicEvents\PeriodicEvent;
8+
use App\Models\Semester;
9+
use Illuminate\Foundation\Testing\RefreshDatabase;
10+
use Tests\TestCase;
11+
12+
class PeriodicEventTest extends TestCase
13+
{
14+
use RefreshDatabase;
15+
16+
/**
17+
* start < now < end
18+
*/
19+
public function test_get_periodic_event(): void
20+
{
21+
PeriodicEvent::create([
22+
'event_model' => ApplicationController::class,
23+
'start_date' => now()->subDay(),
24+
'end_date' => now()->addDay(),
25+
]);
26+
27+
$event = ApplicationController::periodicEvent();
28+
29+
$this->assertNotNull($event);
30+
$this->assertTrue($event->isActive());
31+
$this->assertFalse($event->isExtended());
32+
$this->assertEquals($event->end_date, $event->real_end_date);
33+
34+
35+
$this->assertNull(SemesterEvaluationController::periodicEvent());
36+
}
37+
38+
/**
39+
* start < end < now
40+
*/
41+
public function test_get_periodic_event_passed(): void
42+
{
43+
PeriodicEvent::create([
44+
'event_model' => ApplicationController::class,
45+
'start_date' => now()->subDays(2),
46+
'end_date' => now()->subDay(),
47+
]);
48+
49+
$event = ApplicationController::periodicEvent();
50+
$this->assertNull($event);
51+
52+
}
53+
54+
/**
55+
* start < end < now < show_until
56+
*/
57+
public function test_get_periodic_event_passed_showed(): void
58+
{
59+
PeriodicEvent::create([
60+
'event_model' => ApplicationController::class,
61+
'start_date' => now()->subDays(2),
62+
'end_date' => now()->subDay(),
63+
'show_until' => now()->addDay()
64+
]);
65+
66+
$event = ApplicationController::periodicEvent();
67+
68+
$this->assertNotNull($event);
69+
$this->assertFalse($event->isActive());
70+
$this->assertFalse($event->isExtended());
71+
$this->assertEquals($event->end_date, $event->real_end_date);
72+
73+
}
74+
75+
/**
76+
* start < end < now < extended_end
77+
*/
78+
public function test_get_periodic_event_passed_extended(): void
79+
{
80+
PeriodicEvent::create([
81+
'event_model' => ApplicationController::class,
82+
'start_date' => now()->subDays(2),
83+
'end_date' => now()->subDay(),
84+
'extended_end_date' => now()->addDay()
85+
]);
86+
87+
$event = ApplicationController::periodicEvent();
88+
89+
$this->assertNotNull($event);
90+
$this->assertTrue($event->isActive());
91+
$this->assertTrue($event->isExtended());
92+
$this->assertEquals($event->extended_end_date, $event->real_end_date);
93+
}
94+
95+
/**
96+
* start < end < extended_end < now
97+
*/
98+
public function test_get_periodic_event_passed_extended_passed(): void
99+
{
100+
PeriodicEvent::create([
101+
'event_model' => ApplicationController::class,
102+
'start_date' => now()->subDays(3),
103+
'end_date' => now()->subDays(2),
104+
'extended_end_date' => now()->subDay()
105+
]);
106+
107+
$this->assertNull(ApplicationController::periodicEvent());
108+
}
109+
110+
/**
111+
* start < end < extended_end < now < show_until
112+
*/
113+
public function test_get_periodic_event_passed_extended_passed_showed(): void
114+
{
115+
PeriodicEvent::create([
116+
'event_model' => ApplicationController::class,
117+
'start_date' => now()->subDays(3),
118+
'end_date' => now()->subDays(2),
119+
'extended_end_date' => now()->subDay(),
120+
'show_until' => now()->addDay()
121+
]);
122+
123+
$event = ApplicationController::periodicEvent();
124+
125+
$this->assertNotNull($event);
126+
$this->assertFalse($event->isActive());
127+
$this->assertTrue($event->isExtended());
128+
$this->assertEquals($event->extended_end_date, $event->real_end_date);
129+
}
130+
131+
/**
132+
* now < start < end
133+
*/
134+
public function test_get_periodic_event_future(): void
135+
{
136+
PeriodicEvent::create([
137+
'event_model' => ApplicationController::class,
138+
'start_date' => now()->addDay(),
139+
'end_date' => now()->addDay(),
140+
]);
141+
142+
$event = ApplicationController::periodicEvent();
143+
144+
$this->assertNotNull($event);
145+
$this->assertFalse($event->isActive());
146+
}
147+
148+
/**
149+
* get latest event based on start date
150+
*/
151+
public function test_get_latest_event(): void
152+
{
153+
PeriodicEvent::create([
154+
'event_model' => ApplicationController::class,
155+
'start_date' => now()->subDays(3),
156+
'end_date' => now()->addDays(2),
157+
]);
158+
PeriodicEvent::create([
159+
'event_model' => ApplicationController::class,
160+
'start_date' => now()->subDay(),
161+
'end_date' => now()->addDay(),
162+
]);
163+
PeriodicEvent::create([
164+
'event_model' => SemesterEvaluationController::class,
165+
'start_date' => now()->addDay(),
166+
'end_date' => now()->addDay(),
167+
]);
168+
169+
$event = ApplicationController::periodicEvent();
170+
171+
$this->assertEquals(now()->subDay()->format('Y-m-d'), $event->start_date->format('Y-m-d'));
172+
$this->assertEquals(now()->addDay()->format('Y-m-d'), $event->end_date->format('Y-m-d'));
173+
}
174+
175+
/**
176+
* test event creation, if current event exists it is overridden
177+
*/
178+
public function test_creeta_event(): void
179+
{
180+
$this->actingAs($this->admin);
181+
182+
$response = $this->post(route('applications.event'), [
183+
'semester_id' => Semester::current()->id,
184+
'start_date' => now()->subDays(3),
185+
'end_date' => now()->addDays(2),
186+
'show_until' => now()->addDay(),
187+
]);
188+
189+
$response->assertStatus(302);
190+
$response->assertSessionHasNoErrors();
191+
192+
$response = $this->post(route('applications.event'), [
193+
'semester_id' => Semester::next()->id,
194+
'start_date' => now()->subDays(2),
195+
'end_date' => now()->addDays(3),
196+
'show_until' => now()->addDay(),
197+
]);
198+
$response->assertStatus(302);
199+
$response->assertSessionHasNoErrors();
200+
201+
$this->assertDatabaseCount('periodic_events', 1);
202+
}
203+
}

0 commit comments

Comments
 (0)