diff --git a/plugins/video/README.md b/plugins/video/README.md index 244f1bf..e54b5b8 100644 --- a/plugins/video/README.md +++ b/plugins/video/README.md @@ -49,9 +49,10 @@ See Noosfero license. AUTHORS ======= - Leandro Nunes dos Santos (leandronunes at gmail.com) + Leandro Nunes dos Santos (leandronunes at gmail.com) (Video Block) + Evandro Magalhães Leite Júnior (evandrojr at gmail.com) (Video Gallery & Video Content) ACKNOWLEDGMENTS =============== -The author have been supported by Serpro +The authors have been supported by Serpro diff --git a/plugins/video/lib/ext/article.rb b/plugins/video/lib/ext/article.rb new file mode 100644 index 0000000..8e97c3b --- /dev/null +++ b/plugins/video/lib/ext/article.rb @@ -0,0 +1,31 @@ +require_dependency 'article' + +class Article + + scope :video_gallery, :conditions => ["articles.type = 'VideoPlugin::VideoGallery'"] + + #FIXME This should be done via hotspot + def self.folder_types_with_video + self.folder_types_without_video << 'VideoPlugin::VideoGallery' + end + + #FIXME This should be done via hotspot + class << self + alias_method_chain :folder_types, :video + end + + def self.owner_video_galleries(owner) + conditions = owner.kind_of?(Environment) ? [] : ["profile_id = ?", owner.id] + result = Article.video_gallery.find( + :all, + :order => 'created_at desc', + :conditions => conditions) + end + +end + + + + + + diff --git a/plugins/video/lib/video_block.rb b/plugins/video/lib/video_block.rb deleted file mode 100644 index cbe729a..0000000 --- a/plugins/video/lib/video_block.rb +++ /dev/null @@ -1,62 +0,0 @@ -class VideoBlock < Block - - attr_accessible :url, :width, :height - - settings_items :url, :type => :string, :default => "" - settings_items :width, :type => :integer, :default => 400 - settings_items :height, :type => :integer, :default => 315 - - YOUTUBE_ID_FORMAT = '\w-' - - def is_youtube? - url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false - end - - def is_vimeo? - url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false - end - - def is_video_file? - url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false - end - - def format_embed_video_url_for_youtube - "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? - end - - def format_embed_video_url_for_vimeo - "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? - end - - def self.description - _('Display a Video') - end - - def help - _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') - end - - def content(args={}) - block = self - - proc do - render :file => 'video_block', :locals => { :block => block } - end - end - - private - - def extract_youtube_id - return nil unless is_youtube? - youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") - youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") - youtube_match[1] unless youtube_match.nil? - end - - def extract_vimeo_id - return nil unless is_vimeo? - vimeo_match = url.match('([[:digit:]]*)$') - vimeo_match[1] unless vimeo_match.nil? - end - -end diff --git a/plugins/video/lib/video_plugin.rb b/plugins/video/lib/video_plugin.rb index e3b0a4d..a6d669a 100644 --- a/plugins/video/lib/video_plugin.rb +++ b/plugins/video/lib/video_plugin.rb @@ -1,9 +1,7 @@ -require_dependency File.dirname(__FILE__) + '/video_block' - class VideoPlugin < Noosfero::Plugin def self.plugin_name - "Video Block Plugin" + "Video Content type, Video Block and Video Gallery Plugin" end def self.plugin_description @@ -11,8 +9,37 @@ class VideoPlugin < Noosfero::Plugin end def self.extra_blocks + { VideoPlugin::VideoBlock => {}, VideoPlugin::VideoGalleryBlock => {:position=>['1']} } + end + + def stylesheet? + true + end + + def content_types + [VideoPlugin::VideoGallery, VideoPlugin::Video] + end + + def content_remove_new(content) + if content.kind_of?(VideoPlugin::VideoGallery) or content.kind_of?(VideoPlugin::Video) + true + end + end + + def content_remove_upload(content) + if content.kind_of?(VideoPlugin::VideoGallery) or content.kind_of?(VideoPlugin::Video) + true + end + end + + def article_extra_toolbar_buttons(content) + return [] if !content.kind_of?(VideoPlugin::VideoGallery) { - VideoBlock => {} + :id=>"new-video-btn", + :class=>"button with-text icon-new", + :url=> {:action => 'new', :type=>'VideoPlugin::Video', :controller=>'cms', :parent_id => content.id}, + :title=>_("New Video"), + :icon => :new } end diff --git a/plugins/video/lib/video_plugin/video.rb b/plugins/video/lib/video_plugin/video.rb new file mode 100644 index 0000000..a6b1f19 --- /dev/null +++ b/plugins/video/lib/video_plugin/video.rb @@ -0,0 +1,180 @@ +require 'noosfero/translatable_content' +require 'application_helper' +require 'net/http' + +class VideoPlugin::Video < Article + + settings_items :video_url, :type => :string, :default => 'http://' + settings_items :video_width, :type => :integer, :default => 499 + settings_items :video_height, :type => :integer, :default => 353 + #Video Providers are: youtube, vimeo, file + settings_items :video_provider, :type => :string + settings_items :video_format, :type => :string + settings_items :video_id, :type => :string + settings_items :video_thumbnail_url, :type => :string, :default => '/plugins/video/images/video_generic_thumbnail.jpg' + settings_items :video_thumbnail_width, :type=> :integer + settings_items :video_thumbnail_height, :type=> :integer + settings_items :video_duration, :type=> :integer, :default => 0 + + attr_accessible :video_url + + before_save :fill_video_properties + + def self.type_name + _('Video') + end + + def can_display_versions? + true + end + + def self.short_description + _('Embedded Video') + end + + def self.description + _('Display embedded videos.') + end + + def is_youtube? + VideoPlugin::Video.is_youtube?(self.video_url) + end + + def is_vimeo? + VideoPlugin::Video.is_vimeo?(self.video_url) + end + + include ActionView::Helpers::TagHelper + def to_html(options={}) + article = self + proc do + render :partial => 'content_viewer/video_plugin/video', :locals => {:article => article} + end + end + + def fitted_width + 499 + end + + def fitted_height + ((fitted_width * self.video_height) / self.video_width).to_i + end + + def thumbnail_fitted_width + 80 + end + + def thumbnail_fitted_height + ((thumbnail_fitted_width * self.video_thumbnail_height) / self.video_thumbnail_width).to_i + end + + def no_browser_support_message + '

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

' + end + + def self.is_youtube?(video_url) + video_url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false + end + + def self.is_vimeo?(video_url) + video_url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/([A-z]|\/)*[[:digit:]]+/) ? true : false + end + + def self.is_video_file?(video_url) + video_url.match(/\.(mp4|ogg|ogv|webm)/) ? true : false + end + + def self.format_embed_video_url_for_youtube(video_url) + "//www.youtube-nocookie.com/embed/#{extract_youtube_id(video_url)}?rel=0&wmode=transparent" if is_youtube?(video_url) + end + + def self.format_embed_video_url_for_vimeo(video_url) + "//player.vimeo.com/video/#{extract_vimeo_id(video_url)}" if is_vimeo?(video_url) + end + + def format_embed_video_url_for_youtube + VideoPlugin::Video.format_embed_video_url_for_youtube(self.video_url) + end + + def format_embed_video_url_for_vimeo + VideoPlugin::Video.format_embed_video_url_for_vimeo(self.video_url) + end + + def self.extract_youtube_id(video_url) + return nil unless self.is_youtube?(video_url) + youtube_match = video_url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match ||= video_url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match[1] unless youtube_match.nil? + end + + def self.extract_vimeo_id(video_url) + return nil unless self.is_vimeo?(video_url) + vimeo_match = video_url.match('([[:digit:]]*)$') + vimeo_match[1] unless vimeo_match.nil? + end + + private + + YOUTUBE_ID_FORMAT = '\w-' + + def fill_video_properties + if is_youtube? + fill_youtube_video_properties + elsif is_vimeo? + fill_vimeo_video_properties + elsif true + self.video_format = detect_file_format + self.video_provider = 'file' + end + end + + def fill_youtube_video_properties + self.video_provider = 'youtube' + self.video_id = extract_youtube_id + url = "http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D#{self.video_id}&format=json" + resp = Net::HTTP.get_response(URI.parse(url)) + buffer = resp.body + vid = JSON.parse(buffer) + self.video_thumbnail_url = vid['thumbnail_url'] + self.video_width = vid['width'] + self.video_height = vid['height'] + self.video_thumbnail_width = vid['thumbnail_width'] + self.video_thumbnail_height = vid['thumbnail_height'] + end + + def fill_vimeo_video_properties + self.video_provider = 'vimeo' + self.video_id = extract_vimeo_id + url = "http://vimeo.com/api/v2/video/#{self.video_id}.json" + resp = Net::HTTP.get_response(URI.parse(url)) + buffer = resp.body + vid = JSON.parse(buffer) + vid = vid[0] + self.video_thumbnail_url = vid['thumbnail_large'] + self.video_width = vid['width'] + self.video_height = vid['height'] + self.video_thumbnail_width = 640 + self.video_thumbnail_height = 360 + end + + def detect_file_format + video_type = 'video/unknown' + if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url + video_type='video/mp4' + elsif /.webm/i =~ self.video_url + video_type='video/webm' + elsif /.og[vg]/i =~ self.video_url + video_type='video/ogg' + end + video_type + end + + def extract_youtube_id + VideoPlugin::Video.extract_youtube_id(self.video_url) + end + + def extract_vimeo_id + VideoPlugin::Video.extract_vimeo_id(self.video_url) + end + +end diff --git a/plugins/video/lib/video_plugin/video_block.rb b/plugins/video/lib/video_plugin/video_block.rb new file mode 100644 index 0000000..fac16d7 --- /dev/null +++ b/plugins/video/lib/video_plugin/video_block.rb @@ -0,0 +1,57 @@ +class VideoPlugin::VideoBlock < Block + + attr_accessible :url, :width, :height + + settings_items :url, :type => :string, :default => "" + settings_items :width, :type => :integer, :default => 400 + settings_items :height, :type => :integer, :default => 315 + + YOUTUBE_ID_FORMAT = '\w-' + + def is_youtube? + VideoPlugin::Video.is_youtube?(url) + end + + def is_vimeo? + VideoPlugin::Video.is_vimeo?(url) + end + + def is_video_file? + url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false + end + + def format_embed_video_url_for_youtube + VideoPlugin::Video.format_embed_video_url_for_youtube(url) + end + + def format_embed_video_url_for_vimeo + VideoPlugin::Video.format_embed_video_url_for_vimeo(url) + end + + def self.description + _('Display a Video') + end + + def help + _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') + end + + def content(args={}) + block = self + + proc do + render :file => 'video_block', :locals => { :block => block } + end + end + + private + + def extract_youtube_id + VideoPlugin::Video.extract_youtube_id(url) + end + + def extract_vimeo_id + VideoPlugin::Video.extract_vimeo_id(url) + end + +end diff --git a/plugins/video/lib/video_plugin/video_gallery.rb b/plugins/video/lib/video_plugin/video_gallery.rb new file mode 100644 index 0000000..2159550 --- /dev/null +++ b/plugins/video/lib/video_plugin/video_gallery.rb @@ -0,0 +1,63 @@ +class VideoPlugin::VideoGallery < Folder + + def self.type_name + _('Video Gallery') + end + + settings_items :thumbnail_width, :type => :integer, :default => 50 + settings_items :thumbnail_height, :type => :integer, :default => 50 + settings_items :videos_per_row, :type => :integer, :default => 5 + + validate :not_belong_to_blog + + def not_belong_to_blog + errors.add(:parent, "A video gallery should not belong to a blog.") if parent && parent.blog? + end + + acts_as_having_settings :field => :setting + + xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation' + + include WhiteListFilter + filter_iframes :body + def iframe_whitelist + profile && profile.environment && profile.environment.trusted_sites_for_iframe + end + + def self.short_description + _('Video Gallery') + end + + def self.description + _('A gallery of link to videos that are hosted elsewhere.') + end + + include ActionView::Helpers::TagHelper + def to_html(options = {}) + video_gallery = self + proc do + render :partial => 'content_viewer/video_plugin/video_gallery', :locals => {:video_gallery => video_gallery} + end + end + + def video_gallery? + true + end + + def can_display_hits? + false + end + + def accept_comments? + false + end + + def self.icon_name(article = nil) + 'Video gallery' + end + + def news(limit = 30, highlight = false) + profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) + end + +end diff --git a/plugins/video/lib/video_plugin/video_gallery_block.rb b/plugins/video/lib/video_plugin/video_gallery_block.rb new file mode 100644 index 0000000..41e6219 --- /dev/null +++ b/plugins/video/lib/video_plugin/video_gallery_block.rb @@ -0,0 +1,31 @@ +class VideoPlugin::VideoGalleryBlock < Block + + settings_items :video_gallery_id, :type => :integer + attr_accessible :video_gallery_id + + include ActionView::Helpers + include Rails.application.routes.url_helpers + + def self.description + _('Display a Video Gallery') + end + + def help + _('This block presents a video gallery') + end + + def content(args={}) + block = self + if video_gallery_id.present? + video_gallery = VideoPlugin::VideoGallery.find(video_gallery_id) + proc do + render :partial => 'content_viewer/video_plugin/video_gallery', :locals => {:video_gallery => video_gallery} + end + end + end + + def list_my_galleries + Article.owner_video_galleries(owner) + end + +end diff --git a/plugins/video/lib/video_plugin/video_gallery_helper.rb b/plugins/video/lib/video_plugin/video_gallery_helper.rb new file mode 100644 index 0000000..50919a3 --- /dev/null +++ b/plugins/video/lib/video_plugin/video_gallery_helper.rb @@ -0,0 +1,17 @@ +module VideoPlugin::VideoGalleryHelper + + def list_videos(configure={}) + configure[:recursive] ||= false + configure[:list_type] ||= :folder + if !configure[:contents].blank? + configure[:contents] = configure[:contents].paginate( + :per_page => 17, + :page => params[:npage] + ).order("updated_at DESC") + render :file => 'shared/video_list', :locals => configure + else + content_tag('em', _('(empty folder)')) + end + end + +end diff --git a/plugins/video/public/images/video_generic_thumbnail.jpg b/plugins/video/public/images/video_generic_thumbnail.jpg new file mode 100644 index 0000000..3069cbd Binary files /dev/null and b/plugins/video/public/images/video_generic_thumbnail.jpg differ diff --git a/plugins/video/public/style.css b/plugins/video/public/style.css new file mode 100644 index 0000000..bb7361b --- /dev/null +++ b/plugins/video/public/style.css @@ -0,0 +1,66 @@ +.video-gallery-thumbnail { + position: relative; + display: inline-block; + width: 95px; + height: 115px; + margin: 1em; + border: solid #F0F0F0 1px; + vertical-align: top; + text-align: left; + overflow: hidden; + padding-top: 7px; + margin-botton: 10px; + text-overflow: ellipsis; +} + +.video-gallery-top-box{ + height: 73px; +} + +.video-duration{ + position: absolute; + bottom: 0px; + background-color: black; + font-size: 1em; + text-color: white; +} + +.video-title{ + width: 100%; + overflow: hidden; + text-overflow: ellipsis; +} + +.video-author{ + display: none; + overflow: hidden; + text-overflow: ellipsis; +} + +.video-gallery-thumbnail:hover div{ + display: inline-block; +} + +.video-gallery-table-big{ + width: 100%; + overflow: hidden; +} + +.video-gallery-left-column-big{ + width: 350px; + float: left; +} + +.video-gallery-right-column-big{ + margin-left: 370px; +} + +.video-title-big{ + font-size: 2em; +} + +.video-block-center{ + width: 100%; + margin-left: auto; + margin-right: auto; +} \ No newline at end of file diff --git a/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb b/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb index cfd42dc..367defe 100644 --- a/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb +++ b/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb @@ -18,9 +18,9 @@ class EnvironmentDesignControllerTest < ActionController::TestCase @environment.enabled_plugins = ['VideoPlugin'] @environment.save! - VideoBlock.delete_all + VideoPlugin::VideoBlock.delete_all - @block = VideoBlock.new + @block = VideoPlugin::VideoBlock.new @block.box = @environment.boxes.first @block.save! end diff --git a/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb b/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb index b335c61..3cf520d 100644 --- a/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb +++ b/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb @@ -15,11 +15,11 @@ class ProfileDesignControllerTest < ActionController::TestCase @environment.enabled_plugins = ['VideoPlugin'] @environment.save! - VideoBlock.delete_all + VideoPlugin::VideoBlock.delete_all @box1 = Box.create!(:owner => @profile) @profile.boxes = [@box1] - @block = VideoBlock.new + @block = VideoPlugin::VideoBlock.new @block.box = @box1 @block.save! diff --git a/plugins/video/test/unit/video_block_test.rb b/plugins/video/test/unit/video_block_test.rb index 9b67146..2d535bb 100644 --- a/plugins/video/test/unit/video_block_test.rb +++ b/plugins/video/test/unit/video_block_test.rb @@ -4,94 +4,88 @@ class VideoBlockTest < ActiveSupport::TestCase ### Tests for YouTube should "is_youtube return true when the url contains http://youtube.com" do - block = VideoBlock.new + block = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::VideoBlock.new block.url = "youtube.com/" refute block.is_youtube? end should "is_youtube return false when the url contains empty youtube video ID" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "youtube.com/?v=" refute block.is_youtube? end should "is_youtube return false when the url contains an invalid youtube link" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.yt.com/?v=XXXXX" refute block.is_youtube? end should "format embed video for youtube videos" do - block = VideoBlock.new + block = VideoPlugin::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 = VideoPlugin::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 + block = VideoPlugin::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 + block = VideoPlugin::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 + block = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::VideoBlock.new block.url = "youtube.com/" assert_nil block.send('extract_youtube_id') end @@ -99,111 +93,111 @@ class VideoBlockTest < ActiveSupport::TestCase #### Tests for Vimeo Videos should "is_vimeo return true when the url contains http://vimeo.com" do - block = VideoBlock.new + block = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::VideoBlock.new block.url = "vimeo.com/home" refute block.is_vimeo? end should "is_vimeo return false when the url contains empty vimeo video ID" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "vimeo.com/" refute block.is_vimeo? end should "is_vimeo return false when the url contains an invalid vimeo link" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979" refute block.is_vimeo? end should "format embed video for vimeo videos" do - block = VideoBlock.new + block = VideoPlugin::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 = VideoPlugin::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 + block = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::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 = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979.mp4r" refute block.is_video_file? block.url = "http://www.vmsd.com/98979.oggr" @@ -215,7 +209,7 @@ class VideoBlockTest < ActiveSupport::TestCase end should 'display video block partial' do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new self.expects(:render).with(:file => 'video_block', :locals => { :block => block }) diff --git a/plugins/video/test/unit/video_galery_block_test.rb b/plugins/video/test/unit/video_galery_block_test.rb new file mode 100644 index 0000000..1c85249 --- /dev/null +++ b/plugins/video/test/unit/video_galery_block_test.rb @@ -0,0 +1,12 @@ +require File.dirname(__FILE__) + '/../test_helper' +class VideoGaleryBlockTest < ActiveSupport::TestCase + + should "define its description" do + assert_equal VideoPlugin::VideoGalleryBlock.description, _('Display a Video Gallery') + end + + should "define its help description" do + assert_equal VideoPlugin::VideoGalleryBlock.new.help, _('This block presents a video gallery') + end + +end diff --git a/plugins/video/test/unit/video_galery_test.rb b/plugins/video/test/unit/video_galery_test.rb new file mode 100644 index 0000000..7ed929b --- /dev/null +++ b/plugins/video/test/unit/video_galery_test.rb @@ -0,0 +1,16 @@ +require File.dirname(__FILE__) + '/../test_helper' +class VideoGaleryTest < ActiveSupport::TestCase + + should "define its type_name as Video Gallery" do + assert_equal VideoPlugin::VideoGallery.type_name, _('Video Gallery') + end + + should "define its short_description" do + assert_equal VideoPlugin::VideoGallery.short_description, _('Video Gallery') + end + + should "define its description" do + assert_equal VideoPlugin::VideoGallery.description, _('A gallery of link to videos that are hosted elsewhere.') + end + +end diff --git a/plugins/video/test/unit/video_plugin_test.rb b/plugins/video/test/unit/video_plugin_test.rb index b4fa8c9..93dea85 100644 --- a/plugins/video/test/unit/video_plugin_test.rb +++ b/plugins/video/test/unit/video_plugin_test.rb @@ -2,7 +2,7 @@ require_relative '../test_helper' class VideoPluginTest < ActiveSupport::TestCase should "return VideoBlock in extra_blocks class method" do - assert VideoPlugin.extra_blocks.keys.include?(VideoBlock) + assert VideoPlugin.extra_blocks.keys.include?(VideoPlugin::VideoBlock) end end diff --git a/plugins/video/test/unit/video_test.rb b/plugins/video/test/unit/video_test.rb new file mode 100644 index 0000000..57bb067 --- /dev/null +++ b/plugins/video/test/unit/video_test.rb @@ -0,0 +1,90 @@ +require File.dirname(__FILE__) + '/../test_helper' +class VideoTest < ActiveSupport::TestCase + + include AuthenticatedTestHelper + fixtures :users, :environments + + def setup + @video = VideoPlugin::Video.new + end + + should "define its type_name as video" do + assert_equal VideoPlugin::Video.type_name, _('Video') + end + + should "display version" do + assert @video.can_display_versions? + end + + should "define its short_description" do + assert_equal VideoPlugin::Video.short_description, _('Embedded Video') + end + + should "define its description" do + assert_equal VideoPlugin::Video.description, _('Display embedded videos.') + end + + should "define a fitted_width" do + assert_equal @video.fitted_width, 499 + end + + should "eval a fitted_height" do + @video.video_height = 1000 + @video.video_width = 2000 + fitted_height = ((@video.fitted_width * @video.video_height) / @video.video_width).to_i + assert_equal fitted_height, @video.fitted_height + end + + should "define a thumbnail_fitted_width" do + assert_equal @video.thumbnail_fitted_width, 80 + end + + should "eval a thumbnail_fitted_height" do + @video.video_thumbnail_height = 60 + @video.video_thumbnail_width = 30 + thumbnail_fitted_height = ((@video.thumbnail_fitted_width * @video.video_thumbnail_height) / @video.video_thumbnail_width).to_i + assert_equal thumbnail_fitted_height, @video.thumbnail_fitted_height + end + + should "show a no_browser_support_message" do + assert_equal @video.no_browser_support_message, '

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

' + end + + + ### Tests for YouTube + + should "is_youtube return true when the url contains http://youtube.com" do + @video.video_url = "http://youtube.com/?v=XXXXX" + assert @video.is_youtube? + end + + should "is_youtube return true when the url contains https://youtube.com" do + @video.video_url = "https://youtube.com/?v=XXXXX" + assert @video.is_youtube? + end + + should "is_youtube return false when the url contains an invalid youtube link" do + @video.video_url = "http://www.yt.com/?v=XXXXX" + assert !@video.is_youtube? + end + + ### Tests for vimeo + + should "is_vimeo return true when the url contains vimeo.com" do + @video.video_url = "vimeo.com/09898" + assert @video.is_vimeo? + end + + should "is_vimeo return false when the url not contains vimeo video ID" do + @video.video_url = "vimeo.com/home" + assert !@video.is_vimeo? + end + + should "is_vimeo return true for https://vimeo.com/channels/staffpicks/XXXXXXXXXX" do + @video.video_url = "https://vimeo.com/channels/staffpicks/122325664" + assert @video.is_vimeo? + end + + + +end diff --git a/plugins/video/views/box_organizer/_html5_video_block.html.erb b/plugins/video/views/box_organizer/_html5_video_block.html.erb index a120a21..45a32d6 100644 --- a/plugins/video/views/box_organizer/_html5_video_block.html.erb +++ b/plugins/video/views/box_organizer/_html5_video_block.html.erb @@ -1,3 +1,3 @@ -