forked from ben-xo/dir2cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPodcastTest.php
128 lines (105 loc) · 4.4 KB
/
PodcastTest.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
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class PodcastTest extends TestCase
{
public static function setUpBeforeClass(): void
{
}
public function newPodcast()
{
return new MyPodcast();
}
public function test_generate_with_defaults_is_valid_xml()
{
$mp = $this->newPodcast();
$content = $mp->generate();
$data = simplexml_load_string($content);
$this->assertEquals('2.0', $data->attributes()->version);
$this->assertNotNull($data->channel->title);
$this->assertNotNull($data->channel->link);
$this->assertNotNull($data->channel->description);
$this->assertNotNull($data->channel->language);
$this->assertNotNull($data->channel->ttl);
$this->assertNotNull($data->channel->webMaster);
$this->assertNotNull($data->channel->copyright);
$this->assertNotNull($data->channel->lastBuildDate);
$this->assertNotNull($data->channel->generator);
}
public function test_generate_with_defaults_has_current_build_date()
{
$mp = $this->newPodcast();
$content = $mp->generate();
$data = simplexml_load_string($content);
$this->assertGreaterThan(time() - 100, strtotime((string)$data->channel->lastBuildDate));
$this->assertLessThan(time() + 100, strtotime((string)$data->channel->lastBuildDate));
}
public function test_basic_feed_properties()
{
$mp = $this->newPodcast();
$mp->setTitle('the title');
$mp->setLink('http://www.example.com/');
$mp->setDescription('You may be eaten by a grue');
$mp->setLanguage('en-gb');
$mp->setTtl('100');
$mp->setWebMaster('Ben XO');
$mp->setCopyright('1984');
$mp->setGenerator('The Unit Test Factory');
$content = $mp->generate();
$data = simplexml_load_string($content);
$this->assertEquals('the title', $data->channel->title);
$this->assertEquals('http://www.example.com/', $data->channel->link);
$this->assertEquals('You may be eaten by a grue', $data->channel->description);
$this->assertEquals('en-gb', $data->channel->language);
$this->assertEquals('100', $data->channel->ttl);
$this->assertEquals('Ben XO', $data->channel->webMaster);
$this->assertEquals('1984', $data->channel->copyright);
$this->assertEquals('The Unit Test Factory', $data->channel->generator);
}
public function test_dynamic_copyright_year()
{
$mp = $this->newPodcast();
$mp->setCopyright('Copyright Ben XO %YEAR%');
$content = $mp->generate();
$data = simplexml_load_string($content);
$this->assertEquals('Copyright Ben XO ' . date('Y'), $data->channel->copyright);
}
public function test_feed_no_image()
{
$mp = $this->newPodcast();
$content = $mp->generate();
$data = simplexml_load_string($content);
foreach ($data->channel->children() as $el) {
$this->assertNotEquals('image', $el->getName());
}
}
public function test_feed_with_image()
{
$mp = $this->newPodcast();
$mp->setImage('image.jpg');
$mp->setLink('http://www.example.com/');
$mp->setTitle('Something');
$content = $mp->generate();
$data = simplexml_load_string($content);
$this->assertNotNull($data->channel->image);
$this->assertEquals('image.jpg', $data->channel->image->url);
$this->assertEquals('http://www.example.com/', $data->channel->image->link);
$this->assertEquals('Something', $data->channel->image->title);
}
public function test_html_entities_are_rss_compatible()
{
$mp = $this->newPodcast();
$mp->setTitle("<\x06<\x07<\x08");
$mp->setDescription('⛄️');
$mp->setWebMaster('>>>');
$mp->setGenerator('&');
$content = $mp->generate();
$data = simplexml_load_string($content);
$this->assertEquals('<<<', $data->channel->title);
$this->assertEquals('⛄️', $data->channel->description);
$this->assertEquals('>>>', $data->channel->webMaster);
$this->assertEquals('&', $data->channel->generator);
$this->assertEquals(0, preg_match('/&/', $content));
$this->assertEquals(0, preg_match('/</', $content));
$this->assertEquals(0, preg_match('/>/', $content));
}
}