Fixed Schedule XML parser to support minimum import
This commit is contained in:
parent
2fab7ba39a
commit
f3af7bab50
|
@ -34,6 +34,8 @@ class XmlParser
|
|||
|
||||
/**
|
||||
* Parse the predefined XML content
|
||||
*
|
||||
* According to https://github.com/voc/voctosched/blob/master/schema/basic.xsd
|
||||
*/
|
||||
protected function parseXml(): void
|
||||
{
|
||||
|
@ -93,9 +95,9 @@ class XmlParser
|
|||
$attachments = $this->getListFromSequence($event, 'attachments', 'attachment', 'href');
|
||||
|
||||
$recording = '';
|
||||
$recordingElement = $event->xpath('recording')[0];
|
||||
if ($this->getFirstXpathContent('optout', $recordingElement) == 'false') {
|
||||
$recording = $this->getFirstXpathContent('license', $recordingElement);
|
||||
$recordingElement = $event->xpath('recording');
|
||||
if ($recordingElement && $this->getFirstXpathContent('optout', $recordingElement[0]) == 'false') {
|
||||
$recording = $this->getFirstXpathContent('license', $recordingElement[0]);
|
||||
}
|
||||
|
||||
$events[] = new Event(
|
||||
|
@ -155,8 +157,10 @@ class XmlParser
|
|||
): array {
|
||||
$items = [];
|
||||
|
||||
foreach ($element->xpath($firstElement)[0]->xpath($secondElement) as $item) {
|
||||
$items[(string)$item->attributes()[$idAttribute]] = (string)$item;
|
||||
foreach ($element->xpath($firstElement) as $element) {
|
||||
foreach ($element->xpath($secondElement) as $item) {
|
||||
$items[(string)$item->attributes()[$idAttribute]] = (string)$item;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version='1.0' encoding='utf-8' ?>
|
||||
<schedule
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/voc/voctosched/master/schema/basic.xsd"
|
||||
>
|
||||
<version>dolor</version>
|
||||
<conference>
|
||||
<title>Basic Test Event</title>
|
||||
<acronym>Test2</acronym>
|
||||
<start>2042-01-03</start>
|
||||
<end>2042-01-03</end>
|
||||
<days>1</days>
|
||||
<timeslot_duration>00:30</timeslot_duration>
|
||||
</conference>
|
||||
<day index='1' date='2042-01-03' start='2042-01-03T01:00:00+02:00' end='2042-01-03T22:59:00+02:00'>
|
||||
<room name='Some Room'>
|
||||
<event guid='7b1327a5-049b-4411-8421-163743755933' id='1234'>
|
||||
<date>2042-01-03T14:15:00+02:00</date>
|
||||
<title>Lorem Ipsum</title>
|
||||
<subtitle>Some sub</subtitle>
|
||||
<start>14:15</start>
|
||||
<duration>00:45</duration>
|
||||
<room>Some Room</room>
|
||||
<slug>lorem/ipsum</slug>
|
||||
<recording>
|
||||
<license>WTFPL</license>
|
||||
<optout>true</optout>
|
||||
</recording>
|
||||
<track>Tests</track>
|
||||
<type>Talk</type>
|
||||
<language>en</language>
|
||||
<abstract>45 minutes of awesome lorem ipsum</abstract>
|
||||
<description>Be prepared for the best lorem ipsum of the entire day!</description>
|
||||
<logo>https://lorem.ipsum/foo/bar.png</logo>
|
||||
<persons>
|
||||
<person id='42'>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>
|
|
@ -1,9 +1,12 @@
|
|||
<?xml version='1.0' encoding='utf-8' ?>
|
||||
<schedule>
|
||||
<schedule
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/voc/voctosched/master/schema/extended.xsd"
|
||||
>
|
||||
<version>Some version string</version>
|
||||
<conference>
|
||||
<title>Test Event</title>
|
||||
<acronym>Test1</acronym>
|
||||
<acronym>Test3</acronym>
|
||||
<start>2042-01-01</start>
|
||||
<end>2042-01-01</end>
|
||||
<days>1</days>
|
||||
|
@ -24,6 +27,7 @@
|
|||
<license>WTFPL</license>
|
||||
<optout>false</optout>
|
||||
</recording>
|
||||
<video_download_url>https://foo.bar/baz/schedule/ipsum/recording.mp4</video_download_url>
|
||||
<track>Testing</track>
|
||||
<type>Talk</type>
|
||||
<language>de</language>
|
|
@ -0,0 +1,27 @@
|
|||
<schedule>
|
||||
<version>0.0.1</version>
|
||||
<conference>
|
||||
<title>Some Test Event</title>
|
||||
<acronym>Test1</acronym>
|
||||
</conference>
|
||||
<day index='1' date='2042-01-02' start='2042-01-02T00:00:00+00:00' end='2042-01-02T22:59:00+00:00'>
|
||||
<room name='Random Room'>
|
||||
<event guid='023eb047-5a42-41e0-b1ec-e9fab19b2987' id='42'>
|
||||
<date>2042-01-02T13:30:00+00:00</date>
|
||||
<title>Minimum Setup Test</title>
|
||||
<subtitle>With a subtitle</subtitle>
|
||||
<start>13:30</start>
|
||||
<duration>00:30</duration>
|
||||
<room>Rooming</room>
|
||||
<slug>minimum-setup-test</slug>
|
||||
<track>Testing</track>
|
||||
<type>Talk</type>
|
||||
<abstract>A minimal description</abstract>
|
||||
</event>
|
||||
</room>
|
||||
<room name='Another Room'>
|
||||
</room>
|
||||
</day>
|
||||
<day index='2' date='2042-01-03' start='2042-01-03T00:00:00+00:00' end='2042-01-03T22:59:00+00:00'>
|
||||
</day>
|
||||
</schedule>
|
|
@ -24,8 +24,15 @@ class XmlParserTest extends TestCase
|
|||
libxml_use_internal_errors(true);
|
||||
|
||||
$parser = new XmlParser();
|
||||
|
||||
// Invalid XML
|
||||
$this->assertFalse($parser->load('foo'));
|
||||
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule.xml')));
|
||||
// Minimal import
|
||||
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-minimal.xml')));
|
||||
// Basic import
|
||||
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-basic.xml')));
|
||||
// Extended import
|
||||
$this->assertTrue($parser->load(file_get_contents(__DIR__ . '/Assets/schedule-extended.xml')));
|
||||
|
||||
$schedule = $parser->getSchedule();
|
||||
$this->assertEquals('Some version string', $schedule->getVersion());
|
||||
|
@ -50,5 +57,6 @@ class XmlParserTest extends TestCase
|
|||
$this->assertEquals('de', $event->getLanguage());
|
||||
$this->assertEquals('12:30', $event->getStart());
|
||||
$this->assertEquals([1234 => 'Some Person'], $event->getPersons());
|
||||
$this->assertEquals('https://foo.bar/baz/schedule/ipsum/recording.mp4', $event->getVideoDownloadUrl());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue