forked from ben-xo/dir2cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSS_ItemTest.php
102 lines (81 loc) · 3.07 KB
/
RSS_ItemTest.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
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class RSS_ItemTest extends TestCase
{
public function newRSSItem()
{
return new RSS_Item();
}
public function getDefaultTitle()
{
return '(untitled)';
}
public function test_rss_item_added_to_podcast_channel()
{
$mp = new MyPodcast();
$item = $this->newRSSItem();
$item->setTitle('item title');
$item->setLink('link.mp3');
$item->setPubDate('today');
$item->setDescription("<<< &&& >>> ⚠️\netc");
$item->setLength("1000000");
$item->setType("test");
$mp->addRssItem($item);
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->assertEquals('item title', $data->channel->item[0]->title);
$this->assertEquals('link.mp3', $data->channel->item[0]->link);
$this->assertEquals('today', $data->channel->item[0]->pubDate);
// description is a CDATA section, so we have to double-decode it
$this->assertEquals(
"<<< &&& >>> ⚠️<br />\netc",
html_entity_decode((string)$data->channel->item[0]->description)
);
$enclosure = $data->channel->item[0]->enclosure;
$this->assertEquals('link.mp3', $enclosure->attributes()->url);
$this->assertEquals('1000000', $enclosure->attributes()->length);
$this->assertEquals('test', $enclosure->attributes()->type);
// no image by default
foreach ($data->channel->item[0] as $el) {
$this->assertNotEquals('image', $el->getName());
}
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_html_description_with_DESCRIPTION_HTML_set()
{
define('DESCRIPTION_HTML', true);
$mp = new MyPodcast();
$item = $this->newRSSItem();
$item->setDescription("<h1>test</h1>");
$mp->addRssItem($item);
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);
// description is a CDATA section, so we have to double-decode it
$this->assertEquals(
"<h1>test</h1>",
(string)$data->channel->item[0]->description
);
}
public function test_rss_item_default_title()
{
$mp = new MyPodcast();
$item = $this->newRSSItem();
$mp->addRssItem($item);
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->assertEquals($this->getDefaultTitle(), $data->channel->item[0]->title);
}
public function test_adds_image_to_item_if_set()
{
$mp = new MyPodcast();
$item = $this->newRSSItem();
$item->setImage('visuals.jpg');
$mp->addRssItem($item);
$content = $mp->generate();
$data = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);
$this->assertEquals('visuals.jpg', $data->channel->item[0]->image);
}
}