summaryrefslogtreecommitdiff
path: root/tests/Unit/Helpers/Schedule/ScheduleTest.php
blob: 6a3634cf68cf75c354bb78bd1f18b583c8821474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

namespace Engelsystem\Test\Unit\Helpers\Schedule;

use Carbon\Carbon;
use Engelsystem\Helpers\Schedule\Conference;
use Engelsystem\Helpers\Schedule\Day;
use Engelsystem\Helpers\Schedule\Room;
use Engelsystem\Helpers\Schedule\Schedule;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\TestCase;

class ScheduleTest extends TestCase
{
    use HasDatabase;

    /**
     * @covers \Engelsystem\Helpers\Schedule\Schedule::__construct
     * @covers \Engelsystem\Helpers\Schedule\Schedule::getVersion
     * @covers \Engelsystem\Helpers\Schedule\Schedule::getConference
     * @covers \Engelsystem\Helpers\Schedule\Schedule::getDay
     */
    public function testCreate()
    {
        $conference = new Conference('Foo Bar', 'FooB');
        $days = [$this->createMock(Day::class)];
        $schedule = new Schedule('Foo\'ing stuff 1.0', $conference, $days);

        $this->assertEquals('Foo\'ing stuff 1.0', $schedule->getVersion());
        $this->assertEquals($conference, $schedule->getConference());
        $this->assertEquals($days, $schedule->getDay());
    }

    /**
     * @covers \Engelsystem\Helpers\Schedule\Schedule::getRooms
     */
    public function testGetRooms()
    {
        $conference = new Conference('Test', 'T');
        $room1 = new Room('Test 1');
        $room2 = new Room('Test 2');
        $room3 = new Room('Test 3');
        $days = [
            new Day(
                '2042-01-01',
                new Carbon('2042-01-01T00:00:00+00:00'),
                new Carbon('2042-01-01T23:59:00+00:00'),
                1,
                [$room1, $room2]
            ),
            new Day(
                '2042-01-02',
                new Carbon('2042-02-01T00:00:00+00:00'),
                new Carbon('2042-02-01T23:59:00+00:00'),
                2,
                [new Room('Test 2'), $room3]
            ),
        ];
        $schedule = new Schedule('Lorem 1.3.3.7', $conference, $days);

        $this->assertEquals(['Test 1' => $room1, 'Test 2' => $room2, 'Test 3' => $room3], $schedule->getRooms());

        $schedule = new Schedule('Lorem 1.3.3.0', $conference, []);
        $this->assertEquals([], $schedule->getRooms());
    }

    /**
     * @covers \Engelsystem\Helpers\Schedule\Schedule::getStartDateTime
     * @covers \Engelsystem\Helpers\Schedule\Schedule::getEndDateTime
     */
    public function testGetDateTimes()
    {
        $conference = new Conference('Some Conference', 'SC');
        $days = [
            new Day(
                '2042-01-02',
                new Carbon('2042-01-02T00:00:00+00:00'),
                new Carbon('2042-01-02T23:59:00+00:00'),
                2
            ),
            new Day(
                '2042-01-01',
                new Carbon('2042-01-01T00:00:00+00:00'),
                new Carbon('2042-01-01T23:59:00+00:00'),
                1
            ),
            new Day(
                '2042-01-04',
                new Carbon('2042-01-04T00:00:00+00:00'),
                new Carbon('2042-01-04T23:59:00+00:00'),
                3
            ),
        ];
        $schedule = new Schedule('Ipsum tester', $conference, $days);

        $this->assertEquals('2042-01-01T00:00:00+00:00', $schedule->getStartDateTime()->format(Carbon::RFC3339));
        $this->assertEquals('2042-01-04T23:59:00+00:00', $schedule->getEndDateTime()->format(Carbon::RFC3339));

        $schedule = new Schedule('Ipsum old', $conference, []);
        $this->assertNull($schedule->getStartDateTime());
        $this->assertNull($schedule->getEndDateTime());
    }

    /**
     * Prepare test
     */
    protected function setUp(): void
    {
        parent::setUp();
        $this->initDatabase();
    }
}