forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PodcastFeedTests.swift
281 lines (238 loc) · 9.95 KB
/
PodcastFeedTests.swift
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/**
* Plot
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Plot
final class PodcastFeedTests: XCTestCase {
func testEmptyFeed() {
let feed = PodcastFeed()
assertEqualPodcastFeedContent(feed, "")
}
func testNewFeedURL() {
let feed = PodcastFeed(.newFeedURL("url.com"))
assertEqualPodcastFeedContent(feed, "<itunes:new-feed-url>url.com</itunes:new-feed-url>")
}
func testPodcastTitle() {
let feed = PodcastFeed(.title("MyPodcast"))
assertEqualPodcastFeedContent(feed, "<title>MyPodcast</title>")
}
func testPodcastSubtitle() {
let feed = PodcastFeed(.subtitle("Subtitle"))
assertEqualPodcastFeedContent(feed, "<itunes:subtitle>Subtitle</itunes:subtitle>")
}
func testPodcastDescription() {
let feed = PodcastFeed(.description("Description"))
assertEqualPodcastFeedContent(feed, "<description>Description</description>")
}
func testPodcastSummary() {
let feed = PodcastFeed(.summary("Summary"))
assertEqualPodcastFeedContent(feed, "<itunes:summary>Summary</itunes:summary>")
}
func testPodcastURL() {
let feed = PodcastFeed(.link("url.com"))
assertEqualPodcastFeedContent(feed, "<link>url.com</link>")
}
func testPodcastAtomLink() {
let feed = PodcastFeed(.atomLink("url.com"))
assertEqualPodcastFeedContent(feed, """
<atom:link href="url.com" rel="self" type="application/rss+xml"/>
""")
}
func testPodcastLanguage() {
let feed = PodcastFeed(.language("en-US"))
assertEqualPodcastFeedContent(feed, "<language>en-US</language>")
}
func testPodcastTTL() {
let feed = PodcastFeed(.ttl(200))
assertEqualPodcastFeedContent(feed, "<ttl>200</ttl>")
}
func testPodcastCopyright() {
let feed = PodcastFeed(.copyright("Copyright"))
assertEqualPodcastFeedContent(feed, "<copyright>Copyright</copyright>")
}
func testPodcastAuthor() {
let feed = PodcastFeed(.author("Author"))
assertEqualPodcastFeedContent(feed, "<itunes:author>Author</itunes:author>")
}
func testPodcastExplicitFlag() {
let explicitFeed = PodcastFeed(.explicit(true))
assertEqualPodcastFeedContent(explicitFeed, "<itunes:explicit>yes</itunes:explicit>")
let nonExplicitFeed = PodcastFeed(.explicit(false))
assertEqualPodcastFeedContent(nonExplicitFeed, "<itunes:explicit>no</itunes:explicit>")
}
func testPodcastOwner() {
let feed = PodcastFeed(.owner(.name("Name"), .email("Email")))
assertEqualPodcastFeedContent(feed, """
<itunes:owner><itunes:name>Name</itunes:name><itunes:email>Email</itunes:email></itunes:owner>
""")
}
func testPodcastCategory() {
let feed = PodcastFeed(.category("News"))
assertEqualPodcastFeedContent(feed, #"<itunes:category text="News"/>"#)
}
func testPodcastSubcategory() {
let feed = PodcastFeed(.category("News", .category("Tech News")))
assertEqualPodcastFeedContent(feed, """
<itunes:category text="News"><itunes:category text="Tech News"/></itunes:category>
""")
}
func testPodcastType() {
let episodicFeed = PodcastFeed(.type(.episodic))
assertEqualPodcastFeedContent(episodicFeed, "<itunes:type>episodic</itunes:type>")
let serialFeed = PodcastFeed(.type(.serial))
assertEqualPodcastFeedContent(serialFeed, "<itunes:type>serial</itunes:type>")
}
func testPodcastImage() {
let feed = PodcastFeed(.image("image.png"))
assertEqualPodcastFeedContent(feed, #"<itunes:image href="image.png"/>"#)
}
func testPodcastPublicationDate() throws {
let stubs = try Date.makeStubs(withFormattingStyle: .rss)
let feed = PodcastFeed(.pubDate(stubs.date, timeZone: stubs.timeZone))
assertEqualPodcastFeedContent(feed, "<pubDate>\(stubs.expectedString)</pubDate>")
}
func testPodcastLastBuildDate() throws {
let stubs = try Date.makeStubs(withFormattingStyle: .rss)
let feed = PodcastFeed(.lastBuildDate(stubs.date, timeZone: stubs.timeZone))
assertEqualPodcastFeedContent(feed, "<lastBuildDate>\(stubs.expectedString)</lastBuildDate>")
}
func testEpisodeGUID() {
let guidFeed = PodcastFeed(.item(.guid("123")))
assertEqualPodcastFeedContent(guidFeed, "<item><guid>123</guid></item>")
let permaLinkFeed = PodcastFeed(.item(.guid("url.com", .isPermaLink(true))))
assertEqualPodcastFeedContent(permaLinkFeed, """
<item><guid isPermaLink="true">url.com</guid></item>
""")
let nonPermaLinkFeed = PodcastFeed(.item(.guid("123", .isPermaLink(false))))
assertEqualPodcastFeedContent(nonPermaLinkFeed, """
<item><guid isPermaLink="false">123</guid></item>
""")
}
func testEpisodeTitle() {
let feed = PodcastFeed(.item(.title("Title")))
assertEqualPodcastFeedContent(feed, """
<item><title>Title</title><itunes:title>Title</itunes:title></item>
""")
}
func testEpisodeDescription() {
let feed = PodcastFeed(.item(.description("Description")))
assertEqualPodcastFeedContent(feed, """
<item><description>Description</description></item>
""")
}
func testEpisodeURL() {
let feed = PodcastFeed(.item(.link("url.com")))
assertEqualPodcastFeedContent(feed, "<item><link>url.com</link></item>")
}
func testEpisodePublicationDate() throws {
let stubs = try Date.makeStubs(withFormattingStyle: .rss)
let feed = PodcastFeed(.item(.pubDate(stubs.date, timeZone: stubs.timeZone)))
assertEqualPodcastFeedContent(feed, """
<item><pubDate>\(stubs.expectedString)</pubDate></item>
""")
}
func testEpisodeDuration() {
let feed = PodcastFeed(.item(
.duration("00:15:12"),
.duration(hours: 00, minutes: 15, seconds: 12)
))
assertEqualPodcastFeedContent(feed, """
<item>\
<itunes:duration>00:15:12</itunes:duration>\
<itunes:duration>00:15:12</itunes:duration>\
</item>
""")
}
func testSeasonNumber() {
let feed = PodcastFeed(.item(.seasonNumber(3)))
assertEqualPodcastFeedContent(feed, """
<item><itunes:season>3</itunes:season></item>
""")
}
func testEpisodeNumber() {
let feed = PodcastFeed(.item(.episodeNumber(42)))
assertEqualPodcastFeedContent(feed, """
<item><itunes:episode>42</itunes:episode></item>
""")
}
func testEpisodeType() {
let feed = PodcastFeed(
.item(.episodeType(.full)),
.item(.episodeType(.trailer)),
.item(.episodeType(.bonus))
)
assertEqualPodcastFeedContent(feed, """
<item><itunes:episodeType>full</itunes:episodeType></item>\
<item><itunes:episodeType>trailer</itunes:episodeType></item>\
<item><itunes:episodeType>bonus</itunes:episodeType></item>
""")
}
func testEpisodeAudio() {
let feed = PodcastFeed(.item(.audio(
url: "episode.mp3",
byteSize: 69121733,
title: "Episode"
)))
let expectedComponents = [
"<item>",
#"<enclosure url="episode.mp3" length="69121733" type="audio/mpeg"/>"#,
#"<media:content url="episode.mp3" length="69121733" type="audio/mpeg" isDefault="true" medium="audio">"#,
#"<media:title type="plain">Episode</media:title>"#,
"</media:content>",
"</item>"
]
assertEqualPodcastFeedContent(feed, expectedComponents.joined())
}
func testEpisodeHTMLContent() {
let feed = PodcastFeed(.item(.content(
"<p>Hello</p><p>World & Everyone!</p>"
)))
let expectedComponents = [
"<item>",
"<content:encoded>",
"<![CDATA[<p>Hello</p><p>World & Everyone!</p>]]>",
"</content:encoded>",
"</item>"
]
assertEqualPodcastFeedContent(feed, expectedComponents.joined())
}
}
extension PodcastFeedTests {
static var allTests: Linux.TestList<PodcastFeedTests> {
[
("testEmptyFeed", testEmptyFeed),
("testNewFeedURL", testNewFeedURL),
("testPodcastTitle", testPodcastTitle),
("testPodcastSubtitle", testPodcastSubtitle),
("testPodcastDescription", testPodcastDescription),
("testPodcastSummary", testPodcastSummary),
("testPodcastURL", testPodcastURL),
("testPodcastAtomLink", testPodcastAtomLink),
("testPodcastLanguage", testPodcastLanguage),
("testPodcastTTL", testPodcastTTL),
("testPodcastCopyright", testPodcastCopyright),
("testPodcastAuthor", testPodcastAuthor),
("testPodcastExplicitFlag", testPodcastExplicitFlag),
("testPodcastOwner", testPodcastOwner),
("testPodcastCategory", testPodcastCategory),
("testPodcastSubcategory", testPodcastSubcategory),
("testPodcastType", testPodcastType),
("testPodcastImage", testPodcastImage),
("testPodcastPublicationDate", testPodcastPublicationDate),
("testPodcastLastBuildDate", testPodcastLastBuildDate),
("testEpisodeGUID", testEpisodeGUID),
("testEpisodeTitle", testEpisodeTitle),
("testEpisodeDescription", testEpisodeDescription),
("testEpisodeURL", testEpisodeURL),
("testEpisodePublicationDate", testEpisodePublicationDate),
("testEpisodeDuration", testEpisodeDuration),
("testSeasonNumber", testSeasonNumber),
("testEpisodeNumber", testEpisodeNumber),
("testEpisodeType", testEpisodeType),
("testEpisodeAudio", testEpisodeAudio),
("testEpisodeHTMLContent", testEpisodeHTMLContent)
]
}
}