-
Notifications
You must be signed in to change notification settings - Fork 7
/
XmlTvSpec.php
132 lines (113 loc) · 5.38 KB
/
XmlTvSpec.php
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace spec\XmlTv;
use XmlTv\Exceptions\ValidationException;
use XmlTv\Tv;
use XmlTv\XmlElement;
use XmlTv\XmlTv;
use PhpSpec\ObjectBehavior;
class XmlTvSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(XmlTv::class);
}
function it_generates_an_xml_file_from_an_empty_tv_object()
{
$xml = file_get_contents(__DIR__.'/../epg-empty.xml');
$this->generate(new Tv(), false)->shouldReturn($xml);
}
function it_generates_a_basic_xml_file()
{
$xml = file_get_contents(__DIR__.'/../epg-basic.xml');
$tv = new Tv();
$channel = new Tv\Channel('test');
$channel->addDisplayName(new Tv\Elements\DisplayName('foo'));
$programme = new Tv\Programme('test', '1', '2');
$programme->addTitle(new Tv\Elements\Title('bar'));
$programme->video = new Tv\Elements\Video('yes');
$programme->audio = new Tv\Elements\Audio('no');
$tv->addChannel($channel);
$tv->addProgramme($programme);
$this->generate($tv, false)->shouldReturn($xml);
}
function it_generates_a_xml_file()
{
$xml = file_get_contents(__DIR__.'/../epg.xml');
$date = gmdate(Tv::DATE_FORMAT, 100000);
$tv = new Tv($date, 'http://thesource.test/');
$channel = new Tv\Channel('test');
$channel->addDisplayName(new Tv\Elements\DisplayName('test', 'en'));
$channel->addDisplayName(new Tv\Elements\DisplayName('test', 'de'));
$channel->addIcon(new Tv\Elements\Icon('http://foo.bar/img.png', '200', '200'));
$channel->addUrl(new Tv\Elements\Url('http://foo.bar/'));
$programme = new Tv\Programme('test', '1', '2');
$programme->catchupId = 'plugin://plugin.video.test/?catchup-id=foo';
$programme->addTitle(new Tv\Elements\Title('title'));
$programme->addSubTitle(new Tv\Elements\SubTitle('subtitle'));
$programme->addDescription(new Tv\Elements\Desc('desc'));
$credits = new Tv\Elements\Credits();
$credits->director[] = new Tv\Elements\Credits\Director('Michael May');
$credits->actor[] = new Tv\Elements\Credits\Actor('Com Truise', 'Lead');
$credits->actor[] = new Tv\Elements\Credits\Actor('Foo Bar', 'Supporting');
$credits->writer[] = new Tv\Elements\Credits\Writer('Wri Te');
$credits->adapter[] = new Tv\Elements\Credits\Adapter('Adap Ter');
$credits->producer[] = new Tv\Elements\Credits\Producer('Pro Ducer');
$credits->composer[] = new Tv\Elements\Credits\Composer('Com Poser');
$credits->editor[] = new Tv\Elements\Credits\Editor('Edi Thor');
$credits->presenter[] = new Tv\Elements\Credits\Presenter('Pre Senter');
$credits->commentator[] = new Tv\Elements\Credits\Commentator('Com Mentator');
$credits->guest[] = new Tv\Elements\Credits\Guest('Lan Stee');
$programme->addCredits($credits);
$programme->date = new Tv\Elements\Date('1999');
$programme->addCategory(new Tv\Elements\Category('category'));
$programme->addKeyword(new Tv\Elements\Keyword('keyword'));
$programme->language = new Tv\Elements\Language('de');
$programme->origLanguage = new Tv\Elements\OrigLanguage('fr');
$programme->length = new Tv\Elements\Length('200', Tv\Elements\Length\Unit::MINUTES);
$programme->addIcon(new Tv\Elements\Icon('http://foo.bar/x.png'));
$programme->addUrl(new Tv\Elements\Url('http://programme.test/'));
$programme->addCountry(new Tv\Elements\Country('France', 'en'));
$programme->addEpisodeNum(new Tv\Elements\EpisodeNum('1'));
$programme->video = new Tv\Elements\Video('yes', 'yes', '4:3', 'UHD');
$programme->audio = new Tv\Elements\Audio('yes', 'stereo');
$programme->previouslyShown = new Tv\Elements\PreviouslyShown('', 'foo');
$programme->premiere = new Tv\Elements\Premiere('Premiered on PHPTV');
$programme->lastChance = new Tv\Elements\LastChance('Get it while it is hot!', 'en');
$programme->new = new Tv\Elements\NewProgramme();
$subtitles = new Tv\Elements\Subtitles(Tv\Elements\Subtitles\Type::ONSCREEN);
$subtitles->language = new Tv\Elements\Language('en');
$programme->addSubtitles($subtitles);
$rating = new Tv\Elements\Rating('Good');
$rating->addIcon(new Tv\Elements\Icon('http://foo.bar/icon.png', '500', '400'));
$programme->addRating($rating);
$programme->addStarRating(new Tv\Elements\StarRating('5'));
$programme->addReview(new Tv\Elements\Review('Very nice!', Tv\Elements\Review\Type::TEXT));
$tv->addChannel($channel);
$tv->addProgramme($programme);
$this->generate($tv, false)->shouldReturn($xml);
}
function it_throws_if_the_generated_xml_does_not_validate()
{
$this->shouldThrow(ValidationException::class)->duringGenerate(new InvalidTv(), true);
}
function it_throws_if_an_element_cannot_be_serialized()
{
$this->shouldThrow(\TypeError::class)->duringGenerate(new UnserializableChild(), false);
}
}
class InvalidTv extends Tv
{
public function xmlSerialize(): XmlElement
{
return (new XmlElement('tv'))
->withAttribute('invalid', 'foo');
}
}
class UnserializableChild extends Tv
{
public function xmlSerialize(): XmlElement
{
return (new XmlElement('tv'))
->withChild(new \stdClass());
}
}