summaryrefslogtreecommitdiff
path: root/tests/Unit
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-11-27 23:43:21 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2019-12-08 02:20:48 +0100
commit42721e95726559b4a601240bb5b0fe4e5d755b2a (patch)
tree6810e05f845ca787acc1d02fa82d3df15cd0ef9b /tests/Unit
parent377b390c97afb9106fd9a139819d00306f996f24 (diff)
Added Schedule parsing and replaced old Fahrplan importer
Resolves #553 (Change Frab Import from xCal to XML) Resolves #538 (Feature Request: Multi Frab Import)
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/HasDatabase.php19
-rw-r--r--tests/Unit/Helpers/Schedule/Assets/schedule.xml46
-rw-r--r--tests/Unit/Helpers/Schedule/CalculatesTimeTest.php33
-rw-r--r--tests/Unit/Helpers/Schedule/ConferenceTest.php49
-rw-r--r--tests/Unit/Helpers/Schedule/DayTest.php47
-rw-r--r--tests/Unit/Helpers/Schedule/EventTest.php145
-rw-r--r--tests/Unit/Helpers/Schedule/RoomTest.php31
-rw-r--r--tests/Unit/Helpers/Schedule/ScheduleTest.php112
-rw-r--r--tests/Unit/Helpers/Schedule/XmlParserTest.php54
-rw-r--r--tests/Unit/Http/GuzzleServiceProviderTest.php29
-rw-r--r--tests/Unit/Models/Shifts/ScheduleShiftTest.php41
-rw-r--r--tests/Unit/Models/Shifts/ScheduleTest.php37
12 files changed, 635 insertions, 8 deletions
diff --git a/tests/Unit/HasDatabase.php b/tests/Unit/HasDatabase.php
index dbaa253e..3fe29e4a 100644
--- a/tests/Unit/HasDatabase.php
+++ b/tests/Unit/HasDatabase.php
@@ -36,14 +36,17 @@ trait HasDatabase
$this->database
->getConnection()
->table('migrations')
- ->insert([
- ['migration' => '2018_01_01_000001_import_install_sql'],
- ['migration' => '2018_01_01_000002_import_update_sql'],
- ['migration' => '2018_01_01_000003_fix_old_tables'],
- ['migration' => '2018_01_01_000004_cleanup_group_privileges'],
- ['migration' => '2018_01_01_000005_add_angel_supporter_permissions'],
- ['migration' => '2018_12_27_000000_fix_missing_arrival_dates'],
- ]);
+ ->insert(
+ [
+ ['migration' => '2018_01_01_000001_import_install_sql'],
+ ['migration' => '2018_01_01_000002_import_update_sql'],
+ ['migration' => '2018_01_01_000003_fix_old_tables'],
+ ['migration' => '2018_01_01_000004_cleanup_group_privileges'],
+ ['migration' => '2018_01_01_000005_add_angel_supporter_permissions'],
+ ['migration' => '2018_12_27_000000_fix_missing_arrival_dates'],
+ ['migration' => '2019_09_07_000000_migrate_admin_schedule_permissions'],
+ ]
+ );
$migration->run(__DIR__ . '/../../db/migrations');
}
diff --git a/tests/Unit/Helpers/Schedule/Assets/schedule.xml b/tests/Unit/Helpers/Schedule/Assets/schedule.xml
new file mode 100644
index 00000000..45aaaf35
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/Assets/schedule.xml
@@ -0,0 +1,46 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<schedule>
+ <version>Some version string</version>
+ <conference>
+ <title>Test Event</title>
+ <acronym>Test1</acronym>
+ <start>2042-01-01</start>
+ <end>2042-01-01</end>
+ <days>1</days>
+ <timeslot_duration>00:15</timeslot_duration>
+ <base_url>https://foo.bar/baz/schedule/</base_url>
+ </conference>
+ <day index='1' date='2042-01-01' start='2042-01-01T01:00:00+02:00' end='2042-01-01T22:59:00+02:00'>
+ <room name='Rooming'>
+ <event guid='e427cfa9-9ba1-4b14-a99f-bce83ffe5a1c' id='1337'>
+ <date>2042-01-01T12:30:00+02:00</date>
+ <title>Foo Bar Test</title>
+ <subtitle>Some sub</subtitle>
+ <start>12:30</start>
+ <duration>00:30</duration>
+ <room>Rooming</room>
+ <slug>foo-bar-test</slug>
+ <recording>
+ <license>WTFPL</license>
+ <optout>false</optout>
+ </recording>
+ <track>Testing</track>
+ <type>Talk</type>
+ <language>de</language>
+ <abstract>Foo bar is da best</abstract>
+ <description>Any describing stuff?</description>
+ <url>https://foo.bar/baz/schedule/ipsum</url>
+ <logo>https://lorem.ipsum/foo/bar.png</logo>
+ <persons>
+ <person id='1234'>Some Person</person>
+ </persons>
+ <links>
+ <link href="https://foo.bar">Some Foo Bar</link>
+ </links>
+ <attachments>
+ <attachment href="https://foo.bar/stuff.pdf">A PDF File</attachment>
+ </attachments>
+ </event>
+ </room>
+ </day>
+</schedule>
diff --git a/tests/Unit/Helpers/Schedule/CalculatesTimeTest.php b/tests/Unit/Helpers/Schedule/CalculatesTimeTest.php
new file mode 100644
index 00000000..8f0123e9
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/CalculatesTimeTest.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers\Schedule;
+
+use Engelsystem\Helpers\Schedule\CalculatesTime;
+use Engelsystem\Test\Unit\TestCase;
+
+class CalculatesTimeTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\CalculatesTime::secondsFromTime
+ */
+ public function testSecondsFromTime()
+ {
+ $calc = new class {
+ use CalculatesTime;
+
+ /**
+ * @param string $time
+ * @return int
+ */
+ public function calc(string $time): int
+ {
+ return $this->secondsFromTime($time);
+ }
+ };
+
+ $this->assertEquals(0, $calc->calc('0:00'));
+ $this->assertEquals(60, $calc->calc('0:01'));
+ $this->assertEquals(60 * 60, $calc->calc('01:00'));
+ $this->assertEquals(60 * 60 * 10 + 60 * 11, $calc->calc('10:11'));
+ }
+}
diff --git a/tests/Unit/Helpers/Schedule/ConferenceTest.php b/tests/Unit/Helpers/Schedule/ConferenceTest.php
new file mode 100644
index 00000000..959e272b
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/ConferenceTest.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers\Schedule;
+
+use Engelsystem\Helpers\Schedule\Conference;
+use Engelsystem\Test\Unit\TestCase;
+
+class ConferenceTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\Conference::__construct
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getTitle
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getAcronym
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getStart
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getEnd
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getDays
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getTimeslotDuration
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getTimeslotDurationSeconds
+ * @covers \Engelsystem\Helpers\Schedule\Conference::getBaseUrl
+ */
+ public function testCreate()
+ {
+ $conference = new Conference('Doing stuff', 'DS');
+ $this->assertEquals('Doing stuff', $conference->getTitle());
+ $this->assertEquals('DS', $conference->getAcronym());
+ $this->assertNull($conference->getStart());
+ $this->assertNull($conference->getEnd());
+ $this->assertNull($conference->getDays());
+ $this->assertNull($conference->getTimeslotDuration());
+ $this->assertNull($conference->getTimeslotDurationSeconds());
+ $this->assertNull($conference->getBaseUrl());
+
+ $conference = new Conference(
+ 'Doing stuff',
+ 'DS',
+ '2042-01-01',
+ '2042-01-10',
+ 10,
+ '00:10',
+ 'https://foo.bar/schedule'
+ );
+ $this->assertEquals('2042-01-01', $conference->getStart());
+ $this->assertEquals('2042-01-10', $conference->getEnd());
+ $this->assertEquals(10, $conference->getDays());
+ $this->assertEquals('00:10', $conference->getTimeslotDuration());
+ $this->assertEquals(60 * 10, $conference->getTimeslotDurationSeconds());
+ $this->assertEquals('https://foo.bar/schedule', $conference->getBaseUrl());
+ }
+}
diff --git a/tests/Unit/Helpers/Schedule/DayTest.php b/tests/Unit/Helpers/Schedule/DayTest.php
new file mode 100644
index 00000000..65704181
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/DayTest.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers\Schedule;
+
+use Carbon\Carbon;
+use Engelsystem\Helpers\Schedule\Day;
+use Engelsystem\Helpers\Schedule\Room;
+use Engelsystem\Test\Unit\TestCase;
+
+class DayTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\Day::__construct
+ * @covers \Engelsystem\Helpers\Schedule\Day::getDate
+ * @covers \Engelsystem\Helpers\Schedule\Day::getStart
+ * @covers \Engelsystem\Helpers\Schedule\Day::getEnd
+ * @covers \Engelsystem\Helpers\Schedule\Day::getIndex
+ * @covers \Engelsystem\Helpers\Schedule\Day::getRoom
+ */
+ public function testCreate()
+ {
+ $day = new Day(
+ '2000-01-01',
+ new Carbon('2000-01-01T03:00:00+01:00'),
+ new Carbon('2000-01-02T05:59:00+00:00'),
+ 1
+ );
+ $this->assertEquals('2000-01-01', $day->getDate());
+ $this->assertEquals('2000-01-01T03:00:00+01:00', $day->getStart()->format(Carbon::RFC3339));
+ $this->assertEquals('2000-01-02T05:59:00+00:00', $day->getEnd()->format(Carbon::RFC3339));
+ $this->assertEquals(1, $day->getIndex());
+ $this->assertEquals([], $day->getRoom());
+
+ $rooms = [
+ new Room('Foo'),
+ new Room('Bar'),
+ ];
+ $day = new Day(
+ '2001-01-01',
+ new Carbon('2001-01-01T03:00:00+01:00'),
+ new Carbon('2001-01-02T05:59:00+00:00'),
+ 1,
+ $rooms
+ );
+ $this->assertEquals($rooms, $day->getRoom());
+ }
+}
diff --git a/tests/Unit/Helpers/Schedule/EventTest.php b/tests/Unit/Helpers/Schedule/EventTest.php
new file mode 100644
index 00000000..262aeea7
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/EventTest.php
@@ -0,0 +1,145 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers\Schedule;
+
+use Carbon\Carbon;
+use Engelsystem\Helpers\Schedule\Event;
+use Engelsystem\Helpers\Schedule\Room;
+use Engelsystem\Test\Unit\TestCase;
+
+class EventTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\Event::__construct
+ * @covers \Engelsystem\Helpers\Schedule\Event::getGuid
+ * @covers \Engelsystem\Helpers\Schedule\Event::getId
+ * @covers \Engelsystem\Helpers\Schedule\Event::getRoom
+ * @covers \Engelsystem\Helpers\Schedule\Event::getTitle
+ * @covers \Engelsystem\Helpers\Schedule\Event::getSubtitle
+ * @covers \Engelsystem\Helpers\Schedule\Event::getType
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDate
+ * @covers \Engelsystem\Helpers\Schedule\Event::getStart
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDuration
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDurationSeconds
+ * @covers \Engelsystem\Helpers\Schedule\Event::getAbstract
+ * @covers \Engelsystem\Helpers\Schedule\Event::getSlug
+ * @covers \Engelsystem\Helpers\Schedule\Event::getTrack
+ * @covers \Engelsystem\Helpers\Schedule\Event::getLogo
+ * @covers \Engelsystem\Helpers\Schedule\Event::getPersons
+ * @covers \Engelsystem\Helpers\Schedule\Event::getLanguage
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDescription
+ * @covers \Engelsystem\Helpers\Schedule\Event::getRecording
+ * @covers \Engelsystem\Helpers\Schedule\Event::getLinks
+ * @covers \Engelsystem\Helpers\Schedule\Event::getAttachments
+ * @covers \Engelsystem\Helpers\Schedule\Event::getUrl
+ * @covers \Engelsystem\Helpers\Schedule\Event::getVideoDownloadUrl
+ * @covers \Engelsystem\Helpers\Schedule\Event::getEndDate
+ */
+ public function testCreate()
+ {
+ $room = new Room('Foo');
+ $date = new Carbon('2020-12-28T19:30:00+00:00');
+ $event = new Event(
+ '0-1-2-3',
+ 1,
+ $room,
+ 'Some stuff',
+ 'sub stuff',
+ 'Talk',
+ $date,
+ '19:30:00',
+ '00:50',
+ 'Doing stuff is hard, plz try again',
+ '1-some-stuff',
+ 'Security'
+ );
+
+ $this->assertEquals('0-1-2-3', $event->getGuid());
+ $this->assertEquals(1, $event->getId());
+ $this->assertEquals($room, $event->getRoom());
+ $this->assertEquals('Some stuff', $event->getTitle());
+ $this->assertEquals('sub stuff', $event->getSubtitle());
+ $this->assertEquals('Talk', $event->getType());
+ $this->assertEquals($date, $event->getDate());
+ $this->assertEquals('19:30:00', $event->getStart());
+ $this->assertEquals('00:50', $event->getDuration());
+ $this->assertEquals('Doing stuff is hard, plz try again', $event->getAbstract());
+ $this->assertEquals('1-some-stuff', $event->getSlug());
+ $this->assertEquals('Security', $event->getTrack());
+ $this->assertNull($event->getLogo());
+ $this->assertEquals([], $event->getPersons());
+ $this->assertNull($event->getLanguage());
+ $this->assertNull($event->getDescription());
+ $this->assertEquals('', $event->getRecording());
+ $this->assertEquals([], $event->getLinks());
+ $this->assertEquals([], $event->getAttachments());
+ $this->assertNull($event->getUrl());
+ $this->assertNull($event->getVideoDownloadUrl());
+ $this->assertEquals('2020-12-28T20:20:00+00:00', $event->getEndDate()->format(Carbon::RFC3339));
+ }
+
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\Event::__construct
+ * @covers \Engelsystem\Helpers\Schedule\Event::getGuid
+ * @covers \Engelsystem\Helpers\Schedule\Event::getId
+ * @covers \Engelsystem\Helpers\Schedule\Event::getRoom
+ * @covers \Engelsystem\Helpers\Schedule\Event::getTitle
+ * @covers \Engelsystem\Helpers\Schedule\Event::getSubtitle
+ * @covers \Engelsystem\Helpers\Schedule\Event::getType
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDate
+ * @covers \Engelsystem\Helpers\Schedule\Event::getStart
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDuration
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDurationSeconds
+ * @covers \Engelsystem\Helpers\Schedule\Event::getAbstract
+ * @covers \Engelsystem\Helpers\Schedule\Event::getSlug
+ * @covers \Engelsystem\Helpers\Schedule\Event::getTrack
+ * @covers \Engelsystem\Helpers\Schedule\Event::getLogo
+ * @covers \Engelsystem\Helpers\Schedule\Event::getPersons
+ * @covers \Engelsystem\Helpers\Schedule\Event::getLanguage
+ * @covers \Engelsystem\Helpers\Schedule\Event::getDescription
+ * @covers \Engelsystem\Helpers\Schedule\Event::getRecording
+ * @covers \Engelsystem\Helpers\Schedule\Event::getLinks
+ * @covers \Engelsystem\Helpers\Schedule\Event::getAttachments
+ * @covers \Engelsystem\Helpers\Schedule\Event::getUrl
+ * @covers \Engelsystem\Helpers\Schedule\Event::getVideoDownloadUrl
+ */
+ public function testCreateNotDefault()
+ {
+ $persons = [1337 => 'Some Person'];
+ $links = ['https://foo.bar' => 'Foo Bar'];
+ $attachments = ['/files/foo.pdf' => 'Suspicious PDF'];
+ $event = new Event(
+ '3-2-1-0',
+ 2,
+ new Room('Bar'),
+ 'Lorem',
+ 'Ipsum',
+ 'Workshop',
+ new Carbon('2021-01-01T00:00:00+00:00'),
+ '00:00:00',
+ '00:30',
+ 'Lorem ipsum dolor sit amet',
+ '2-lorem',
+ 'DevOps',
+ '/foo/bar.png',
+ $persons,
+ 'de',
+ 'Foo bar is awesome! & That\'s why...',
+ 'CC BY SA',
+ $links,
+ $attachments,
+ 'https://foo.bar/2-lorem',
+ 'https://videos.orem.ipsum/2-lorem.mp4'
+ );
+
+ $this->assertEquals('/foo/bar.png', $event->getLogo());
+ $this->assertEquals($persons, $event->getPersons());
+ $this->assertEquals('de', $event->getLanguage());
+ $this->assertEquals('Foo bar is awesome! & That\'s why...', $event->getDescription());
+ $this->assertEquals('CC BY SA', $event->getRecording());
+ $this->assertEquals($links, $event->getLinks());
+ $this->assertEquals($attachments, $event->getAttachments());
+ $this->assertEquals('https://foo.bar/2-lorem', $event->getUrl());
+ $this->assertEquals('https://videos.orem.ipsum/2-lorem.mp4', $event->getVideoDownloadUrl());
+ }
+}
diff --git a/tests/Unit/Helpers/Schedule/RoomTest.php b/tests/Unit/Helpers/Schedule/RoomTest.php
new file mode 100644
index 00000000..8b9b600a
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/RoomTest.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers\Schedule;
+
+use Engelsystem\Helpers\Schedule\Event;
+use Engelsystem\Helpers\Schedule\Room;
+use Engelsystem\Test\Unit\TestCase;
+
+class RoomTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\Room::__construct
+ * @covers \Engelsystem\Helpers\Schedule\Room::getName
+ * @covers \Engelsystem\Helpers\Schedule\Room::getEvent
+ * @covers \Engelsystem\Helpers\Schedule\Room::setEvent
+ */
+ public function testCreate()
+ {
+ $room = new Room('Test');
+ $this->assertEquals('Test', $room->getName());
+ $this->assertEquals([], $room->getEvent());
+
+ $events = [$this->createMock(Event::class), $this->createMock(Event::class)];
+ $events2 = [$this->createMock(Event::class)];
+ $room = new Room('Test2', $events);
+ $this->assertEquals($events, $room->getEvent());
+
+ $room->setEvent($events2);
+ $this->assertEquals($events2, $room->getEvent());
+ }
+}
diff --git a/tests/Unit/Helpers/Schedule/ScheduleTest.php b/tests/Unit/Helpers/Schedule/ScheduleTest.php
new file mode 100644
index 00000000..6a3634cf
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/ScheduleTest.php
@@ -0,0 +1,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();
+ }
+}
diff --git a/tests/Unit/Helpers/Schedule/XmlParserTest.php b/tests/Unit/Helpers/Schedule/XmlParserTest.php
new file mode 100644
index 00000000..023e9c7d
--- /dev/null
+++ b/tests/Unit/Helpers/Schedule/XmlParserTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers\Schedule;
+
+use Engelsystem\Helpers\Schedule\Day;
+use Engelsystem\Helpers\Schedule\Event;
+use Engelsystem\Helpers\Schedule\Room;
+use Engelsystem\Helpers\Schedule\XmlParser;
+use Engelsystem\Test\Unit\TestCase;
+use Illuminate\Support\Arr;
+
+class XmlParserTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Helpers\Schedule\XmlParser::load
+ * @covers \Engelsystem\Helpers\Schedule\XmlParser::parseXml
+ * @covers \Engelsystem\Helpers\Schedule\XmlParser::parseEvents
+ * @covers \Engelsystem\Helpers\Schedule\XmlParser::getFirstXpathContent
+ * @covers \Engelsystem\Helpers\Schedule\XmlParser::getListFromSequence
+ * @covers \Engelsystem\Helpers\Schedule\XmlParser::getSchedule
+ */
+ public function testLoad()
+ {
+ libxml_use_internal_errors(true);
+
+ $parser = new XmlParser();
+ $this->assertFalse($parser->load('foo'));
+ $this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule.xml')));
+
+ $schedule = $parser->getSchedule();
+ $this->assertEquals('Some version string', $schedule->getVersion());
+ $this->assertEquals('Test Event', $schedule->getConference()->getTitle());
+
+ /** @var Room $room */
+ $room = Arr::first($schedule->getRooms());
+ $this->assertEquals('Rooming', $room->getName());
+
+ /** @var Day $day */
+ $day = Arr::first($schedule->getDay());
+ $this->assertEquals('2042-01-01', $day->getDate());
+ $this->assertEquals(1, $day->getIndex());
+
+ /** @var Room $room */
+ $room = Arr::first($day->getRoom());
+ /** @var Event $event */
+ $event = Arr::first($room->getEvent());
+
+ $this->assertEquals('Foo Bar Test', $event->getTitle());
+ $this->assertEquals('WTFPL', $event->getRecording());
+ $this->assertEquals('de', $event->getLanguage());
+ $this->assertEquals('12:30', $event->getStart());
+ $this->assertEquals([1234 => 'Some Person'], $event->getPersons());
+ }
+}
diff --git a/tests/Unit/Http/GuzzleServiceProviderTest.php b/tests/Unit/Http/GuzzleServiceProviderTest.php
new file mode 100644
index 00000000..4d3c938b
--- /dev/null
+++ b/tests/Unit/Http/GuzzleServiceProviderTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Http;
+
+use Engelsystem\Application;
+use Engelsystem\Http\GuzzleServiceProvider;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+use GuzzleHttp\Client as GuzzleClient;
+
+class GuzzleServiceProviderTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Http\GuzzleServiceProvider::register
+ */
+ public function testRegister()
+ {
+ $app = new Application();
+
+ $serviceProvider = new GuzzleServiceProvider($app);
+ $serviceProvider->register();
+
+ /** @var GuzzleClient $guzzle */
+ $guzzle = $app->make(GuzzleClient::class);
+ $config = $guzzle->getConfig();
+
+ $this->assertFalse($config['http_errors']);
+ $this->assertArrayHasKey('timeout', $config);
+ }
+}
diff --git a/tests/Unit/Models/Shifts/ScheduleShiftTest.php b/tests/Unit/Models/Shifts/ScheduleShiftTest.php
new file mode 100644
index 00000000..b615f90d
--- /dev/null
+++ b/tests/Unit/Models/Shifts/ScheduleShiftTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Models\Shifts;
+
+use Engelsystem\Models\Shifts\Schedule;
+use Engelsystem\Models\Shifts\ScheduleShift;
+use Engelsystem\Test\Unit\HasDatabase;
+use Engelsystem\Test\Unit\TestCase;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class ScheduleShiftTest extends TestCase
+{
+ use HasDatabase;
+
+ /**
+ * @covers \Engelsystem\Models\Shifts\ScheduleShift::schedule
+ */
+ public function testScheduleShifts()
+ {
+ $schedule = new Schedule(['url' => 'https://lorem.ipsum/schedule.xml']);
+ $schedule->save();
+
+ $scheduleShift = new ScheduleShift(['shift_id' => 1, 'guid' => 'a']);
+ $scheduleShift->schedule()->associate($schedule);
+ $scheduleShift->save();
+
+ /** @var ScheduleShift $scheduleShift */
+ $scheduleShift = (new ScheduleShift())->find(1);
+ $this->assertInstanceOf(BelongsTo::class, $scheduleShift->schedule());
+ $this->assertEquals($schedule->id, $scheduleShift->schedule->id);
+ }
+
+ /**
+ * Prepare test
+ */
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $this->initDatabase();
+ }
+}
diff --git a/tests/Unit/Models/Shifts/ScheduleTest.php b/tests/Unit/Models/Shifts/ScheduleTest.php
new file mode 100644
index 00000000..34988afd
--- /dev/null
+++ b/tests/Unit/Models/Shifts/ScheduleTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Models\Shifts;
+
+use Engelsystem\Models\Shifts\Schedule;
+use Engelsystem\Models\Shifts\ScheduleShift;
+use Engelsystem\Test\Unit\HasDatabase;
+use Engelsystem\Test\Unit\TestCase;
+
+class ScheduleTest extends TestCase
+{
+ use HasDatabase;
+
+ /**
+ * @covers \Engelsystem\Models\Shifts\Schedule::scheduleShifts
+ */
+ public function testScheduleShifts()
+ {
+ $schedule = new Schedule(['url' => 'https://foo.bar/schedule.xml']);
+ $schedule->save();
+
+ (new ScheduleShift(['shift_id' => 1, 'schedule_id' => $schedule->id, 'guid' => 'a']))->save();
+ (new ScheduleShift(['shift_id' => 2, 'schedule_id' => $schedule->id, 'guid' => 'b']))->save();
+ (new ScheduleShift(['shift_id' => 3, 'schedule_id' => $schedule->id, 'guid' => 'c']))->save();
+
+ $this->assertCount(3, $schedule->scheduleShifts);
+ }
+
+ /**
+ * Prepare test
+ */
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $this->initDatabase();
+ }
+}