Commit 5b502e59d288e9aeb48bcd60e267604c88a6eb19
1 parent
7c606c01
Exists in
master
and in
28 other branches
Initial version of Video plugin
Signed-off-by: Leandro Nunes dos Santos <leandronunes@gmail.com> Signed-off-by: Marcos da Silva Ramos <ms.ramos@outlook.com> Signed-off-by: Fábio Teixeira <fabio1079@gmail.com> Signed-off-by: Luiz Matos <luizff.matos@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
18 changed files
with
662 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +README - DisplayContent (DisplayContent Plugin) | ||
2 | +================================ | ||
3 | + | ||
4 | +DisplayContent is a plugin to allow the user adds a block where you could choose any of your content for display it. | ||
5 | + | ||
6 | +The DisplayContent block will be available for all layout columns of communities, peole, enterprises and environments. | ||
7 | + | ||
8 | +All the articles choosen are displayed as a list with a link for the title and the lead content. | ||
9 | + | ||
10 | +If a Blog or a Folder is choosen the block will display all articles inside the blog or the folder. | ||
11 | + | ||
12 | +Galleries are not displayed in this block. | ||
13 | + | ||
14 | +INSTALL | ||
15 | +======= | ||
16 | + | ||
17 | +Enable Plugin | ||
18 | +------------- | ||
19 | + | ||
20 | +Also, you need to enable DisplayContent Plugin at you Noosfero: | ||
21 | + | ||
22 | +cd <your_noosfero_dir> | ||
23 | +./script/noosfero-plugins enable display_content | ||
24 | + | ||
25 | +Active Plugin | ||
26 | +------------- | ||
27 | + | ||
28 | +As a Noosfero administrator user, go to administrator panel: | ||
29 | + | ||
30 | +- Click on "Enable/disable plugins" option | ||
31 | +- Click on "Display Content Plugin" check-box | ||
32 | + | ||
33 | +DEVELOPMENT | ||
34 | +=========== | ||
35 | + | ||
36 | +Noosfero uses jQuery 1.5.1 and the jsTree doesn't works fine with this jQuery version. | ||
37 | +Until Noosfero upgrade its JQuery version to a newer one is necessary to load jQuery 1.8.3 inside plugin and apply some changes in jsTree to avoid jQuery conflit. | ||
38 | + | ||
39 | +Get the Display Content (Noosfero with Display Content Plugin) development repository: | ||
40 | + | ||
41 | +$ git clone https://gitorious.org/+noosfero/noosfero/display_content | ||
42 | + | ||
43 | +Running DisplayContent tests | ||
44 | +-------------------- | ||
45 | + | ||
46 | +$ rake test:noosfero_plugins:display_content | ||
47 | + | ||
48 | + | ||
49 | +Get Involved | ||
50 | +============ | ||
51 | + | ||
52 | +If you found any bug and/or want to collaborate, please send an e-mail to leandronunes@gmail.com | ||
53 | + | ||
54 | +LICENSE | ||
55 | +======= | ||
56 | + | ||
57 | +Copyright (c) The Author developers. | ||
58 | + | ||
59 | +See Noosfero license. | ||
60 | + | ||
61 | + | ||
62 | +AUTHORS | ||
63 | +======= | ||
64 | + | ||
65 | + Leandro Nunes dos Santos (leandronunes at gmail.com) | ||
66 | + | ||
67 | +ACKNOWLEDGMENTS | ||
68 | +=============== | ||
69 | + | ||
70 | +The author have been supported by Serpro |
plugins/video/controllers/video_plugin_admin_controller.rb
0 → 100644
plugins/video/controllers/video_plugin_myprofile_controller.rb
0 → 100644
No preview for this file type
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
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_valid_source? | ||
8 | + | ||
9 | + if url.match(/.*youtu(.be|be.com).*v=[[:alnum:]].*/) | ||
10 | + true | ||
11 | + elsif url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]].*/) | ||
12 | + true | ||
13 | + else | ||
14 | + false | ||
15 | + end | ||
16 | + end | ||
17 | + | ||
18 | + def is_file? | ||
19 | + false | ||
20 | + | ||
21 | + extensions = [".mp4", ".ogg", ".ogv", ".wmv"] | ||
22 | + if extensions.include? url[-4, 4] | ||
23 | + true | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + def format_embed_video_url_for_youtube | ||
28 | + self.url.gsub("watch?v=", "embed/") | ||
29 | + end | ||
30 | + | ||
31 | + def format_embed_video_url_for_vimeo | ||
32 | + self.url.gsub("vimeo.com/", "player.vimeo.com/video/") | ||
33 | + end | ||
34 | + | ||
35 | + def self.description | ||
36 | + _('Add Video') | ||
37 | + end | ||
38 | + | ||
39 | + def help | ||
40 | + _('This block presents a video block.') | ||
41 | + end | ||
42 | + | ||
43 | + def content(args={}) | ||
44 | + block = self | ||
45 | + | ||
46 | + lambda do | ||
47 | + render :file => 'video_block', :locals => { :block => block } | ||
48 | + end | ||
49 | + end | ||
50 | + | ||
51 | + | ||
52 | + def cacheable? | ||
53 | + false | ||
54 | + end | ||
55 | + | ||
56 | +end |
@@ -0,0 +1,19 @@ | @@ -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/display_content_plugin_admin_controller_test.rb
0 → 100644
@@ -0,0 +1,179 @@ | @@ -0,0 +1,179 @@ | ||
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
0 → 100644
@@ -0,0 +1,180 @@ | @@ -0,0 +1,180 @@ | ||
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 |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' |
@@ -0,0 +1,103 @@ | @@ -0,0 +1,103 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +class VideoBlockTest < ActiveSupport::TestCase | ||
3 | + | ||
4 | + ### Tests for YouTube | ||
5 | + | ||
6 | + should "is_valid_source 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_valid_source? | ||
10 | + end | ||
11 | + | ||
12 | + should "is_valid_source 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_valid_source? | ||
16 | + end | ||
17 | + | ||
18 | + should "is_valid_source 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_valid_source? | ||
22 | + end | ||
23 | + | ||
24 | + should "is_valid_source 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_valid_source? | ||
28 | + end | ||
29 | + | ||
30 | + should "is_valid_source return true when the url contains youtube.com" do | ||
31 | + block = VideoBlock.new | ||
32 | + block.url = "youtube.com/?v=XXXXX" | ||
33 | + assert block.is_valid_source? | ||
34 | + end | ||
35 | + | ||
36 | + should "is_valid_source return false when the url not contains youtube video ID" do | ||
37 | + block = VideoBlock.new | ||
38 | + block.url = "youtube.com/" | ||
39 | + assert !block.is_valid_source? | ||
40 | + end | ||
41 | + | ||
42 | + should "is_valid_source 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_valid_source? | ||
46 | + end | ||
47 | + | ||
48 | + should "is_valid_source 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_valid_source? | ||
52 | + end | ||
53 | + | ||
54 | + #### Tests for Vimeo Videos | ||
55 | + | ||
56 | + should "is_valid_source return true when the url contains http://vimeo.com" do | ||
57 | + block = VideoBlock.new | ||
58 | + block.url = "http://vimeo.com/98979" | ||
59 | + assert block.is_valid_source? | ||
60 | + end | ||
61 | + | ||
62 | + should "is_valid_source return true when the url contains https://vimeo.com" do | ||
63 | + block = VideoBlock.new | ||
64 | + block.url = "https://vimeo.com/989798" | ||
65 | + assert block.is_valid_source? | ||
66 | + end | ||
67 | + | ||
68 | + should "is_valid_source return true when the url contains https://www.vimeo.com" do | ||
69 | + block = VideoBlock.new | ||
70 | + block.url = "https://www.vimeo.com/98987" | ||
71 | + assert block.is_valid_source? | ||
72 | + end | ||
73 | + | ||
74 | + should "is_valid_source return true when the url contains www.vimeo.com" do | ||
75 | + block = VideoBlock.new | ||
76 | + block.url = "www.vimeo.com/989798" | ||
77 | + assert block.is_valid_source? | ||
78 | + end | ||
79 | + | ||
80 | + should "is_valid_source return true when the url contains vimeo.com" do | ||
81 | + block = VideoBlock.new | ||
82 | + block.url = "vimeo.com/09898" | ||
83 | + assert block.is_valid_source? | ||
84 | + end | ||
85 | + | ||
86 | + should "is_valid_source return false when the url not contains vimeo video ID" do | ||
87 | + block = VideoBlock.new | ||
88 | + block.url = "vimeo.com/home" | ||
89 | + assert !block.is_valid_source? | ||
90 | + end | ||
91 | + | ||
92 | + should "is_valid_source return false when the url contains empty vimeo video ID" do | ||
93 | + block = VideoBlock.new | ||
94 | + block.url = "vimeo.com/" | ||
95 | + assert !block.is_valid_source? | ||
96 | + end | ||
97 | + | ||
98 | + should "is_valid_source return false when the url contains an invalid vimeo link" do | ||
99 | + block = VideoBlock.new | ||
100 | + block.url = "http://www.vmsd.com/98979" | ||
101 | + assert !block.is_valid_source? | ||
102 | + end | ||
103 | +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 @@ | @@ -0,0 +1 @@ | ||
1 | +<iframe width=<%="#{width}px"%> height=<%="#{height}px"%> src=<%= "#{url}" %> frameborder="0" allowfullscreen></iframe> |
@@ -0,0 +1,11 @@ | @@ -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,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +<h3 class="block-title"> | ||
2 | + <span><%=block.title%></span> | ||
3 | +</h3> | ||
4 | +<div class="video-block-data"> | ||
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 }%> | ||
7 | + <% 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 }%> | ||
9 | + <% elsif block.is_file? %> | ||
10 | + <%= render :partial => 'html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> | ||
11 | + <% else %> | ||
12 | + <%= "<span class='alert-block'> Cadastre uma nova URL (Vimeo, Youtube)</span>" %> | ||
13 | + <% end %> | ||
14 | + | ||
15 | +</div> |