Commit 4ed9e248a3ad96c75d47bf4f6f62239f574c0c17
1 parent
6e6dd66a
Exists in
master
and in
28 other branches
adding functional tests
Showing
11 changed files
with
245 additions
and
399 deletions
Show diff stats
plugins/video/controllers/video_plugin_admin_controller.rb
plugins/video/controllers/video_plugin_module.rb
plugins/video/controllers/video_plugin_myprofile_controller.rb
plugins/video/lib/video_block.rb
| ... | ... | @@ -5,38 +5,33 @@ class VideoBlock < Block |
| 5 | 5 | settings_items :height, :type => :integer, :default => 315 |
| 6 | 6 | |
| 7 | 7 | def is_youtube? |
| 8 | - url.match(/.*(youtube.com.*v=[[:alnum:]]*|youtu.be\/[[:alnum:]]*).*/) ? true : false | |
| 8 | + url.match(/.*(youtube.com.*v=[[:alnum:]]+|youtu.be\/[[:alnum:]]+).*/) ? true : false | |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def is_vimeo? |
| 12 | - url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]*/) ? true : false | |
| 12 | + url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def is_video_file? |
| 16 | 16 | url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | - #FIXME Make this test | |
| 20 | 19 | def format_embed_video_url_for_youtube |
| 21 | - "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" | |
| 20 | + "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? | |
| 22 | 21 | end |
| 23 | 22 | |
| 24 | - #FIXME Make this test | |
| 25 | 23 | def format_embed_video_url_for_vimeo |
| 26 | - "//player.vimeo.com/video/#{extract_vimeo_id}" | |
| 24 | + "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? | |
| 27 | 25 | end |
| 28 | 26 | |
| 29 | - #FIXME Make this test | |
| 30 | 27 | def self.description |
| 31 | - _('Add Video') | |
| 28 | + _('Add Videos') | |
| 32 | 29 | end |
| 33 | 30 | |
| 34 | - #FIXME Make this test | |
| 35 | 31 | def help |
| 36 | - _('This block presents a video block.') | |
| 32 | + _('This block presents a video from youtube, vimeo and video formats mp4, ogg, ogv and webm') | |
| 37 | 33 | end |
| 38 | 34 | |
| 39 | - #FIXME Make this test | |
| 40 | 35 | def content(args={}) |
| 41 | 36 | block = self |
| 42 | 37 | |
| ... | ... | @@ -45,14 +40,8 @@ class VideoBlock < Block |
| 45 | 40 | end |
| 46 | 41 | end |
| 47 | 42 | |
| 48 | - #FIXME Make this test | |
| 49 | - def cacheable? | |
| 50 | - false | |
| 51 | - end | |
| 52 | - | |
| 53 | 43 | private |
| 54 | 44 | |
| 55 | - #FIXME Make this test | |
| 56 | 45 | def extract_youtube_id |
| 57 | 46 | return nil unless is_youtube? |
| 58 | 47 | youtube_match = url.match('v=([[:alnum:]]*)') |
| ... | ... | @@ -65,4 +54,5 @@ class VideoBlock < Block |
| 65 | 54 | vimeo_match = url.match('([[:digit:]]*)$') |
| 66 | 55 | vimeo_match[1] unless vimeo_match.nil? |
| 67 | 56 | end |
| 57 | + | |
| 68 | 58 | end | ... | ... |
plugins/video/test/functional/display_content_plugin_admin_controller_test.rb
| ... | ... | @@ -1,179 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | -require File.dirname(__FILE__) + '/../../controllers/display_content_plugin_admin_controller' | |
| 3 | - | |
| 4 | - | |
| 5 | -# Re-raise errors caught by the controller. | |
| 6 | -class DisplayContentPluginAdminControllerController; def rescue_action(e) raise e end; end | |
| 7 | - | |
| 8 | -class DisplayContentPluginAdminControllerTest < ActionController::TestCase | |
| 9 | - | |
| 10 | - def setup | |
| 11 | - @controller = DisplayContentPluginAdminController.new | |
| 12 | - @request = ActionController::TestRequest.new | |
| 13 | - @response = ActionController::TestResponse.new | |
| 14 | - | |
| 15 | - @environment = Environment.default | |
| 16 | - user_login = create_admin_user(@environment) | |
| 17 | - login_as(user_login) | |
| 18 | - @admin = User[user_login].person | |
| 19 | - @environment.enabled_plugins = ['DisplayContentPlugin'] | |
| 20 | - @environment.portal_community = fast_create(Community, :name => 'my test profile', :identifier => 'mytestcommunity') | |
| 21 | - @environment.save! | |
| 22 | - | |
| 23 | - box = Box.new(:owner => @environment, :position => 1) | |
| 24 | - box.save | |
| 25 | - | |
| 26 | - DisplayContentBlock.delete_all | |
| 27 | - @block = DisplayContentBlock.new | |
| 28 | - @block.box = environment.boxes.first | |
| 29 | - @block.save! | |
| 30 | - end | |
| 31 | - | |
| 32 | - attr_accessor :environment, :block | |
| 33 | - | |
| 34 | - should 'access index action' do | |
| 35 | - get :index, :block_id => block.id | |
| 36 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 37 | - assert_response :success | |
| 38 | - end | |
| 39 | - | |
| 40 | - should 'index action returns a empty json if there is no content' do | |
| 41 | - Article.delete_all | |
| 42 | - get :index, :block_id => block.id | |
| 43 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 44 | - assert_equal [], json_response | |
| 45 | - end | |
| 46 | - | |
| 47 | - should 'index action returns an json with node content' do | |
| 48 | - Article.delete_all | |
| 49 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) | |
| 50 | - | |
| 51 | - get :index, :block_id => block.id | |
| 52 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 53 | - expected_json = {'data' => article.title} | |
| 54 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 55 | - | |
| 56 | - assert_equal [expected_json], json_response | |
| 57 | - end | |
| 58 | - | |
| 59 | - should 'index action returns an json with node checked if the node is in the nodes list' do | |
| 60 | - Article.delete_all | |
| 61 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) | |
| 62 | - block.nodes= [article.id] | |
| 63 | - block.save! | |
| 64 | - | |
| 65 | - get :index, :block_id => block.id | |
| 66 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 67 | - expected_json = {'data' => article.title} | |
| 68 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 69 | - expected_json['attr'].merge!({'class' => 'jstree-checked'}) | |
| 70 | - | |
| 71 | - assert_equal [expected_json], json_response | |
| 72 | - end | |
| 73 | - | |
| 74 | - should 'index action returns an json with node undetermined if the node is in the parent nodes list' do | |
| 75 | - Article.delete_all | |
| 76 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id) | |
| 77 | - block.parent_nodes= [article.id] | |
| 78 | - block.save! | |
| 79 | - | |
| 80 | - get :index, :block_id => block.id | |
| 81 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 82 | - expected_json = {'data' => article.title} | |
| 83 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 84 | - expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 85 | - expected_json['children'] = [] | |
| 86 | - | |
| 87 | - assert_equal [expected_json], json_response | |
| 88 | - end | |
| 89 | - | |
| 90 | - should 'index action returns an json with node closed if the node has article with children' do | |
| 91 | - Article.delete_all | |
| 92 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) | |
| 93 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 94 | - | |
| 95 | - get :index, :block_id => block.id | |
| 96 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 97 | - expected_json = {'data' => f.title} | |
| 98 | - expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 99 | - expected_json['state'] = 'closed' | |
| 100 | - | |
| 101 | - assert_equal [expected_json], json_response | |
| 102 | - end | |
| 103 | - | |
| 104 | - should 'index action returns an json with all the children nodes if some parent is in the parents list' do | |
| 105 | - Article.delete_all | |
| 106 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) | |
| 107 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 108 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 109 | - block.parent_nodes = [f.id] | |
| 110 | - block.save! | |
| 111 | - | |
| 112 | - get :index, :block_id => block.id | |
| 113 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 114 | - expected_json = {'data' => f.title} | |
| 115 | - expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 116 | - children = [ | |
| 117 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 118 | - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | |
| 119 | - ] | |
| 120 | - expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 121 | - expected_json['children'] = children | |
| 122 | - expected_json['state'] = 'closed' | |
| 123 | - | |
| 124 | - assert_equal [expected_json], json_response | |
| 125 | - end | |
| 126 | - | |
| 127 | - should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do | |
| 128 | - Article.delete_all | |
| 129 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) | |
| 130 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 131 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 132 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => environment.portal_community.id) | |
| 133 | - block.parent_nodes = [f.id] | |
| 134 | - block.save! | |
| 135 | - | |
| 136 | - get :index, :block_id => block.id | |
| 137 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 138 | - expected_json = [] | |
| 139 | - value = {'data' => f.title} | |
| 140 | - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 141 | - children = [ | |
| 142 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 143 | - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | |
| 144 | - ] | |
| 145 | - value['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 146 | - value['children'] = children | |
| 147 | - value['state'] = 'closed' | |
| 148 | - expected_json.push(value) | |
| 149 | - | |
| 150 | - value = {'data' => a3.title} | |
| 151 | - value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | |
| 152 | - expected_json.push(value) | |
| 153 | - | |
| 154 | - assert_equal expected_json, json_response | |
| 155 | - end | |
| 156 | - | |
| 157 | - should 'index action returns an json without children nodes if the parent is not in the parents list' do | |
| 158 | - Article.delete_all | |
| 159 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => environment.portal_community.id) | |
| 160 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 161 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => environment.portal_community.id, :parent_id => f.id) | |
| 162 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => environment.portal_community.id) | |
| 163 | - | |
| 164 | - get :index, :block_id => block.id | |
| 165 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 166 | - expected_json = [] | |
| 167 | - value = {'data' => f.title} | |
| 168 | - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 169 | - value['state'] = 'closed' | |
| 170 | - expected_json.push(value) | |
| 171 | - | |
| 172 | - value = {'data' => a3.title} | |
| 173 | - value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | |
| 174 | - expected_json.push(value) | |
| 175 | - | |
| 176 | - assert_equal expected_json, json_response | |
| 177 | - end | |
| 178 | - | |
| 179 | -end |
plugins/video/test/functional/display_content_plugin_myprofile_controller_test.rb
| ... | ... | @@ -1,180 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | -require File.dirname(__FILE__) + '/../../controllers/display_content_plugin_myprofile_controller' | |
| 3 | - | |
| 4 | - | |
| 5 | -# Re-raise errors caught by the controller. | |
| 6 | -class DisplayContentPluginMyprofileControllerController; def rescue_action(e) raise e end; end | |
| 7 | - | |
| 8 | -class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | |
| 9 | - | |
| 10 | - def setup | |
| 11 | - @controller = DisplayContentPluginMyprofileController.new | |
| 12 | - @request = ActionController::TestRequest.new | |
| 13 | - @response = ActionController::TestResponse.new | |
| 14 | - | |
| 15 | - user = create_user('testinguser') | |
| 16 | - login_as(user.login) | |
| 17 | - @profile = user.person | |
| 18 | - @environment = @profile.environment | |
| 19 | - | |
| 20 | - @environment.enabled_plugins = ['DisplaContentPlugin'] | |
| 21 | - @environment.save! | |
| 22 | - | |
| 23 | -# box = Box.new(:owner => @environment, :position => 1) | |
| 24 | -# box.save | |
| 25 | - | |
| 26 | - DisplayContentBlock.delete_all | |
| 27 | - @block = DisplayContentBlock.new | |
| 28 | - @block.box = @profile.boxes.first | |
| 29 | - @block.save! | |
| 30 | - end | |
| 31 | - | |
| 32 | - attr_accessor :profile, :block | |
| 33 | - | |
| 34 | - should 'access index action' do | |
| 35 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 36 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 37 | - assert_response :success | |
| 38 | - end | |
| 39 | - | |
| 40 | - should 'index action returns a empty json if there is no content' do | |
| 41 | - Article.delete_all | |
| 42 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 43 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 44 | - assert_equal [], json_response | |
| 45 | - end | |
| 46 | - | |
| 47 | - should 'index action returns an json with node content' do | |
| 48 | - Article.delete_all | |
| 49 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 50 | - | |
| 51 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 52 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 53 | - expected_json = {'data' => article.title} | |
| 54 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 55 | - | |
| 56 | - assert_equal [expected_json], json_response | |
| 57 | - end | |
| 58 | - | |
| 59 | - should 'index action returns an json with node checked if the node is in the nodes list' do | |
| 60 | - Article.delete_all | |
| 61 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 62 | - block.nodes= [article.id] | |
| 63 | - block.save! | |
| 64 | - | |
| 65 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 66 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 67 | - expected_json = {'data' => article.title} | |
| 68 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 69 | - expected_json['attr'].merge!({'class' => 'jstree-checked'}) | |
| 70 | - | |
| 71 | - assert_equal [expected_json], json_response | |
| 72 | - end | |
| 73 | - | |
| 74 | - should 'index action returns an json with node undetermined if the node is in the parent nodes list' do | |
| 75 | - Article.delete_all | |
| 76 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
| 77 | - block.parent_nodes= [article.id] | |
| 78 | - block.save! | |
| 79 | - | |
| 80 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 81 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 82 | - expected_json = {'data' => article.title} | |
| 83 | - expected_json['attr'] = { 'node_id' => article.id, 'parent_id' => article.parent_id} | |
| 84 | - expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 85 | - expected_json['children'] = [] | |
| 86 | - | |
| 87 | - assert_equal [expected_json], json_response | |
| 88 | - end | |
| 89 | - | |
| 90 | - should 'index action returns an json with node closed if the node has article with children' do | |
| 91 | - Article.delete_all | |
| 92 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 93 | - article = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 94 | - block.save! | |
| 95 | - | |
| 96 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 97 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 98 | - expected_json = {'data' => f.title} | |
| 99 | - expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 100 | - expected_json['state'] = 'closed' | |
| 101 | - | |
| 102 | - assert_equal [expected_json], json_response | |
| 103 | - end | |
| 104 | - | |
| 105 | - should 'index action returns an json with all the children nodes if some parent is in the parents list' do | |
| 106 | - Article.delete_all | |
| 107 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 108 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 109 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | |
| 110 | - block.parent_nodes = [f.id] | |
| 111 | - block.save! | |
| 112 | - | |
| 113 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 114 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 115 | - expected_json = {'data' => f.title} | |
| 116 | - expected_json['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 117 | - children = [ | |
| 118 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 119 | - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | |
| 120 | - ] | |
| 121 | - expected_json['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 122 | - expected_json['children'] = children | |
| 123 | - expected_json['state'] = 'closed' | |
| 124 | - | |
| 125 | - assert_equal [expected_json], json_response | |
| 126 | - end | |
| 127 | - | |
| 128 | - should 'index action returns an json with all the children nodes and root nodes if some parent is in the parents list and there is others root articles' do | |
| 129 | - Article.delete_all | |
| 130 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 131 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 132 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | |
| 133 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) | |
| 134 | - block.parent_nodes = [f.id] | |
| 135 | - block.save! | |
| 136 | - | |
| 137 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 138 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 139 | - expected_json = [] | |
| 140 | - value = {'data' => f.title} | |
| 141 | - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 142 | - children = [ | |
| 143 | - {'data' => a1.title, 'attr' => {'node_id' => a1.id, 'parent_id' => a1.parent_id}}, | |
| 144 | - {'data' => a2.title, 'attr' => {'node_id' => a2.id, 'parent_id'=> a2.parent_id}} | |
| 145 | - ] | |
| 146 | - value['attr'].merge!({'class' => 'jstree-undetermined'}) | |
| 147 | - value['children'] = children | |
| 148 | - value['state'] = 'closed' | |
| 149 | - expected_json.push(value) | |
| 150 | - | |
| 151 | - value = {'data' => a3.title} | |
| 152 | - value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | |
| 153 | - expected_json.push(value) | |
| 154 | - | |
| 155 | - assert_equal expected_json, json_response | |
| 156 | - end | |
| 157 | - | |
| 158 | - should 'index action returns an json without children nodes if the parent is not in the parents list' do | |
| 159 | - Article.delete_all | |
| 160 | - f = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | |
| 161 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f.id) | |
| 162 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :parent_id => f.id) | |
| 163 | - a3 = fast_create(TextileArticle, :name => 'test article 3', :profile_id => profile.id) | |
| 164 | - | |
| 165 | - get :index, :block_id => block.id, :profile => profile.identifier | |
| 166 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
| 167 | - expected_json = [] | |
| 168 | - value = {'data' => f.title} | |
| 169 | - value['attr'] = { 'node_id' => f.id, 'parent_id' => f.parent_id} | |
| 170 | - value['state'] = 'closed' | |
| 171 | - expected_json.push(value) | |
| 172 | - | |
| 173 | - value = {'data' => a3.title} | |
| 174 | - value['attr'] = { 'node_id' => a3.id, 'parent_id' => a3.parent_id} | |
| 175 | - expected_json.push(value) | |
| 176 | - | |
| 177 | - assert_equal expected_json, json_response | |
| 178 | - end | |
| 179 | - | |
| 180 | -end |
plugins/video/test/functional/video_plugin_myprofile_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 | ... | ... |
plugins/video/test/unit/video_block_test.rb
| ... | ... | @@ -51,6 +51,44 @@ class VideoBlockTest < ActiveSupport::TestCase |
| 51 | 51 | assert !block.is_youtube? |
| 52 | 52 | end |
| 53 | 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 | + | |
| 54 | 92 | #### Tests for Vimeo Videos |
| 55 | 93 | |
| 56 | 94 | should "is_vimeo return true when the url contains http://vimeo.com" do |
| ... | ... | @@ -101,6 +139,37 @@ class VideoBlockTest < ActiveSupport::TestCase |
| 101 | 139 | assert !block.is_vimeo? |
| 102 | 140 | end |
| 103 | 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 | + | |
| 104 | 173 | # Other video formats |
| 105 | 174 | should "is_video return true if url ends with mp4" do |
| 106 | 175 | block = VideoBlock.new |
| ... | ... | @@ -138,4 +207,26 @@ class VideoBlockTest < ActiveSupport::TestCase |
| 138 | 207 | assert !block.is_video_file? |
| 139 | 208 | end |
| 140 | 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 | + should 'display box_organizer/iframe_video_block partial for youtube videos' do | |
| 219 | + block = VideoBlock.new | |
| 220 | + block.url = "youtube.com/?v=XXXXX" | |
| 221 | + | |
| 222 | +# self.expects(:render).with(:partial => 'box_organizer/iframe_video_block', :locals => { | |
| 223 | +# :url => block.format_embed_video_url_for_youtube, | |
| 224 | +# :width => block.width, | |
| 225 | +# :height => block.height | |
| 226 | +# }) | |
| 227 | +c = instance_eval(& block.content) | |
| 228 | +puts c.inspect | |
| 229 | + end | |
| 230 | + | |
| 231 | + | |
| 141 | 232 | end | ... | ... |
plugins/video/test/unit/video_plugin_test.rb
plugins/video/views/box_organizer/_video_block.rhtml
| 1 | 1 | <label for="url" class="formlabel"> Video URL: </label> |
| 2 | 2 | |
| 3 | 3 | <div class="formfield type-text"> |
| 4 | - <%= text_field_tag 'block[url]', @block.url, :class => 'video-url', :maxlength => 255 %> | |
| 4 | + <%= text_field_tag 'block[url]', @block.url, :class => 'video-url', :maxlength => 255 %> | |
| 5 | 5 | </div> |
| 6 | 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 %> | |
| 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 | 11 | </div> | ... | ... |
plugins/video/views/video_block.rhtml
| ... | ... | @@ -3,13 +3,19 @@ |
| 3 | 3 | </h3> |
| 4 | 4 | <div class="video-block-data"> |
| 5 | 5 | <% if block.is_youtube? %> |
| 6 | - <%= render :partial => 'iframe_video_block', :locals => { :url => block.format_embed_video_url_for_youtube, :width => block.width, :height => block.height }%> | |
| 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> | |
| 7 | 9 | <% elsif block.is_vimeo? %> |
| 8 | - <%= render :partial => 'iframe_video_block', :locals => { :url => block.format_embed_video_url_for_vimeo, :width => block.width, :height => block.height }%> | |
| 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> | |
| 9 | 13 | <% elsif block.is_video_file? %> |
| 10 | - <%= render :partial => 'html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> | |
| 14 | + <div class='video'> | |
| 15 | + <%= render :partial => 'box_organizer/html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> | |
| 16 | + </div> | |
| 11 | 17 | <% else %> |
| 12 | - <%= "<span class='alert-block'> Cadastre uma nova URL (Vimeo, Youtube)</span>" %> | |
| 18 | + <span class='alert-block'><%= _("Register a new url (Vimeo, Youtube, Other)") %> | |
| 13 | 19 | <% end %> |
| 14 | 20 | |
| 15 | 21 | </div> | ... | ... |