diff options
Diffstat (limited to 'tests/Unit/Helpers/Schedule')
-rw-r--r-- | tests/Unit/Helpers/Schedule/Assets/schedule.xml | 46 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/CalculatesTimeTest.php | 33 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/ConferenceTest.php | 49 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/DayTest.php | 47 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/EventTest.php | 145 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/RoomTest.php | 31 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/ScheduleTest.php | 112 | ||||
-rw-r--r-- | tests/Unit/Helpers/Schedule/XmlParserTest.php | 54 |
8 files changed, 517 insertions, 0 deletions
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()); + } +} |