Schedule: Update to parse newer specification

This commit is contained in:
Igor Scheller 2023-12-17 23:42:23 +01:00 committed by xuwhite
parent b63eb44b39
commit d8f8a4f67d
21 changed files with 659 additions and 60 deletions

View File

@ -9,6 +9,7 @@ use Engelsystem\Helpers\Carbon;
use DateTimeInterface;
use Engelsystem\Controllers\BaseController;
use Engelsystem\Controllers\HasUserNotifications;
use Engelsystem\Helpers\Schedule\ConferenceTrack;
use Engelsystem\Helpers\Schedule\Event;
use Engelsystem\Helpers\Schedule\Room;
use Engelsystem\Helpers\Schedule\Schedule;
@ -158,7 +159,7 @@ class ScheduleController extends BaseController
'',
'',
'',
''
new ConferenceTrack('')
);
$this->deleteEvent($event, $schedule);
@ -571,7 +572,7 @@ class ScheduleController extends BaseController
$duration->format('%H:%I'),
'',
'',
''
new ConferenceTrack('')
);
}

View File

@ -8,6 +8,9 @@ class Conference
{
use CalculatesTime;
/**
* @param ConferenceTrack[] $tracks
*/
public function __construct(
protected string $title,
protected string $acronym,
@ -15,7 +18,12 @@ class Conference
protected ?string $end = null,
protected ?int $days = null,
protected ?string $timeslotDuration = null,
protected ?string $baseUrl = null
protected ?string $baseUrl = null,
protected ?string $logo = null,
protected ?string $url = null,
protected ?string $timeZoneName = null,
protected ?ConferenceColor $color = null,
protected array $tracks = [],
) {
}
@ -63,4 +71,32 @@ class Conference
{
return $this->baseUrl;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function getUrl(): ?string
{
return $this->url;
}
public function getTimeZoneName(): ?string
{
return $this->timeZoneName;
}
public function getColor(): ?ConferenceColor
{
return $this->color;
}
/**
* @return ConferenceTrack[]
*/
public function getTracks(): array
{
return $this->tracks;
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Helpers\Schedule;
class ConferenceColor
{
/**
* @param array<string, string> $others type -> color
*/
public function __construct(
protected ?string $primary = null,
protected ?string $background = null,
protected array $others = []
) {
}
public function getPrimary(): ?string
{
return $this->primary;
}
public function getBackground(): ?string
{
return $this->background;
}
public function getOthers(): array
{
return $this->others;
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Helpers\Schedule;
class ConferenceTrack
{
public function __construct(
protected string $name,
protected ?string $color = null,
protected ?string $slug = null,
) {
}
public function getName(): string
{
return $this->name;
}
public function getColor(): ?string
{
return $this->color;
}
public function getSlug(): ?string
{
return $this->slug;
}
}

View File

@ -19,11 +19,11 @@ class Event
* @param string $start time (hh:mm:ss || hh:mm)
* @param string $duration (h?h:mm:ss || h?h:mm)
* @param string $slug globally unique
* @param string[] $persons id => name
* @param array<int, string> $persons id => name
* @param string|null $language two-letter code
* @param string|null $recording license (and opt out in XML, null if not recorded, empty if no license defined)/
* @param array $links href => title
* @param array $attachments href => title
* @param EventRecording|null $recording license, links, url and opt out from XML, null if not defined
* @param array<string, string> $links href => title
* @param array<string, string> $attachments href => title
*/
public function __construct(
protected string $guid,
@ -37,16 +37,17 @@ class Event
protected string $duration,
protected string $abstract,
protected string $slug,
protected string $track,
protected ConferenceTrack $track,
protected ?string $logo = null,
protected array $persons = [],
protected ?string $language = null,
protected ?string $description = null,
protected ?string $recording = '',
protected ?EventRecording $recording = null,
protected array $links = [],
protected array $attachments = [],
protected ?string $url = null,
protected ?string $videoDownloadUrl = null
protected ?string $videoDownloadUrl = null,
protected ?string $feedbackUrl = null,
) {
$this->endDate = $this->date
->copy()
@ -118,7 +119,7 @@ class Event
return $this->slug;
}
public function getTrack(): string
public function getTrack(): ConferenceTrack
{
return $this->track;
}
@ -129,7 +130,7 @@ class Event
}
/**
* @return string[]
* @return array<string, string>
*/
public function getPersons(): array
{
@ -146,7 +147,7 @@ class Event
return $this->description;
}
public function getRecording(): ?string
public function getRecording(): ?EventRecording
{
return $this->recording;
}
@ -166,6 +167,11 @@ class Event
return $this->url;
}
public function getFeedbackUrl(): ?string
{
return $this->feedbackUrl;
}
public function getVideoDownloadUrl(): ?string
{
return $this->videoDownloadUrl;

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Helpers\Schedule;
class EventRecording
{
public function __construct(
protected string $license,
protected bool $optOut,
protected ?string $url = null,
protected ?string $link = null
) {
}
public function getLicense(): string
{
return $this->license;
}
public function isOptOut(): bool
{
return $this->optOut;
}
public function getUrl(): ?string
{
return $this->url;
}
public function getLink(): ?string
{
return $this->link;
}
}

View File

@ -8,9 +8,11 @@ class Room
{
/**
* @param Event[] $events
* @param ?string $guid Globally unique id
*/
public function __construct(
protected string $name,
protected ?string $guid = null,
protected array $events = []
) {
}
@ -35,4 +37,9 @@ class Room
{
$this->events = $events;
}
public function getGuid(): ?string
{
return $this->guid;
}
}

View File

@ -14,7 +14,8 @@ class Schedule
public function __construct(
protected string $version,
protected Conference $conference,
protected array $days
protected array $days,
protected ?ScheduleGenerator $generator = null,
) {
}
@ -82,4 +83,9 @@ class Schedule
return $end;
}
public function getGenerator(): ?ScheduleGenerator
{
return $this->generator;
}
}

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Helpers\Schedule;
class ScheduleGenerator
{
public function __construct(
protected ?string $name = null,
protected ?string $version = null,
) {
}
public function getName(): ?string
{
return $this->name;
}
public function getVersion(): ?string
{
return $this->version;
}
}

View File

@ -35,6 +35,10 @@ class XmlParser
protected function parseXml(): void
{
$version = $this->getFirstXpathContent('version');
$generator = $this->parseGenerator($this->scheduleXML);
$color = $this->parseConferenceColor($this->scheduleXML);
$tracks = $this->parseTracks($this->scheduleXML);
$conference = new Conference(
$this->getFirstXpathContent('conference/title'),
$this->getFirstXpathContent('conference/acronym'),
@ -42,28 +46,36 @@ class XmlParser
$this->getFirstXpathContent('conference/end'),
(int) $this->getFirstXpathContent('conference/days'),
$this->getFirstXpathContent('conference/timeslot_duration'),
$this->getFirstXpathContent('conference/base_url')
$this->getFirstXpathContent('conference/base_url'),
$this->getFirstXpathContent('conference/logo'),
$this->getFirstXpathContent('conference/url'),
$this->getFirstXpathContent('conference/time_zone_name'),
$color,
$tracks,
);
$days = [];
$days = [];
foreach ($this->scheduleXML->xpath('day') as $day) {
$rooms = [];
foreach ($day->xpath('room') as $roomElement) {
$guid = (string) $roomElement->attributes()['guid'];
$room = new Room(
(string) $roomElement->attributes()['name']
(string) $roomElement->attributes()['name'],
!empty($guid) ? $guid : null
);
$events = $this->parseEvents($roomElement->xpath('event'), $room);
$events = $this->parseEvents($roomElement->xpath('event'), $room, $tracks);
$room->setEvents($events);
$rooms[] = $room;
}
$data = $day->attributes();
$days[] = new Day(
(string) $day->attributes()['date'],
new Carbon($day->attributes()['start']),
new Carbon($day->attributes()['end']),
(int) $day->attributes()['index'],
(string) $data['date'],
new Carbon($data['start']),
new Carbon($data['end']),
(int) $data['index'],
$rooms
);
}
@ -71,14 +83,68 @@ class XmlParser
$this->schedule = new Schedule(
$version,
$conference,
$days
$days,
$generator
);
}
protected function parseGenerator(SimpleXMLElement $scheduleXML): ?ScheduleGenerator
{
$generatorData = $scheduleXML->xpath('generator');
if (!isset($generatorData[0])) {
return null;
}
$data = $generatorData[0]->attributes();
return new ScheduleGenerator(
(string) $data['name'] ?? null,
(string) $data['version'] ?? null,
);
}
protected function parseConferenceColor(SimpleXMLElement $scheduleXML): ?ConferenceColor
{
$conferenceColorData = $scheduleXML->xpath('conference/color');
if (!isset($conferenceColorData[0])) {
return null;
}
$data = collect($conferenceColorData[0]->attributes())->map(fn($value) => (string) $value);
$additionalData = $data->collect()->forget(['primary', 'background']);
return new ConferenceColor(
$data['primary'] ?? null,
$data['background'] ?? null,
$additionalData->isNotEmpty() ? $additionalData->toArray() : []
);
}
/**
* @param SimpleXMLElement[] $eventElements
* @return ConferenceTrack[]
*/
protected function parseEvents(array $eventElements, Room $room): array
protected function parseTracks(SimpleXMLElement $scheduleXML): array
{
$tracksData = $scheduleXML->xpath('conference/track');
if (!isset($tracksData[0])) {
return [];
}
$tracks = [];
foreach ($tracksData as $trackData) {
$data = $trackData->attributes();
$tracks[] = new ConferenceTrack(
(string) $data['name'],
(string) $data['color'] ?? null,
(string) $data['slug'] ?? null,
);
}
return $tracks;
}
/**
* @param SimpleXMLElement[] $eventElements
* @param ConferenceTrack[] $tracks
*/
protected function parseEvents(array $eventElements, Room $room, array $tracks): array
{
$events = [];
@ -87,11 +153,9 @@ class XmlParser
$links = $this->getListFromSequence($event, 'links', 'link', 'href');
$attachments = $this->getListFromSequence($event, 'attachments', 'attachment', 'href');
$recording = '';
$recordingElement = $event->xpath('recording');
if ($recordingElement && $this->getFirstXpathContent('optout', $recordingElement[0]) == 'false') {
$recording = $this->getFirstXpathContent('license', $recordingElement[0]);
}
$recording = $this->parseRecording($event);
$trackName = $this->getFirstXpathContent('track', $event);
$track = collect($tracks)->where('name', $trackName)->first() ?: new ConferenceTrack($trackName);
$events[] = new Event(
(string) $event->attributes()['guid'],
@ -105,7 +169,7 @@ class XmlParser
$this->getFirstXpathContent('duration', $event),
$this->getFirstXpathContent('abstract', $event),
$this->getFirstXpathContent('slug', $event),
$this->getFirstXpathContent('track', $event),
$track,
$this->getFirstXpathContent('logo', $event) ?: null,
$persons,
$this->getFirstXpathContent('language', $event) ?: null,
@ -114,13 +178,30 @@ class XmlParser
$links,
$attachments,
$this->getFirstXpathContent('url', $event) ?: null,
$this->getFirstXpathContent('video_download_url', $event) ?: null
$this->getFirstXpathContent('video_download_url', $event) ?: null,
$this->getFirstXpathContent('feedback_url', $event) ?: null,
);
}
return $events;
}
protected function parseRecording(SimpleXMLElement $event): ?EventRecording
{
$recordingElement = $event->xpath('recording');
if (!isset($recordingElement[0])) {
return null;
}
$element = $recordingElement[0];
return new EventRecording(
$this->getFirstXpathContent('license', $element) ?: '',
$this->getFirstXpathContent('optout', $element) != 'false',
$this->getFirstXpathContent('url', $element) ?: null,
$this->getFirstXpathContent('link', $element) ?: null,
);
}
protected function getFirstXpathContent(string $path, ?SimpleXMLElement $xml = null): string
{
$element = ($xml ?: $this->scheduleXML)->xpath($path);

View File

@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="https://c3voc.de/schedule/schema.xsd"
>
<generator name="Engelsystem" version="1.2.3"/>
<version>Some version string</version>
<version>some-version-string</version>
<conference>
<title>Test Event</title>
<acronym>test-3</acronym>
@ -13,7 +13,11 @@
<days>1</days>
<timeslot_duration>00:15</timeslot_duration>
<base_url>https://foo.bar/baz/schedule/</base_url>
<logo>https://foo.bar/baz.png</logo>
<url>https://foo.bar/</url>
<time_zone_name>Europe/Berlin</time_zone_name>
<color primary="#abcdef" background="#aabbcc" customColor="#s011e7"/>
<track name="Testing" color="#dead55" slug="testing"/>
</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' guid="bf5f1132-82bd-4da2-bbe0-1abbf8daf4ab">
@ -38,15 +42,19 @@
<abstract>Foo bar is da best</abstract>
<description>Any describing stuff?</description>
<url>https://foo.bar/baz/schedule/ipsum</url>
<feedback_url>https://foo.bar/baz/schedule/ipsum#feedback</feedback_url>
<logo>https://lorem.ipsum/foo/bar.png</logo>
<persons>
<person id='1234'>Some Person</person>
<person id='1337'>Another Person</person>
</persons>
<links>
<link href="https://foo.bar">Some Foo Bar</link>
<link href="https://example.com">Another example</link>
</links>
<attachments>
<attachment href="https://foo.bar/stuff.pdf">A PDF File</attachment>
<attachment href="https://foo.bar/something.png">An image</attachment>
</attachments>
</event>
</room>

View File

@ -11,6 +11,8 @@
<end>2042-10-02</end>
<days>2</days>
<timeslot_duration>00:30</timeslot_duration>
<track name="Talk"/>
<track name="Testing"/>
</conference>
<day index='1' date='2042-10-01' start='2042-10-01T10:00:00+02:00' end='2042-10-01T22:59:00+02:00'>
<room name='Example Room'>
@ -22,7 +24,7 @@
<duration>01:30</duration>
<room>Example Room</room>
<slug>first-1-event</slug>
<track>Testing</track>
<track>Foo</track>
<type>Talk</type>
<abstract>A minimal description</abstract>
<url>https://example.com/first-1-event</url>

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers\Schedule;
use Engelsystem\Helpers\Schedule\ConferenceColor;
use Engelsystem\Test\Unit\TestCase;
class ConferenceColorTest extends TestCase
{
/**
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::__construct
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::getPrimary
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::getBackground
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::getOthers
*/
public function testCreateDefaults(): void
{
$conferenceColor = new ConferenceColor();
$this->assertNull($conferenceColor->getPrimary());
$this->assertNull($conferenceColor->getBackground());
$this->assertEmpty($conferenceColor->getOthers());
}
/**
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::__construct
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::getPrimary
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::getBackground
* @covers \Engelsystem\Helpers\Schedule\ConferenceColor::getOthers
*/
public function testCreate(): void
{
$conferenceColor = new ConferenceColor(
'#abcdef',
'#aabbcc',
[
'tertiary' => '#133742',
]
);
$this->assertEquals('#abcdef', $conferenceColor->getPrimary());
$this->assertEquals('#aabbcc', $conferenceColor->getBackground());
$this->assertArrayHasKey('tertiary', $conferenceColor->getOthers());
$this->assertEquals('#133742', $conferenceColor->getOthers()['tertiary']);
}
}

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers\Schedule;
use Engelsystem\Helpers\Schedule\Conference;
use Engelsystem\Helpers\Schedule\ConferenceColor;
use Engelsystem\Helpers\Schedule\ConferenceTrack;
use Engelsystem\Test\Unit\TestCase;
class ConferenceTest extends TestCase
@ -19,8 +21,13 @@ class ConferenceTest extends TestCase
* @covers \Engelsystem\Helpers\Schedule\Conference::getTimeslotDuration
* @covers \Engelsystem\Helpers\Schedule\Conference::getTimeslotDurationSeconds
* @covers \Engelsystem\Helpers\Schedule\Conference::getBaseUrl
* @covers \Engelsystem\Helpers\Schedule\Conference::getLogo
* @covers \Engelsystem\Helpers\Schedule\Conference::getUrl
* @covers \Engelsystem\Helpers\Schedule\Conference::getTimeZoneName
* @covers \Engelsystem\Helpers\Schedule\Conference::getColor
* @covers \Engelsystem\Helpers\Schedule\Conference::getTracks
*/
public function testCreate(): void
public function testCreateDefault(): void
{
$conference = new Conference('Doing stuff', 'DS');
$this->assertEquals('Doing stuff', $conference->getTitle());
@ -31,7 +38,31 @@ class ConferenceTest extends TestCase
$this->assertNull($conference->getTimeslotDuration());
$this->assertNull($conference->getTimeslotDurationSeconds());
$this->assertNull($conference->getBaseUrl());
$this->assertNull($conference->getLogo());
$this->assertNull($conference->getUrl());
$this->assertNull($conference->getTimeZoneName());
$this->assertNull($conference->getColor());
$this->assertEmpty($conference->getTracks());
}
/**
* @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
* @covers \Engelsystem\Helpers\Schedule\Conference::getLogo
* @covers \Engelsystem\Helpers\Schedule\Conference::getUrl
* @covers \Engelsystem\Helpers\Schedule\Conference::getTimeZoneName
* @covers \Engelsystem\Helpers\Schedule\Conference::getColor
* @covers \Engelsystem\Helpers\Schedule\Conference::getTracks
*/
public function testCreate(): void
{
$conference = new Conference(
'Doing stuff',
'DS',
@ -39,13 +70,27 @@ class ConferenceTest extends TestCase
'2042-01-10',
10,
'00:10',
'https://foo.bar/schedule'
'https://foo.bar/schedule',
'https://foo.bar/logo.png',
'https://foo.bar',
'Europe/Berlin',
new ConferenceColor('#ffffff'),
[new ConferenceTrack('Test')]
);
$this->assertEquals('Doing stuff', $conference->getTitle());
$this->assertEquals('DS', $conference->getAcronym());
$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());
$this->assertEquals('https://foo.bar/logo.png', $conference->getLogo());
$this->assertEquals('https://foo.bar', $conference->getUrl());
$this->assertEquals('Europe/Berlin', $conference->getTimeZoneName());
$this->assertNotNull($conference->getColor());
$this->assertEquals('#ffffff', $conference->getColor()->getPrimary());
$this->assertNotNull($conference->getTracks());
$this->assertEquals('Test', $conference->getTracks()[0]->getName());
}
}

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers\Schedule;
use Engelsystem\Helpers\Schedule\ConferenceTrack;
use Engelsystem\Test\Unit\TestCase;
class ConferenceTrackTest extends TestCase
{
/**
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::__construct
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::getName
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::getColor
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::getSlug
*/
public function testCreateDefaults(): void
{
$conferenceColor = new ConferenceTrack('Tracking');
$this->assertEquals('Tracking', $conferenceColor->getName());
$this->assertNull($conferenceColor->getColor());
$this->assertNull($conferenceColor->getSlug());
}
/**
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::__construct
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::getName
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::getColor
* @covers \Engelsystem\Helpers\Schedule\ConferenceTrack::getSlug
*/
public function testCreate(): void
{
$conferenceColor = new ConferenceTrack(
'Testing',
'#abcdef',
'testing'
);
$this->assertEquals('Testing', $conferenceColor->getName());
$this->assertEquals('#abcdef', $conferenceColor->getColor());
$this->assertEquals('testing', $conferenceColor->getSlug());
}
}

View File

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers\Schedule;
use Engelsystem\Helpers\Schedule\EventRecording;
use Engelsystem\Test\Unit\TestCase;
class EventRecordingTest extends TestCase
{
/**
* @covers \Engelsystem\Helpers\Schedule\EventRecording::__construct
* @covers \Engelsystem\Helpers\Schedule\EventRecording::getLicense
* @covers \Engelsystem\Helpers\Schedule\EventRecording::isOptOut
* @covers \Engelsystem\Helpers\Schedule\EventRecording::getUrl
* @covers \Engelsystem\Helpers\Schedule\EventRecording::getLink
*/
public function testCreateDefaults(): void
{
$eventRecording = new EventRecording(
'WTFPL',
true
);
$this->assertEquals('WTFPL', $eventRecording->getLicense());
$this->assertTrue($eventRecording->isOptOut());
$this->assertNull($eventRecording->getUrl());
$this->assertNull($eventRecording->getLink());
}
/**
* @covers \Engelsystem\Helpers\Schedule\EventRecording::__construct
* @covers \Engelsystem\Helpers\Schedule\EventRecording::getLicense
* @covers \Engelsystem\Helpers\Schedule\EventRecording::isOptOut
* @covers \Engelsystem\Helpers\Schedule\EventRecording::getUrl
* @covers \Engelsystem\Helpers\Schedule\EventRecording::getLink
*/
public function testCreate(): void
{
$eventRecording = new EventRecording(
'BeerWare',
false,
'https://example.com/recording',
'https://exampple.com/license'
);
$this->assertEquals('BeerWare', $eventRecording->getLicense());
$this->assertFalse($eventRecording->isOptOut());
$this->assertEquals('https://example.com/recording', $eventRecording->getUrl());
$this->assertEquals('https://exampple.com/license', $eventRecording->getLink());
}
}

View File

@ -5,8 +5,11 @@ declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers\Schedule;
use Carbon\Carbon;
use Engelsystem\Helpers\Schedule\ConferenceTrack;
use Engelsystem\Helpers\Schedule\Event;
use Engelsystem\Helpers\Schedule\EventRecording;
use Engelsystem\Helpers\Schedule\Room;
use Engelsystem\Helpers\Uuid;
use Engelsystem\Test\Unit\TestCase;
class EventTest extends TestCase
@ -34,15 +37,17 @@ class EventTest extends TestCase
* @covers \Engelsystem\Helpers\Schedule\Event::getLinks
* @covers \Engelsystem\Helpers\Schedule\Event::getAttachments
* @covers \Engelsystem\Helpers\Schedule\Event::getUrl
* @covers \Engelsystem\Helpers\Schedule\Event::getFeedbackUrl
* @covers \Engelsystem\Helpers\Schedule\Event::getVideoDownloadUrl
* @covers \Engelsystem\Helpers\Schedule\Event::getEndDate
*/
public function testCreate(): void
public function testCreateDefault(): void
{
$room = new Room('Foo');
$date = new Carbon('2020-12-28T19:30:00+00:00');
$uuid = Uuid::uuid();
$event = new Event(
'0-1-2-3',
$uuid,
1,
$room,
'Some stuff',
@ -53,10 +58,10 @@ class EventTest extends TestCase
'00:50',
'Doing stuff is hard, plz try again',
'1-some-stuff',
'Security'
new ConferenceTrack('Security'),
);
$this->assertEquals('0-1-2-3', $event->getGuid());
$this->assertEquals($uuid, $event->getGuid());
$this->assertEquals(1, $event->getId());
$this->assertEquals($room, $event->getRoom());
$this->assertEquals('Some stuff', $event->getTitle());
@ -67,16 +72,17 @@ class EventTest extends TestCase
$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->assertEquals('Security', $event->getTrack()->getName());
$this->assertNull($event->getLogo());
$this->assertEquals([], $event->getPersons());
$this->assertNull($event->getLanguage());
$this->assertNull($event->getDescription());
$this->assertEquals('', $event->getRecording());
$this->assertNull($event->getRecording());
$this->assertEquals([], $event->getLinks());
$this->assertEquals([], $event->getAttachments());
$this->assertNull($event->getUrl());
$this->assertNull($event->getVideoDownloadUrl());
$this->assertNull($event->getFeedbackUrl());
$this->assertEquals('2020-12-28T20:20:00+00:00', $event->getEndDate()->format(Carbon::RFC3339));
}
@ -104,15 +110,16 @@ class EventTest extends TestCase
* @covers \Engelsystem\Helpers\Schedule\Event::getLinks
* @covers \Engelsystem\Helpers\Schedule\Event::getAttachments
* @covers \Engelsystem\Helpers\Schedule\Event::getUrl
* @covers \Engelsystem\Helpers\Schedule\Event::getFeedbackUrl
* @covers \Engelsystem\Helpers\Schedule\Event::getVideoDownloadUrl
*/
public function testCreateNotDefault(): void
public function testCreate(): void
{
$persons = [1337 => 'Some Person'];
$links = ['https://foo.bar' => 'Foo Bar'];
$attachments = ['/files/foo.pdf' => 'Suspicious PDF'];
$event = new Event(
'3-2-1-0',
Uuid::uuid(),
2,
new Room('Bar'),
'Lorem',
@ -123,27 +130,30 @@ class EventTest extends TestCase
'00:30',
'Lorem ipsum dolor sit amet',
'2-lorem',
'DevOps',
new ConferenceTrack('DevOps'),
'/foo/bar.png',
$persons,
'de',
'Foo bar is awesome! & That\'s why...',
'CC BY SA',
new EventRecording('CC BY SA', false),
$links,
$attachments,
'https://foo.bar/2-lorem',
'https://videos.orem.ipsum/2-lorem.mp4'
'https://videos.orem.ipsum/2-lorem.mp4',
'https://videos.orem.ipsum/2-lorem/feedback'
);
$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->assertNotNull($event->getRecording());
$this->assertEquals('CC BY SA', $event->getRecording()->getLicense());
$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());
$this->assertEquals('https://videos.orem.ipsum/2-lorem/feedback', $event->getFeedbackUrl());
$event->setTitle('Event title');
$this->assertEquals('Event title', $event->getTitle());

View File

@ -15,18 +15,30 @@ class RoomTest extends TestCase
* @covers \Engelsystem\Helpers\Schedule\Room::__construct
* @covers \Engelsystem\Helpers\Schedule\Room::getName
* @covers \Engelsystem\Helpers\Schedule\Room::getEvents
* @covers \Engelsystem\Helpers\Schedule\Room::setEvents
* @covers \Engelsystem\Helpers\Schedule\Room::getGuid
*/
public function testCreate(): void
public function testCreateDefault(): void
{
$room = new Room('Test');
$this->assertEquals('Test', $room->getName());
$this->assertEquals([], $room->getEvents());
$this->assertNull($room->getGuid());
}
/**
* @covers \Engelsystem\Helpers\Schedule\Room::__construct
* @covers \Engelsystem\Helpers\Schedule\Room::getName
* @covers \Engelsystem\Helpers\Schedule\Room::getEvents
* @covers \Engelsystem\Helpers\Schedule\Room::setEvents
* @covers \Engelsystem\Helpers\Schedule\Room::getGuid
*/
public function testCreate(): void
{
$uuid = Uuid::uuid();
$events = [$this->createMock(Event::class), $this->createMock(Event::class)];
$events2 = [$this->createMock(Event::class)];
$room = new Room('Test2', $events);
$room = new Room('Test2', $uuid, $events);
$this->assertEquals($events, $room->getEvents());
$this->assertEquals($uuid, $room->getGuid());
$room->setEvents($events2);
$this->assertEquals($events2, $room->getEvents());

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers\Schedule;
use Engelsystem\Helpers\Schedule\ScheduleGenerator;
use Engelsystem\Test\Unit\TestCase;
class ScheduleGeneratorTest extends TestCase
{
/**
* @covers \Engelsystem\Helpers\Schedule\ScheduleGenerator::__construct
* @covers \Engelsystem\Helpers\Schedule\ScheduleGenerator::getName
* @covers \Engelsystem\Helpers\Schedule\ScheduleGenerator::getVersion
*/
public function testCreateDefaults(): void
{
$conferenceColor = new ScheduleGenerator();
$this->assertNull($conferenceColor->getName());
$this->assertNull($conferenceColor->getVersion());
}
/**
* @covers \Engelsystem\Helpers\Schedule\ScheduleGenerator::__construct
* @covers \Engelsystem\Helpers\Schedule\ScheduleGenerator::getName
* @covers \Engelsystem\Helpers\Schedule\ScheduleGenerator::getVersion
*/
public function testCreate(): void
{
$conferenceColor = new ScheduleGenerator('Engelsystem', '1.2.3');
$this->assertEquals('Engelsystem', $conferenceColor->getName());
$this->assertEquals('1.2.3', $conferenceColor->getVersion());
}
}

View File

@ -9,6 +9,7 @@ use Engelsystem\Helpers\Schedule\Conference;
use Engelsystem\Helpers\Schedule\Day;
use Engelsystem\Helpers\Schedule\Room;
use Engelsystem\Helpers\Schedule\Schedule;
use Engelsystem\Helpers\Schedule\ScheduleGenerator;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\TestCase;
@ -21,6 +22,7 @@ class ScheduleTest extends TestCase
* @covers \Engelsystem\Helpers\Schedule\Schedule::getVersion
* @covers \Engelsystem\Helpers\Schedule\Schedule::getConference
* @covers \Engelsystem\Helpers\Schedule\Schedule::getDays
* @covers \Engelsystem\Helpers\Schedule\Schedule::getGenerator
*/
public function testCreate(): void
{
@ -31,6 +33,7 @@ class ScheduleTest extends TestCase
$this->assertEquals('Foo\'ing stuff 1.0', $schedule->getVersion());
$this->assertEquals($conference, $schedule->getConference());
$this->assertEquals($days, $schedule->getDays());
$this->assertNull($schedule->getGenerator());
}
/**
@ -103,6 +106,19 @@ class ScheduleTest extends TestCase
$this->assertNull($schedule->getEndDateTime());
}
/**
* @covers \Engelsystem\Helpers\Schedule\Schedule::__construct
* @covers \Engelsystem\Helpers\Schedule\Schedule::getGenerator
*/
public function testGetGenerator(): void
{
$conference = new Conference('Foo Bar', 'FooB');
$generator = new ScheduleGenerator('test', '1337');
$schedule = new Schedule('1.0', $conference, [], $generator);
$this->assertEquals($generator, $schedule->getGenerator());
}
/**
* Prepare test
*/

View File

@ -16,13 +16,18 @@ class XmlParserTest extends TestCase
/**
* @covers \Engelsystem\Helpers\Schedule\XmlParser::load
* @covers \Engelsystem\Helpers\Schedule\XmlParser::parseXml
* @covers \Engelsystem\Helpers\Schedule\XmlParser::parseGenerator
* @covers \Engelsystem\Helpers\Schedule\XmlParser::parseConferenceColor
* @covers \Engelsystem\Helpers\Schedule\XmlParser::parseTracks
* @covers \Engelsystem\Helpers\Schedule\XmlParser::parseEvents
* @covers \Engelsystem\Helpers\Schedule\XmlParser::parseRecording
* @covers \Engelsystem\Helpers\Schedule\XmlParser::getFirstXpathContent
* @covers \Engelsystem\Helpers\Schedule\XmlParser::getListFromSequence
* @covers \Engelsystem\Helpers\Schedule\XmlParser::getSchedule
*/
public function testLoad(): void
{
$dateTimeFormat = 'Y-m-d\TH:i:sP';
$parser = new XmlParser();
// Invalid XML
@ -38,28 +43,86 @@ class XmlParserTest extends TestCase
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-extended.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());
$generator = $schedule->getGenerator();
$this->assertNotNull($generator);
$this->assertEquals('Engelsystem', $generator->getName());
$this->assertEquals('1.2.3', $generator->getVersion());
$this->assertEquals('some-version-string', $schedule->getVersion());
$conference = $schedule->getConference();
$this->assertEquals('Test Event', $conference->getTitle());
$this->assertEquals('test-3', $conference->getAcronym());
$this->assertEquals('2042-01-01T01:00:00+02:00', $conference->getStart());
$this->assertEquals('2042-01-01T22:59:00+02:00', $conference->getEnd());
$this->assertEquals(1, $conference->getDays());
$this->assertEquals('00:15', $conference->getTimeslotDuration());
$this->assertEquals('https://foo.bar/baz/schedule/', $conference->getBaseUrl());
$this->assertEquals('https://foo.bar/baz.png', $conference->getLogo());
$this->assertEquals('https://foo.bar/', $conference->getUrl());
$this->assertEquals('Europe/Berlin', $conference->getTimeZoneName());
$color = $conference->getColor();
$this->assertNotNull($color);
$this->assertEquals('#abcdef', $color->getPrimary());
$this->assertEquals('#aabbcc', $color->getBackground());
$this->assertEquals(['customColor' => '#s011e7'], $color->getOthers());
$tracks = $conference->getTracks();
$this->assertNotNull($tracks);
$this->assertEquals('Testing', $tracks[0]->getName());
$this->assertEquals('#dead55', $tracks[0]->getColor());
$this->assertEquals('testing', $tracks[0]->getSlug());
;
/** @var Day $day */
$day = Arr::first($schedule->getDays());
$this->assertEquals('2042-01-01', $day->getDate());
$this->assertEquals(1, $day->getIndex());
$this->assertEquals('2042-01-01T01:00:00+02:00', $day->getStart()->format($dateTimeFormat));
$this->assertEquals('2042-01-01T22:59:00+02:00', $day->getEnd()->format($dateTimeFormat));
/** @var Room $room */
$room = Arr::first($schedule->getRooms());
$this->assertEquals('Rooming', $room->getName());
$this->assertEquals('bf5f1132-82bd-4da2-bbe0-1abbf8daf4ab', $room->getGuid());
/** @var Room $room */
$room = Arr::first($day->getRooms());
/** @var Event $event */
$event = Arr::first($room->getEvents());
$this->assertEquals('e427cfa9-9ba1-4b14-a99f-bce83ffe5a1c', $event->getGuid());
$this->assertEquals('1337', $event->getId());
$this->assertEquals('2042-01-01T12:30:00+02:00', $event->getDate()->format($dateTimeFormat));
$this->assertEquals('Foo Bar Test', $event->getTitle());
$this->assertEquals('WTFPL', $event->getRecording());
$this->assertEquals('de', $event->getLanguage());
$this->assertEquals('Some sub', $event->getSubtitle());
$this->assertEquals('12:30', $event->getStart());
$this->assertEquals([1234 => 'Some Person'], $event->getPersons());
$this->assertEquals('00:30', $event->getDuration());
$this->assertEquals($room, $event->getRoom());
$this->assertEquals('some-3-test', $event->getSlug());
$recording = $event->getRecording();
$this->assertNotNull($recording);
$this->assertEquals('WTFPL', $recording->getLicense());
$this->assertFalse($recording->isOptOut());
$this->assertEquals('https://recorder.test/some-3-test/recorded', $recording->getUrl());
$this->assertEquals('https://recorder.test/some-3-test', $recording->getLink());
$this->assertEquals('https://foo.bar/baz/schedule/ipsum/recording.mp4', $event->getVideoDownloadUrl());
$this->assertEquals('Testing', $event->getTrack()->getName());
$this->assertEquals('Talk', $event->getType());
$this->assertEquals('de', $event->getLanguage());
$this->assertEquals('Foo bar is da best', $event->getAbstract());
$this->assertEquals('Any describing stuff?', $event->getDescription());
$this->assertEquals('https://foo.bar/baz/schedule/ipsum', $event->getUrl());
$this->assertEquals('https://foo.bar/baz/schedule/ipsum#feedback', $event->getFeedbackUrl());
$this->assertEquals('https://lorem.ipsum/foo/bar.png', $event->getLogo());
$this->assertEquals([1234 => 'Some Person', 1337 => 'Another Person'], $event->getPersons());
$this->assertEquals([
'https://foo.bar' => 'Some Foo Bar',
'https://example.com' => 'Another example',
], $event->getLinks());
$this->assertEquals([
'https://foo.bar/stuff.pdf' => 'A PDF File',
'https://foo.bar/something.png' => 'An image',
], $event->getAttachments());
}
}