|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PODEntender\Application\Service\FileProcessing; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use PODEntender\Domain\Model\Feed\ChannelBuilder; |
|
7
|
|
|
use PODEntender\Domain\Model\Feed\FeedBuilder; |
|
8
|
|
|
use PODEntender\Domain\Model\Feed\ItemBuilder; |
|
9
|
|
|
use PODEntender\Domain\Model\FileProcessing\RssFeedConfiguration; |
|
10
|
|
|
use PODEntender\Domain\Model\Post\AudioEpisode; |
|
11
|
|
|
use PODEntender\Domain\Model\Post\AudioEpisodeCollection; |
|
12
|
|
|
use PODEntender\Domain\Model\Post\PostRepository; |
|
13
|
|
|
use SimpleXMLElement; |
|
14
|
|
|
|
|
15
|
|
|
class GenerateRssFeedTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var GenerateRssFeed */ |
|
18
|
|
|
private $generateRssFeed; |
|
19
|
|
|
|
|
20
|
|
|
/** @var PostRepository */ |
|
21
|
|
|
private $postRepository; |
|
22
|
|
|
|
|
23
|
|
|
/** @var RssFeedConfiguration */ |
|
24
|
|
|
private $rssConfiguration; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->postRepository = $this->prophesize(PostRepository::class); |
|
29
|
|
|
|
|
30
|
|
|
$this->generateRssFeed = new GenerateRssFeed( |
|
31
|
|
|
new FeedBuilder(), |
|
32
|
|
|
$this->postRepository->reveal() |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$this->rssConfiguration = new RssFeedConfiguration( |
|
36
|
|
|
'My Test Title', |
|
37
|
|
|
'My Test Subtitle', |
|
38
|
|
|
'My Test Description', |
|
39
|
|
|
\DateTime::createFromFormat('Y-m-d', '2019-05-01'), |
|
|
|
|
|
|
40
|
|
|
'pt-BR', |
|
41
|
|
|
'My Test Generator', |
|
42
|
|
|
'MY Test Managing Editor', |
|
43
|
|
|
'My Test Image Url', |
|
44
|
|
|
'My Test Url', |
|
45
|
|
|
'My Test Feed Url', |
|
46
|
|
|
'My Test Author', |
|
47
|
|
|
'My Test Explicit', |
|
48
|
|
|
'My Test Type', |
|
49
|
|
|
'My Test Email', |
|
50
|
|
|
'My Test Category', |
|
51
|
|
|
'my/test/output.xml' |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testValidRssElementIsGenerated(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->postRepository->withAudio()->willReturn(new AudioEpisodeCollection()); |
|
58
|
|
|
|
|
59
|
|
|
$outputFile = $this->generateRssFeed->execute($this->rssConfiguration); |
|
60
|
|
|
$reader = new SimpleXMLElement($outputFile->content()); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals('rss', $reader->getName()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testDestinationPathMatchesConfiguration(): void |
|
66
|
|
|
{ |
|
67
|
|
|
$this->postRepository->withAudio()->willReturn(new AudioEpisodeCollection()); |
|
68
|
|
|
|
|
69
|
|
|
$outputFile = $this->generateRssFeed->execute($this->rssConfiguration); |
|
70
|
|
|
$this->assertEquals($this->rssConfiguration->outputFilepath(), $outputFile->path()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testRssConfigurationIsPresentOnXml(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->postRepository->withAudio()->willReturn(new AudioEpisodeCollection()); |
|
76
|
|
|
|
|
77
|
|
|
$outputFile = $this->generateRssFeed->execute($this->rssConfiguration); |
|
78
|
|
|
$reader = new SimpleXMLElement($outputFile->content()); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals($this->rssConfiguration->title(), $reader->channel->title); |
|
81
|
|
|
$this->assertEquals($this->rssConfiguration->url(), $reader->channel->link); |
|
82
|
|
|
$this->assertEquals($this->rssConfiguration->description(), $reader->channel->description); |
|
83
|
|
|
$this->assertEquals( |
|
84
|
|
|
$this->rssConfiguration->lastBuildDate()->format(ChannelBuilder::DATE_FORMAT), |
|
85
|
|
|
$reader->channel->lastBuildDate |
|
86
|
|
|
); |
|
87
|
|
|
$this->assertEquals($this->rssConfiguration->language(), $reader->channel->language); |
|
88
|
|
|
$this->assertEquals($this->rssConfiguration->generator(), $reader->channel->generator); |
|
89
|
|
|
$this->assertEquals($this->rssConfiguration->managingEditor(), $reader->channel->managingEditor); |
|
90
|
|
|
$this->assertEquals($this->rssConfiguration->category(), $reader->channel->category); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertEquals($this->rssConfiguration->title(), $reader->channel->image->title); |
|
93
|
|
|
$this->assertEquals($this->rssConfiguration->imageUrl(), $reader->channel->image->url); |
|
94
|
|
|
$this->assertEquals($this->rssConfiguration->url(), $reader->channel->image->link); |
|
95
|
|
|
|
|
96
|
|
|
$atomLink = $reader->xpath('channel/atom:link')[0]; |
|
97
|
|
|
$this->assertEquals($this->rssConfiguration->feedUrl(), $atomLink['href']); |
|
98
|
|
|
$this->assertEquals('self', $atomLink['rel']); |
|
99
|
|
|
$this->assertEquals('application/rss+xml', $atomLink['type']); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertEquals($this->rssConfiguration->subtitle(), $reader->xpath('channel/itunes:subtitle')[0]); |
|
102
|
|
|
$this->assertEquals($this->rssConfiguration->description(), $reader->xpath('channel/itunes:summary')[0]); |
|
103
|
|
|
$this->assertEquals($this->rssConfiguration->author(), $reader->xpath('channel/itunes:author')[0]); |
|
104
|
|
|
$this->assertEquals($this->rssConfiguration->explicit(), $reader->xpath('channel/itunes:explicit')[0]); |
|
105
|
|
|
$this->assertEquals($this->rssConfiguration->type(), $reader->xpath('channel/itunes:type')[0]); |
|
106
|
|
|
$this->assertEquals( |
|
107
|
|
|
$this->rssConfiguration->category(), |
|
108
|
|
|
$reader->xpath('channel/itunes:category')[0]['text'] |
|
109
|
|
|
); |
|
110
|
|
|
$this->assertEquals( |
|
111
|
|
|
$this->rssConfiguration->imageUrl(), |
|
112
|
|
|
$reader->xpath('channel/itunes:image')[0]['href'] |
|
113
|
|
|
); |
|
114
|
|
|
$this->assertEquals( |
|
115
|
|
|
$this->rssConfiguration->author(), |
|
116
|
|
|
$reader->xpath('channel/itunes:owner/itunes:name')[0] |
|
117
|
|
|
); |
|
118
|
|
|
$this->assertEquals( |
|
119
|
|
|
$this->rssConfiguration->email(), |
|
120
|
|
|
$reader->xpath('channel/itunes:owner/itunes:email')[0] |
|
121
|
|
|
); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertEquals( |
|
124
|
|
|
$this->rssConfiguration->description(), |
|
125
|
|
|
$reader->xpath('channel/googleplay:description')[0] |
|
126
|
|
|
); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function testAudioItemsArePresentOnXml(): void |
|
130
|
|
|
{ |
|
131
|
|
|
$episode = $this->prophesize(AudioEpisode::class); |
|
132
|
|
|
$episode->guid()->willReturn('My Test Guid'); |
|
133
|
|
|
$episode->title()->willReturn('My Test Title'); |
|
134
|
|
|
$episode->description()->willReturn('My Test Description'); |
|
135
|
|
|
$episode->audioCover()->willReturn('My Test Audio Cover'); |
|
136
|
|
|
$episode->audioUrl()->willReturn('My Test Audio Url'); |
|
137
|
|
|
$episode->author()->willReturn('My Test Author'); |
|
138
|
|
|
$episode->url()->willReturn('My Test Url'); |
|
139
|
|
|
$episode->createdAt()->willReturn(\DateTime::createFromFormat('Y-m-d', '2019-01-01')); |
|
140
|
|
|
$episode->updatedAt()->willReturn(\DateTime::createFromFormat('Y-m-d', '2019-01-01')); |
|
141
|
|
|
$episode->duration()->willReturn('00:00:00'); |
|
142
|
|
|
$episode->category()->willReturn('My Test Category'); |
|
143
|
|
|
|
|
144
|
|
|
$actualEpisode = $episode->reveal(); |
|
145
|
|
|
$this->postRepository->withAudio()->willReturn(new AudioEpisodeCollection([$actualEpisode])); |
|
146
|
|
|
|
|
147
|
|
|
$reader = new SimpleXMLElement($this->generateRssFeed->execute($this->rssConfiguration)->content()); |
|
148
|
|
|
|
|
149
|
|
|
$this->assertEquals($actualEpisode->title(), $reader->xpath('channel/item/title')[0]); |
|
150
|
|
|
$this->assertEquals($actualEpisode->url(), $reader->xpath('channel/item/link')[0]); |
|
151
|
|
|
$this->assertEquals($actualEpisode->url(), $reader->xpath('channel/item/comments')[0]); |
|
152
|
|
|
$this->assertEquals( |
|
153
|
|
|
$actualEpisode->createdAt()->format(ItemBuilder::DATE_FORMAT), |
|
154
|
|
|
$reader->xpath('channel/item/pubDate')[0] |
|
155
|
|
|
); |
|
156
|
|
|
$this->assertEquals($actualEpisode->guid(), $reader->xpath('channel/item/guid')[0]); |
|
157
|
|
|
$this->assertEquals('false', $reader->xpath('channel/item/guid')[0]['isPermaLink']); |
|
158
|
|
|
|
|
159
|
|
|
$category = $reader->xpath('channel/item/category')[0]; |
|
160
|
|
|
$this->assertEquals($actualEpisode->category(), $category); |
|
161
|
|
|
$this->assertStringContainsString('CDATA', $category->asXML()); |
|
162
|
|
|
|
|
163
|
|
|
$enclosure = $reader->xpath('channel/item/enclosure')[0]; |
|
164
|
|
|
$this->assertEquals($actualEpisode->audioUrl(), $enclosure['url']); |
|
165
|
|
|
$this->assertEquals('audio/mpeg', $enclosure['type']); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertEquals($actualEpisode->description(), $reader->xpath('channel/item/itunes:subtitle')[0]); |
|
168
|
|
|
$this->assertEquals($actualEpisode->description(), $reader->xpath('channel/item/itunes:summary')[0]); |
|
169
|
|
|
$this->assertEquals($actualEpisode->author(), $reader->xpath('channel/item/itunes:author')[0]); |
|
170
|
|
|
$this->assertEquals( |
|
171
|
|
|
$this->rssConfiguration->explicit(), |
|
172
|
|
|
$reader->xpath('channel/item/itunes:explicit')[0] |
|
173
|
|
|
); |
|
174
|
|
|
$this->assertEquals($actualEpisode->duration(), $reader->xpath('channel/item/itunes:duration')[0]); |
|
175
|
|
|
$this->assertEquals($actualEpisode->audioCover(), $reader->xpath('channel/item/itunes:image')[0]['href']); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|