summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-03-09 21:37:10 -0400
committerFrederic Guillot <fred@kanboard.net>2015-03-09 21:37:10 -0400
commitc870508923f62e90a81fe39d923d7776dd1e9634 (patch)
treef0c8966fe226b5c48730c29d3eaefb51a9010b8b /tests
parent732899564517c6efd9ef965f3f843309a222ce50 (diff)
Add user timetables
Diffstat (limited to 'tests')
-rw-r--r--tests/units/TimetableTest.php130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/units/TimetableTest.php b/tests/units/TimetableTest.php
new file mode 100644
index 00000000..4b4dcc83
--- /dev/null
+++ b/tests/units/TimetableTest.php
@@ -0,0 +1,130 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\User;
+use Model\Timetable;
+use Model\TimetableDay;
+use Model\TimetableWeek;
+use Model\TimetableOff;
+use Model\TimetableExtra;
+
+class TimetableTest extends Base
+{
+ public function testCalculateWorkDays()
+ {
+ $w = new TimetableWeek($this->container);
+ $t = new Timetable($this->container);
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+
+ $monday = new DateTime('next Monday');
+
+ $timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(4, $timetable);
+
+ $this->assertEquals($monday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[1][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($monday->add(new DateInterval('P1D'))->format('Y-m-d').' 09:30', $timetable[2][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[2][1]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[3][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[3][1]->format('Y-m-d H:i'));
+ }
+
+ public function testCalculateOverTime()
+ {
+ $d = new TimetableDay($this->container);
+ $w = new TimetableWeek($this->container);
+ $e = new TimetableExtra($this->container);
+ $t = new Timetable($this->container);
+
+ $monday = new DateTime('next Monday');
+ $tuesday = new DateTime('next Monday + 1 day');
+ $friday = new DateTime('next Monday + 4 days');
+
+ $this->assertNotFalse($d->create(1, '08:00', '12:00'));
+ $this->assertNotFalse($d->create(1, '14:00', '18:00'));
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+
+ $this->assertNotFalse($e->create(1, $tuesday->format('Y-m-d'), 0, '17:00', '22:00'));
+ $this->assertNotFalse($e->create(1, $friday->format('Y-m-d'), 1));
+
+ $timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(7, $timetable);
+
+ $this->assertEquals($monday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[1][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 09:30', $timetable[2][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 12:00', $timetable[2][1]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 13:00', $timetable[3][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[3][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[4][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 22:00', $timetable[4][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 08:00', $timetable[5][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 12:00', $timetable[5][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 14:00', $timetable[6][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 18:00', $timetable[6][1]->format('Y-m-d H:i'));
+ }
+
+ public function testCalculateTimeOff()
+ {
+ $d = new TimetableDay($this->container);
+ $w = new TimetableWeek($this->container);
+ $o = new TimetableOff($this->container);
+ $t = new Timetable($this->container);
+
+ $monday = new DateTime('next Monday');
+ $tuesday = new DateTime('next Monday + 1 day');
+ $friday = new DateTime('next Monday + 4 days');
+
+ $this->assertNotFalse($d->create(1, '08:00', '12:00'));
+ $this->assertNotFalse($d->create(1, '14:00', '18:00'));
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 5, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 5, '13:00', '17:00'));
+
+ $this->assertNotFalse($o->create(1, $tuesday->format('Y-m-d'), 0, '14:00', '15:00'));
+ $this->assertNotFalse($o->create(1, $monday->format('Y-m-d'), 1));
+
+ $timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(5, $timetable);
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 14:00', $timetable[1][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 15:00', $timetable[2][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[2][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 09:30', $timetable[3][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 12:00', $timetable[3][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 13:00', $timetable[4][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 17:00', $timetable[4][1]->format('Y-m-d H:i'));
+ }
+}