summaryrefslogtreecommitdiff
path: root/tests/Unit/Helpers/Schedule/XmlParserTest.php
blob: 023e9c7d2faa920644fa8310ccc8f174d59f5929 (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
<?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());
    }
}