video_block_test.rb
6.79 KB
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
require File.dirname(__FILE__) + '/../test_helper'
class VideoBlockTest < ActiveSupport::TestCase
### Tests for YouTube
should "is_youtube return true when the url contains http://youtube.com" do
block = VideoBlock.new
block.url = "http://youtube.com/?v=XXXXX"
assert block.is_youtube?
end
should "is_youtube return true when the url contains https://youtube.com" do
block = VideoBlock.new
block.url = "https://youtube.com/?v=XXXXX"
assert block.is_youtube?
end
should "is_youtube return true when the url contains https://www.youtube.com" do
block = VideoBlock.new
block.url = "https://www.youtube.com/?v=XXXXX"
assert block.is_youtube?
end
should "is_youtube return true when the url contains www.youtube.com" do
block = VideoBlock.new
block.url = "www.youtube.com/?v=XXXXX"
assert block.is_youtube?
end
should "is_youtube return true when the url contains youtube.com" do
block = VideoBlock.new
block.url = "youtube.com/?v=XXXXX"
assert block.is_youtube?
end
should "is_youtube return false when the url not contains youtube video ID" do
block = VideoBlock.new
block.url = "youtube.com/"
assert !block.is_youtube?
end
should "is_youtube return false when the url contains empty youtube video ID" do
block = VideoBlock.new
block.url = "youtube.com/?v="
assert !block.is_youtube?
end
should "is_youtube return false when the url contains an invalid youtube link" do
block = VideoBlock.new
block.url = "http://www.yt.com/?v=XXXXX"
assert !block.is_youtube?
end
should "format embed video for youtube videos" do
block = VideoBlock.new
block.url = "youtube.com/?v=XXXXX"
assert_match /\/\/www.youtube-nocookie.com\/embed/, block.format_embed_video_url_for_youtube
end
should "format embed video return nil if is not a youtube url" do
block = VideoBlock.new
block.url = "http://www.yt.com/?v=XXXXX"
assert_nil block.format_embed_video_url_for_youtube
end
should "extract youtube id from youtube video url's if it's a valid youtube full url" do
block = VideoBlock.new
id = 'oi43jre2d2'
block.url = "youtube.com/?v=#{id}"
assert_equal id, block.send('extract_youtube_id')
end
should "extract youtube id from youtube video url's if it has underline and hyphen" do
block = VideoBlock.new
id = 'oi43_re-d2'
block.url = "youtube.com/?v=#{id}"
assert_equal id, block.send('extract_youtube_id')
end
should "extract youtube id from youtube video url's if it's a valid youtube short url" do
block = VideoBlock.new
id = 'oi43jre2d2'
block.url = "youtu.be/#{id}"
assert_equal id, block.send('extract_youtube_id')
end
should "extract_youtube_id return nil if the url it's not a valid youtube url" do
block = VideoBlock.new
block.url = "http://www.yt.com/?v=XXXXX"
assert_nil block.send('extract_youtube_id')
end
should "extract_youtube_id return nil if youtue url there is no id" do
block = VideoBlock.new
block.url = "youtube.com/"
assert_nil block.send('extract_youtube_id')
end
#### Tests for Vimeo Videos
should "is_vimeo return true when the url contains http://vimeo.com" do
block = VideoBlock.new
block.url = "http://vimeo.com/98979"
assert block.is_vimeo?
end
should "is_vimeo return true when the url contains https://vimeo.com" do
block = VideoBlock.new
block.url = "https://vimeo.com/989798"
assert block.is_vimeo?
end
should "is_vimeo return true when the url contains https://www.vimeo.com" do
block = VideoBlock.new
block.url = "https://www.vimeo.com/98987"
assert block.is_vimeo?
end
should "is_vimeo return true when the url contains www.vimeo.com" do
block = VideoBlock.new
block.url = "www.vimeo.com/989798"
assert block.is_vimeo?
end
should "is_vimeo return true when the url contains vimeo.com" do
block = VideoBlock.new
block.url = "vimeo.com/09898"
assert block.is_vimeo?
end
should "is_vimeo return false when the url not contains vimeo video ID" do
block = VideoBlock.new
block.url = "vimeo.com/home"
assert !block.is_vimeo?
end
should "is_vimeo return false when the url contains empty vimeo video ID" do
block = VideoBlock.new
block.url = "vimeo.com/"
assert !block.is_vimeo?
end
should "is_vimeo return false when the url contains an invalid vimeo link" do
block = VideoBlock.new
block.url = "http://www.vmsd.com/98979"
assert !block.is_vimeo?
end
should "format embed video for vimeo videos" do
block = VideoBlock.new
block.url = "vimeo.com/09898"
assert_match /\/\/player.vimeo.com\/video\/[[:digit:]]+/, block.format_embed_video_url_for_vimeo
end
should "format embed video return nil if is not a vimeo url" do
block = VideoBlock.new
block.url = "http://www.yt.com/?v=XXXXX"
assert_nil block.format_embed_video_url_for_vimeo
end
should "extract vimeo id from vimeo video url's if it's a valid vimeo url" do
block = VideoBlock.new
id = '23048239432'
block.url = "vimeo.com/#{id}"
assert_equal id, block.send('extract_vimeo_id')
end
should "extract_vimeo_id return nil if the url it's not a valid vimeo url" do
block = VideoBlock.new
block.url = "http://www.yt.com/XXXXX"
assert_nil block.send('extract_vimeo_id')
end
should "extract_vimeo_id return nil if vimeo url there is no id" do
block = VideoBlock.new
block.url = "vimeo.com/"
assert_nil block.send('extract_youtube_id')
end
# Other video formats
should "is_video return true if url ends with mp4" do
block = VideoBlock.new
block.url = "http://www.vmsd.com/98979.mp4"
assert block.is_video_file?
end
should "is_video return true if url ends with ogg" do
block = VideoBlock.new
block.url = "http://www.vmsd.com/98979.ogg"
assert block.is_video_file?
end
should "is_video return true if url ends with ogv" do
block = VideoBlock.new
block.url = "http://www.vmsd.com/98979.ogv"
assert block.is_video_file?
end
should "is_video return true if url ends with webm" do
block = VideoBlock.new
block.url = "http://www.vmsd.com/98979.webm"
assert block.is_video_file?
end
should "is_video return false if url ends without mp4, ogg, ogv, webm" do
block = VideoBlock.new
block.url = "http://www.vmsd.com/98979.mp4r"
assert !block.is_video_file?
block.url = "http://www.vmsd.com/98979.oggr"
assert !block.is_video_file?
block.url = "http://www.vmsd.com/98979.ogvr"
assert !block.is_video_file?
block.url = "http://www.vmsd.com/98979.webmr"
assert !block.is_video_file?
end
should 'display video block partial' do
block = VideoBlock.new
self.expects(:render).with(:file => 'video_block', :locals => {
:block => block
})
instance_eval(& block.content)
end
end