forked from ben-xo/dir2cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiTunes_Podcast_HelperTest.php
157 lines (129 loc) · 6.02 KB
/
iTunes_Podcast_HelperTest.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class iTunes_Podcast_HelperTest extends TestCase
{
public function test_adds_namespace_to_podcast()
{
$mp = new MyPodcast();
$mp->addHelper(new iTunes_Podcast_Helper());
$content = $mp->generate();
$this->assertEquals(1, preg_match(
'#<rss[^>]* xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"[^>]*>#',
$content
));
}
public function assertChannelHasElement($expected_element, $expected_value, $channel)
{
$children = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$this->assertEquals($expected_value, $children->$expected_element);
}
public function assertChannelHasElementWithAttribute($expected_element, $expected_attr_name, $expected_value, $channel)
{
$children = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$this->assertEquals(
$expected_value,
$children->$expected_element->attributes()->$expected_attr_name
);
}
public function assertChannelHasElementWithAttributeAtIndex($expected_element, $expected_attr_name, $expected_value, $expected_index, $channel)
{
$children = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$this->assertEquals(
$expected_value,
$children->$expected_element[$expected_index]->attributes()->$expected_attr_name
);
}
public function test_adds_arbitrary_set_params_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->setA('First');
$itunes->setB('Second');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$this->assertChannelHasElement('a', 'First', $data->channel);
$this->assertChannelHasElement('b', 'Second', $data->channel);
}
public function test_adds_simple_category_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->addCategories('Music');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$this->assertChannelHasElementWithAttribute('category', 'text', 'Music', $data->channel);
}
public function test_adds_multiple_categories_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->addCategories('Music, Documentary');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$this->assertChannelHasElementWithAttributeAtIndex('category', 'text', 'Music', 0, $data->channel);
$this->assertChannelHasElementWithAttributeAtIndex('category', 'text', 'Documentary', 1, $data->channel);
}
public function test_adds_multiple_subcategories_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->addCategories('Music > Techno, Documentary > Music & Film');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$this->assertChannelHasElementWithAttributeAtIndex('category', 'text', 'Music', 0, $data->channel);
$this->assertChannelHasElementWithAttributeAtIndex('category', 'text', 'Documentary', 1, $data->channel);
$category = $data->channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd')->category;
$this->assertEquals('Techno', $category[0]->category[0]->attributes()->text);
$this->assertEquals('Music & Film', $category[1]->category[0]->attributes()->text);
}
public function test_adds_owner_name_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->setOwnerName('Ben XO');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$owner = $data->channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd')->owner;
$this->assertEquals('Ben XO', $owner->name);
}
public function test_adds_owner_email_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->setOwnerEmail('[email protected]');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$owner = $data->channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd')->owner;
$this->assertEquals('[email protected]', $owner->email);
}
public function test_adds_both_owner_name_and_email_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->setOwnerName('Ben XO');
$itunes->setOwnerEmail('[email protected]');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$owner = $data->channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd')->owner;
$this->assertEquals('Ben XO', $owner->name);
$this->assertEquals('[email protected]', $owner->email);
}
public function test_adds_explicit_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->setExplicit('yes');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$this->assertChannelHasElement('explicit', 'yes', $data->channel);
}
public function test_adds_image_to_podcast()
{
$mp = new MyPodcast();
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$itunes->setImage('itunes_image.jpg');
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement');
$this->assertChannelHasElementWithAttribute('image', 'href', 'itunes_image.jpg', $data->channel);
}
}