Commit dfa6a6140f6b2706140c5436866846f41d1fc50d
Exists in
master
and in
22 other branches
Merge commit 'refs/merge-requests/406' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/406
Showing
14 changed files
with
658 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +README - Video (Video Plugin) | |
| 2 | +================================ | |
| 3 | + | |
| 4 | +Video is a plugin to allow the user adds a block where you could choose any url from youtube, vimeo and url's of the following file formats: mp4, ogg, ogv and webm. | |
| 5 | + | |
| 6 | +The Video block will be available for all layout columns of communities, peole, enterprises and environments. | |
| 7 | + | |
| 8 | +INSTALL | |
| 9 | +======= | |
| 10 | + | |
| 11 | +Enable Plugin | |
| 12 | +------------- | |
| 13 | + | |
| 14 | +Also, you need to enable Video Plugin at you Noosfero: | |
| 15 | + | |
| 16 | +cd <your_noosfero_dir> | |
| 17 | +./script/noosfero-plugins enable video | |
| 18 | + | |
| 19 | +Active Plugin | |
| 20 | +------------- | |
| 21 | + | |
| 22 | +As a Noosfero administrator user, go to administrator panel: | |
| 23 | + | |
| 24 | +- Click on "Enable/disable plugins" option | |
| 25 | +- Click on "Display Content Plugin" check-box | |
| 26 | + | |
| 27 | +Running Video tests | |
| 28 | +-------------------- | |
| 29 | + | |
| 30 | +$ rake test:noosfero_plugins:video | |
| 31 | + | |
| 32 | + | |
| 33 | +Get Involved | |
| 34 | +============ | |
| 35 | + | |
| 36 | +If you found any bug and/or want to collaborate, please send an e-mail to leandronunes@gmail.com | |
| 37 | + | |
| 38 | +LICENSE | |
| 39 | +======= | |
| 40 | + | |
| 41 | +Copyright (c) The Author developers. | |
| 42 | + | |
| 43 | +See Noosfero license. | |
| 44 | + | |
| 45 | + | |
| 46 | +AUTHORS | |
| 47 | +======= | |
| 48 | + | |
| 49 | + Leandro Nunes dos Santos (leandronunes at gmail.com) | |
| 50 | + | |
| 51 | +ACKNOWLEDGMENTS | |
| 52 | +=============== | |
| 53 | + | |
| 54 | +The author have been supported by Serpro | ... | ... |
| ... | ... | @@ -0,0 +1,58 @@ |
| 1 | +class VideoBlock < Block | |
| 2 | + | |
| 3 | + settings_items :url, :type => :string, :default => "" | |
| 4 | + settings_items :width, :type => :integer, :default => 400 | |
| 5 | + settings_items :height, :type => :integer, :default => 315 | |
| 6 | + | |
| 7 | + def is_youtube? | |
| 8 | + url.match(/.*(youtube.com.*v=[[:alnum:]]+|youtu.be\/[[:alnum:]]+).*/) ? true : false | |
| 9 | + end | |
| 10 | + | |
| 11 | + def is_vimeo? | |
| 12 | + url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false | |
| 13 | + end | |
| 14 | + | |
| 15 | + def is_video_file? | |
| 16 | + url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false | |
| 17 | + end | |
| 18 | + | |
| 19 | + def format_embed_video_url_for_youtube | |
| 20 | + "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? | |
| 21 | + end | |
| 22 | + | |
| 23 | + def format_embed_video_url_for_vimeo | |
| 24 | + "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? | |
| 25 | + end | |
| 26 | + | |
| 27 | + def self.description | |
| 28 | + _('Add Videos') | |
| 29 | + end | |
| 30 | + | |
| 31 | + def help | |
| 32 | + _('This block presents a video from youtube, vimeo and video formats mp4, ogg, ogv and webm') | |
| 33 | + end | |
| 34 | + | |
| 35 | + def content(args={}) | |
| 36 | + block = self | |
| 37 | + | |
| 38 | + lambda do | |
| 39 | + render :file => 'video_block', :locals => { :block => block } | |
| 40 | + end | |
| 41 | + end | |
| 42 | + | |
| 43 | + private | |
| 44 | + | |
| 45 | + def extract_youtube_id | |
| 46 | + return nil unless is_youtube? | |
| 47 | + youtube_match = url.match('v=([[:alnum:]]*)') | |
| 48 | + youtube_match ||= url.match('youtu.be\/([[:alnum:]]*)') | |
| 49 | + youtube_match[1] unless youtube_match.nil? | |
| 50 | + end | |
| 51 | + | |
| 52 | + def extract_vimeo_id | |
| 53 | + return nil unless is_vimeo? | |
| 54 | + vimeo_match = url.match('([[:digit:]]*)$') | |
| 55 | + vimeo_match[1] unless vimeo_match.nil? | |
| 56 | + end | |
| 57 | + | |
| 58 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +require_dependency File.dirname(__FILE__) + '/video_block' | |
| 2 | + | |
| 3 | +class VideoPlugin < Noosfero::Plugin | |
| 4 | + | |
| 5 | + def self.plugin_name | |
| 6 | + "Video Block Plugin" | |
| 7 | + end | |
| 8 | + | |
| 9 | + def self.plugin_description | |
| 10 | + _("A plugin that adds a block where you could add videos from youtube, vimeo and html5.") | |
| 11 | + end | |
| 12 | + | |
| 13 | + def self.extra_blocks | |
| 14 | + { | |
| 15 | + VideoBlock => {} | |
| 16 | + } | |
| 17 | + end | |
| 18 | + | |
| 19 | +end | ... | ... |
plugins/video/test/functional/video_plugin_environment_design_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,130 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +# Re-raise errors caught by the controller. | |
| 4 | +class EnvironmentDesignController; def rescue_action(e) raise e end; end | |
| 5 | + | |
| 6 | +class EnvironmentDesignControllerTest < ActionController::TestCase | |
| 7 | + | |
| 8 | + def setup | |
| 9 | + @controller = EnvironmentDesignController.new | |
| 10 | + @request = ActionController::TestRequest.new | |
| 11 | + @response = ActionController::TestResponse.new | |
| 12 | + | |
| 13 | + Environment.delete_all | |
| 14 | + User.delete_all | |
| 15 | + @environment = Environment.create!(defaults_for_environment.merge(:is_default => true)) | |
| 16 | + user = create_user('testinguser') | |
| 17 | + login_as(user.person.identifier) | |
| 18 | + @environment.add_admin(user.person) | |
| 19 | + @environment.save! | |
| 20 | + | |
| 21 | + @environment.enabled_plugins = ['VideoPlugin'] | |
| 22 | + @environment.save! | |
| 23 | + | |
| 24 | + VideoBlock.delete_all | |
| 25 | + | |
| 26 | + @block = VideoBlock.new | |
| 27 | + @block.box = @environment.boxes.first | |
| 28 | + @block.save! | |
| 29 | + end | |
| 30 | + | |
| 31 | + attr_accessor :environment, :block | |
| 32 | + | |
| 33 | + should 'display video-block-data class in profile block edition' do | |
| 34 | + block.url='youtube.com/?v=XXXXX' | |
| 35 | + block.save! | |
| 36 | + get :index | |
| 37 | + | |
| 38 | + assert_tag :div, :attributes => {:class => 'video-block-data'} | |
| 39 | + end | |
| 40 | + | |
| 41 | + should "display iframe tag in profile block edition on youtube url's" do | |
| 42 | + block.url='youtube.com/?v=XXXXX' | |
| 43 | + block.save | |
| 44 | + get :index | |
| 45 | + | |
| 46 | + assert_tag :tag => 'iframe' | |
| 47 | + end | |
| 48 | + | |
| 49 | + should "the width in iframe tag be defined on youtube url's" do | |
| 50 | + block.url='youtube.com/?v=XXXXX' | |
| 51 | + block.save | |
| 52 | + get :index | |
| 53 | + | |
| 54 | + assert_tag :tag => 'iframe', :attributes => {:width => '400px'} | |
| 55 | + end | |
| 56 | + | |
| 57 | + should "display iframe tag in profile block edition on vimeo url's" do | |
| 58 | + block.url='http://vimeo.com/98979' | |
| 59 | + block.save | |
| 60 | + get :index | |
| 61 | + | |
| 62 | + assert_tag :tag => 'iframe' | |
| 63 | + end | |
| 64 | + | |
| 65 | + should "the width in iframe tag be defined on vimeo url's" do | |
| 66 | + block.url='http://vimeo.com/98979' | |
| 67 | + block.save | |
| 68 | + get :index | |
| 69 | + | |
| 70 | + assert_tag :tag => 'iframe', :attributes => {:width => '400px'} | |
| 71 | + end | |
| 72 | + | |
| 73 | + should "display video tag in profile block edition for any video url" do | |
| 74 | + block.url='http://www.vmsd.com/98979.mp4' | |
| 75 | + block.save | |
| 76 | + get :index | |
| 77 | + | |
| 78 | + assert_tag :tag => 'video' | |
| 79 | + end | |
| 80 | + | |
| 81 | + should "the width in video tag be defined for any video url" do | |
| 82 | + block.url='http://www.vmsd.com/98979.mp4' | |
| 83 | + block.save | |
| 84 | + get :index | |
| 85 | + | |
| 86 | + assert_tag :tag => 'video', :attributes => {:width => '400px'} | |
| 87 | + end | |
| 88 | + | |
| 89 | + should 'the heigth in iframe tag be defined' do | |
| 90 | + block.url='youtube.com/?v=XXXXX' | |
| 91 | + block.save | |
| 92 | + get :index | |
| 93 | + | |
| 94 | + assert_tag :tag => 'iframe', :attributes => {:height => '315px'} | |
| 95 | + end | |
| 96 | + | |
| 97 | + should 'display youtube videos' do | |
| 98 | + block.url='youtube.com/?v=XXXXX' | |
| 99 | + block.save | |
| 100 | + get :index | |
| 101 | + | |
| 102 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'div', :attributes => {:class => 'youtube'} } | |
| 103 | + end | |
| 104 | + | |
| 105 | + should 'display vimeo videos' do | |
| 106 | + block.url='http://vimeo.com/98979' | |
| 107 | + block.save | |
| 108 | + get :index | |
| 109 | + | |
| 110 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'div', :attributes => {:class => 'vimeo'} } | |
| 111 | + end | |
| 112 | + | |
| 113 | + should 'display other videos' do | |
| 114 | + block.url='http://www.vmsd.com/98979.mp4' | |
| 115 | + block.save | |
| 116 | + get :index | |
| 117 | + | |
| 118 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'div', :attributes => {:class => 'video'} } | |
| 119 | + end | |
| 120 | + | |
| 121 | + should 'display a messagem to register a new url' do | |
| 122 | + block.url='http://www.vmsd.com/test.pdf' | |
| 123 | + block.save | |
| 124 | + get :index | |
| 125 | + | |
| 126 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'span', :attributes => {:class => 'alert-block'} } | |
| 127 | + end | |
| 128 | + | |
| 129 | + | |
| 130 | +end | ... | ... |
plugins/video/test/functional/video_plugin_profile_design_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,132 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +# Re-raise errors caught by the controller. | |
| 4 | +class ProfileDesignController; def rescue_action(e) raise e end; end | |
| 5 | + | |
| 6 | +class ProfileDesignControllerTest < ActionController::TestCase | |
| 7 | + | |
| 8 | + def setup | |
| 9 | + @controller = ProfileDesignController.new | |
| 10 | + @request = ActionController::TestRequest.new | |
| 11 | + @response = ActionController::TestResponse.new | |
| 12 | + | |
| 13 | + user = create_user('testinguser') | |
| 14 | + login_as(user.login) | |
| 15 | + @profile = user.person | |
| 16 | + @environment = @profile.environment | |
| 17 | + | |
| 18 | + @environment.enabled_plugins = ['VideoPlugin'] | |
| 19 | + @environment.save! | |
| 20 | + | |
| 21 | + VideoBlock.delete_all | |
| 22 | + @box1 = Box.create!(:owner => @profile) | |
| 23 | + @profile.boxes = [@box1] | |
| 24 | + | |
| 25 | + @block = VideoBlock.new | |
| 26 | + @block.box = @box1 | |
| 27 | + @block.save! | |
| 28 | + | |
| 29 | + @profile.blocks<<@block | |
| 30 | + @profile.save! | |
| 31 | + end | |
| 32 | + | |
| 33 | + attr_accessor :profile, :block | |
| 34 | + | |
| 35 | + should 'display video-block-data class in profile block edition' do | |
| 36 | + block.url='youtube.com/?v=XXXXX' | |
| 37 | + block.save | |
| 38 | + get :index, :profile => profile.identifier | |
| 39 | + | |
| 40 | + assert_tag :div, :attributes => {:class => 'video-block-data'} | |
| 41 | + end | |
| 42 | + | |
| 43 | + should "display iframe tag in profile block edition on youtube url's" do | |
| 44 | + block.url='youtube.com/?v=XXXXX' | |
| 45 | + block.save | |
| 46 | + get :index, :profile => profile.identifier | |
| 47 | + | |
| 48 | + assert_tag :tag => 'iframe' | |
| 49 | + end | |
| 50 | + | |
| 51 | + should "the width in iframe tag be defined on youtube url's" do | |
| 52 | + block.url='youtube.com/?v=XXXXX' | |
| 53 | + block.save | |
| 54 | + get :index, :profile => profile.identifier | |
| 55 | + | |
| 56 | + assert_tag :tag => 'iframe', :attributes => {:width => '400px'} | |
| 57 | + end | |
| 58 | + | |
| 59 | + should "display iframe tag in profile block edition on vimeo url's" do | |
| 60 | + block.url='http://vimeo.com/98979' | |
| 61 | + block.save | |
| 62 | + get :index, :profile => profile.identifier | |
| 63 | + | |
| 64 | + assert_tag :tag => 'iframe' | |
| 65 | + end | |
| 66 | + | |
| 67 | + should "the width in iframe tag be defined on vimeo url's" do | |
| 68 | + block.url='http://vimeo.com/98979' | |
| 69 | + block.save | |
| 70 | + get :index, :profile => profile.identifier | |
| 71 | + | |
| 72 | + assert_tag :tag => 'iframe', :attributes => {:width => '400px'} | |
| 73 | + end | |
| 74 | + | |
| 75 | + should "display video tag in profile block edition for any video url" do | |
| 76 | + block.url='http://www.vmsd.com/98979.mp4' | |
| 77 | + block.save | |
| 78 | + get :index, :profile => profile.identifier | |
| 79 | + | |
| 80 | + assert_tag :tag => 'video' | |
| 81 | + end | |
| 82 | + | |
| 83 | + should "the width in video tag be defined for any video url" do | |
| 84 | + block.url='http://www.vmsd.com/98979.mp4' | |
| 85 | + block.save | |
| 86 | + get :index, :profile => profile.identifier | |
| 87 | + | |
| 88 | + assert_tag :tag => 'video', :attributes => {:width => '400px'} | |
| 89 | + end | |
| 90 | + | |
| 91 | + should 'the heigth in iframe tag be defined' do | |
| 92 | + block.url='youtube.com/?v=XXXXX' | |
| 93 | + block.save | |
| 94 | + get :index, :profile => profile.identifier | |
| 95 | + | |
| 96 | + assert_tag :tag => 'iframe', :attributes => {:height => '315px'} | |
| 97 | + end | |
| 98 | + | |
| 99 | + should 'display youtube videos' do | |
| 100 | + block.url='youtube.com/?v=XXXXX' | |
| 101 | + block.save | |
| 102 | + get :index, :profile => profile.identifier | |
| 103 | + | |
| 104 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'div', :attributes => {:class => 'youtube'} } | |
| 105 | + end | |
| 106 | + | |
| 107 | + should 'display vimeo videos' do | |
| 108 | + block.url='http://vimeo.com/98979' | |
| 109 | + block.save | |
| 110 | + get :index, :profile => profile.identifier | |
| 111 | + | |
| 112 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'div', :attributes => {:class => 'vimeo'} } | |
| 113 | + end | |
| 114 | + | |
| 115 | + should 'display other videos' do | |
| 116 | + block.url='http://www.vmsd.com/98979.mp4' | |
| 117 | + block.save | |
| 118 | + get :index, :profile => profile.identifier | |
| 119 | + | |
| 120 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'div', :attributes => {:class => 'video'} } | |
| 121 | + end | |
| 122 | + | |
| 123 | + should 'display a messagem to register a new url' do | |
| 124 | + block.url='http://www.vmsd.com/test.pdf' | |
| 125 | + block.save | |
| 126 | + get :index, :profile => profile.identifier | |
| 127 | + | |
| 128 | + assert_tag :tag => 'div', :attributes => {:class => 'video-block-data'}, :descendant => { :tag => 'span', :attributes => {:class => 'alert-block'} } | |
| 129 | + end | |
| 130 | + | |
| 131 | + | |
| 132 | +end | ... | ... |
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | ... | ... |
| ... | ... | @@ -0,0 +1,218 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | +class VideoBlockTest < ActiveSupport::TestCase | |
| 3 | + | |
| 4 | + ### Tests for YouTube | |
| 5 | + | |
| 6 | + should "is_youtube return true when the url contains http://youtube.com" do | |
| 7 | + block = VideoBlock.new | |
| 8 | + block.url = "http://youtube.com/?v=XXXXX" | |
| 9 | + assert block.is_youtube? | |
| 10 | + end | |
| 11 | + | |
| 12 | + should "is_youtube return true when the url contains https://youtube.com" do | |
| 13 | + block = VideoBlock.new | |
| 14 | + block.url = "https://youtube.com/?v=XXXXX" | |
| 15 | + assert block.is_youtube? | |
| 16 | + end | |
| 17 | + | |
| 18 | + should "is_youtube return true when the url contains https://www.youtube.com" do | |
| 19 | + block = VideoBlock.new | |
| 20 | + block.url = "https://www.youtube.com/?v=XXXXX" | |
| 21 | + assert block.is_youtube? | |
| 22 | + end | |
| 23 | + | |
| 24 | + should "is_youtube return true when the url contains www.youtube.com" do | |
| 25 | + block = VideoBlock.new | |
| 26 | + block.url = "www.youtube.com/?v=XXXXX" | |
| 27 | + assert block.is_youtube? | |
| 28 | + end | |
| 29 | + | |
| 30 | + should "is_youtube return true when the url contains youtube.com" do | |
| 31 | + block = VideoBlock.new | |
| 32 | + block.url = "youtube.com/?v=XXXXX" | |
| 33 | + assert block.is_youtube? | |
| 34 | + end | |
| 35 | + | |
| 36 | + should "is_youtube return false when the url not contains youtube video ID" do | |
| 37 | + block = VideoBlock.new | |
| 38 | + block.url = "youtube.com/" | |
| 39 | + assert !block.is_youtube? | |
| 40 | + end | |
| 41 | + | |
| 42 | + should "is_youtube return false when the url contains empty youtube video ID" do | |
| 43 | + block = VideoBlock.new | |
| 44 | + block.url = "youtube.com/?v=" | |
| 45 | + assert !block.is_youtube? | |
| 46 | + end | |
| 47 | + | |
| 48 | + should "is_youtube return false when the url contains an invalid youtube link" do | |
| 49 | + block = VideoBlock.new | |
| 50 | + block.url = "http://www.yt.com/?v=XXXXX" | |
| 51 | + assert !block.is_youtube? | |
| 52 | + end | |
| 53 | + | |
| 54 | + should "format embed video for youtube videos" do | |
| 55 | + block = VideoBlock.new | |
| 56 | + block.url = "youtube.com/?v=XXXXX" | |
| 57 | + assert_match /\/\/www.youtube-nocookie.com\/embed/, block.format_embed_video_url_for_youtube | |
| 58 | + end | |
| 59 | + | |
| 60 | + should "format embed video return nil if is not a youtube url" do | |
| 61 | + block = VideoBlock.new | |
| 62 | + block.url = "http://www.yt.com/?v=XXXXX" | |
| 63 | + assert_nil block.format_embed_video_url_for_youtube | |
| 64 | + end | |
| 65 | + | |
| 66 | + should "extract youtube id from youtube video url's if it's a valid youtube full url" do | |
| 67 | + block = VideoBlock.new | |
| 68 | + id = 'oi43jre2d2' | |
| 69 | + block.url = "youtube.com/?v=#{id}" | |
| 70 | + assert_equal id, block.send('extract_youtube_id') | |
| 71 | + end | |
| 72 | + | |
| 73 | + should "extract youtube id from youtube video url's if it's a valid youtube short url" do | |
| 74 | + block = VideoBlock.new | |
| 75 | + id = 'oi43jre2d2' | |
| 76 | + block.url = "youtu.be/#{id}" | |
| 77 | + assert_equal id, block.send('extract_youtube_id') | |
| 78 | + end | |
| 79 | + | |
| 80 | + should "extract_youtube_id return nil if the url it's not a valid youtube url" do | |
| 81 | + block = VideoBlock.new | |
| 82 | + block.url = "http://www.yt.com/?v=XXXXX" | |
| 83 | + assert_nil block.send('extract_youtube_id') | |
| 84 | + end | |
| 85 | + | |
| 86 | + should "extract_youtube_id return nil if youtue url there is no id" do | |
| 87 | + block = VideoBlock.new | |
| 88 | + block.url = "youtube.com/" | |
| 89 | + assert_nil block.send('extract_youtube_id') | |
| 90 | + end | |
| 91 | + | |
| 92 | + #### Tests for Vimeo Videos | |
| 93 | + | |
| 94 | + should "is_vimeo return true when the url contains http://vimeo.com" do | |
| 95 | + block = VideoBlock.new | |
| 96 | + block.url = "http://vimeo.com/98979" | |
| 97 | + assert block.is_vimeo? | |
| 98 | + end | |
| 99 | + | |
| 100 | + should "is_vimeo return true when the url contains https://vimeo.com" do | |
| 101 | + block = VideoBlock.new | |
| 102 | + block.url = "https://vimeo.com/989798" | |
| 103 | + assert block.is_vimeo? | |
| 104 | + end | |
| 105 | + | |
| 106 | + should "is_vimeo return true when the url contains https://www.vimeo.com" do | |
| 107 | + block = VideoBlock.new | |
| 108 | + block.url = "https://www.vimeo.com/98987" | |
| 109 | + assert block.is_vimeo? | |
| 110 | + end | |
| 111 | + | |
| 112 | + should "is_vimeo return true when the url contains www.vimeo.com" do | |
| 113 | + block = VideoBlock.new | |
| 114 | + block.url = "www.vimeo.com/989798" | |
| 115 | + assert block.is_vimeo? | |
| 116 | + end | |
| 117 | + | |
| 118 | + should "is_vimeo return true when the url contains vimeo.com" do | |
| 119 | + block = VideoBlock.new | |
| 120 | + block.url = "vimeo.com/09898" | |
| 121 | + assert block.is_vimeo? | |
| 122 | + end | |
| 123 | + | |
| 124 | + should "is_vimeo return false when the url not contains vimeo video ID" do | |
| 125 | + block = VideoBlock.new | |
| 126 | + block.url = "vimeo.com/home" | |
| 127 | + assert !block.is_vimeo? | |
| 128 | + end | |
| 129 | + | |
| 130 | + should "is_vimeo return false when the url contains empty vimeo video ID" do | |
| 131 | + block = VideoBlock.new | |
| 132 | + block.url = "vimeo.com/" | |
| 133 | + assert !block.is_vimeo? | |
| 134 | + end | |
| 135 | + | |
| 136 | + should "is_vimeo return false when the url contains an invalid vimeo link" do | |
| 137 | + block = VideoBlock.new | |
| 138 | + block.url = "http://www.vmsd.com/98979" | |
| 139 | + assert !block.is_vimeo? | |
| 140 | + end | |
| 141 | + | |
| 142 | + should "format embed video for vimeo videos" do | |
| 143 | + block = VideoBlock.new | |
| 144 | + block.url = "vimeo.com/09898" | |
| 145 | + assert_match /\/\/player.vimeo.com\/video\/[[:digit:]]+/, block.format_embed_video_url_for_vimeo | |
| 146 | + end | |
| 147 | + | |
| 148 | + should "format embed video return nil if is not a vimeo url" do | |
| 149 | + block = VideoBlock.new | |
| 150 | + block.url = "http://www.yt.com/?v=XXXXX" | |
| 151 | + assert_nil block.format_embed_video_url_for_vimeo | |
| 152 | + end | |
| 153 | + | |
| 154 | + should "extract vimeo id from vimeo video url's if it's a valid vimeo url" do | |
| 155 | + block = VideoBlock.new | |
| 156 | + id = '23048239432' | |
| 157 | + block.url = "vimeo.com/#{id}" | |
| 158 | + assert_equal id, block.send('extract_vimeo_id') | |
| 159 | + end | |
| 160 | + | |
| 161 | + should "extract_vimeo_id return nil if the url it's not a valid vimeo url" do | |
| 162 | + block = VideoBlock.new | |
| 163 | + block.url = "http://www.yt.com/XXXXX" | |
| 164 | + assert_nil block.send('extract_vimeo_id') | |
| 165 | + end | |
| 166 | + | |
| 167 | + should "extract_vimeo_id return nil if vimeo url there is no id" do | |
| 168 | + block = VideoBlock.new | |
| 169 | + block.url = "vimeo.com/" | |
| 170 | + assert_nil block.send('extract_youtube_id') | |
| 171 | + end | |
| 172 | + | |
| 173 | + # Other video formats | |
| 174 | + should "is_video return true if url ends with mp4" do | |
| 175 | + block = VideoBlock.new | |
| 176 | + block.url = "http://www.vmsd.com/98979.mp4" | |
| 177 | + assert block.is_video_file? | |
| 178 | + end | |
| 179 | + | |
| 180 | + should "is_video return true if url ends with ogg" do | |
| 181 | + block = VideoBlock.new | |
| 182 | + block.url = "http://www.vmsd.com/98979.ogg" | |
| 183 | + assert block.is_video_file? | |
| 184 | + end | |
| 185 | + | |
| 186 | + should "is_video return true if url ends with ogv" do | |
| 187 | + block = VideoBlock.new | |
| 188 | + block.url = "http://www.vmsd.com/98979.ogv" | |
| 189 | + assert block.is_video_file? | |
| 190 | + end | |
| 191 | + | |
| 192 | + should "is_video return true if url ends with webm" do | |
| 193 | + block = VideoBlock.new | |
| 194 | + block.url = "http://www.vmsd.com/98979.webm" | |
| 195 | + assert block.is_video_file? | |
| 196 | + end | |
| 197 | + | |
| 198 | + should "is_video return false if url ends without mp4, ogg, ogv, webm" do | |
| 199 | + block = VideoBlock.new | |
| 200 | + block.url = "http://www.vmsd.com/98979.mp4r" | |
| 201 | + assert !block.is_video_file? | |
| 202 | + block.url = "http://www.vmsd.com/98979.oggr" | |
| 203 | + assert !block.is_video_file? | |
| 204 | + block.url = "http://www.vmsd.com/98979.ogvr" | |
| 205 | + assert !block.is_video_file? | |
| 206 | + block.url = "http://www.vmsd.com/98979.webmr" | |
| 207 | + assert !block.is_video_file? | |
| 208 | + end | |
| 209 | + | |
| 210 | + should 'display video block partial' do | |
| 211 | + block = VideoBlock.new | |
| 212 | + self.expects(:render).with(:file => 'video_block', :locals => { | |
| 213 | + :block => block | |
| 214 | + }) | |
| 215 | + instance_eval(& block.content) | |
| 216 | + end | |
| 217 | + | |
| 218 | +end | ... | ... |
plugins/video/views/box_organizer/_html5_video_block.rhtml
0 → 100644
plugins/video/views/box_organizer/_iframe_video_block.rhtml
0 → 100644
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +<iframe width=<%="#{width}px"%> height=<%="#{height}px"%> src=<%= "#{url}" %> frameborder="0" allowfullscreen></iframe> | ... | ... |
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +<label for="url" class="formlabel"> Video URL: </label> | |
| 2 | + | |
| 3 | +<div class="formfield type-text"> | |
| 4 | + <%= text_field_tag 'block[url]', @block.url, :class => 'video-url', :maxlength => 255 %> | |
| 5 | +</div> | |
| 6 | +<div class="formfield type-text"> | |
| 7 | + <label for="width" class="formlabel"> Width: </label> | |
| 8 | + <%= text_field_tag 'block[width]', @block.width, :size => 7, :class => 'video-width', :maxlength => 5 %> | |
| 9 | + <label for="height" class="formlabel"> Height: </label> | |
| 10 | + <%= text_field_tag 'block[height]', @block.height, :size => 7, :class => 'video-height', :maxlength => 5 %> | |
| 11 | +</div> | ... | ... |
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +<h3 class="block-title"> | |
| 2 | + <span><%=block.title%></span> | |
| 3 | +</h3> | |
| 4 | +<div class="video-block-data"> | |
| 5 | + <% if block.is_youtube? %> | |
| 6 | + <div class='youtube'> | |
| 7 | + <%= render :partial => 'box_organizer/iframe_video_block', :locals => { :url => block.format_embed_video_url_for_youtube, :width => block.width, :height => block.height }%> | |
| 8 | + </div> | |
| 9 | + <% elsif block.is_vimeo? %> | |
| 10 | + <div class='vimeo'> | |
| 11 | + <%= render :partial => 'box_organizer/iframe_video_block', :locals => { :url => block.format_embed_video_url_for_vimeo, :width => block.width, :height => block.height }%> | |
| 12 | + </div> | |
| 13 | + <% elsif block.is_video_file? %> | |
| 14 | + <div class='video'> | |
| 15 | + <%= render :partial => 'box_organizer/html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> | |
| 16 | + </div> | |
| 17 | + <% else %> | |
| 18 | + <span class='alert-block'><%= _("Register a new url (Vimeo, Youtube, Other)") %> | |
| 19 | + <% end %> | |
| 20 | + | |
| 21 | +</div> | ... | ... |