Commit 1451d7e5081fa75ff44775c48c0691fe1baee7d8
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/259' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/259 Conflicts: app/controllers/admin/environment_design_controller.rb
Showing
7 changed files
with
1024 additions
and
19 deletions
Show diff stats
app/controllers/admin/environment_design_controller.rb
... | ... | @@ -4,6 +4,7 @@ class EnvironmentDesignController < BoxOrganizerController |
4 | 4 | |
5 | 5 | def available_blocks |
6 | 6 | @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] |
7 | + @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) | |
7 | 8 | end |
8 | 9 | |
9 | 10 | end | ... | ... |
app/controllers/box_organizer_controller.rb
... | ... | @@ -68,8 +68,8 @@ class BoxOrganizerController < ApplicationController |
68 | 68 | raise ArgumentError.new("Type %s is not allowed. Go away." % type) |
69 | 69 | end |
70 | 70 | else |
71 | - @center_block_types = Box.acceptable_center_blocks & available_blocks | |
72 | - @side_block_types = Box.acceptable_side_blocks & available_blocks | |
71 | + @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1) | |
72 | + @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]) | |
73 | 73 | @boxes = boxes_holder.boxes |
74 | 74 | render :action => 'add_block', :layout => false |
75 | 75 | end | ... | ... |
app/controllers/my_profile/profile_design_controller.rb
... | ... | @@ -7,17 +7,25 @@ class ProfileDesignController < BoxOrganizerController |
7 | 7 | def available_blocks |
8 | 8 | blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] |
9 | 9 | |
10 | + blocks += plugins.dispatch(:extra_blocks) | |
11 | + | |
10 | 12 | # blocks exclusive for organizations |
11 | 13 | if profile.has_members? |
12 | 14 | blocks << MembersBlock |
13 | 15 | end |
14 | 16 | |
15 | - # blocks exclusive to person | |
17 | + # blocks exclusive to people | |
16 | 18 | if profile.person? |
17 | 19 | blocks << FriendsBlock |
18 | 20 | blocks << FavoriteEnterprisesBlock |
19 | 21 | blocks << CommunitiesBlock |
20 | 22 | blocks << EnterprisesBlock |
23 | + blocks += plugins.dispatch(:extra_blocks, :type => Person) | |
24 | + end | |
25 | + | |
26 | + # blocks exclusive to communities | |
27 | + if profile.community? | |
28 | + blocks += plugins.dispatch(:extra_blocks, :type => Community) | |
21 | 29 | end |
22 | 30 | |
23 | 31 | # blocks exclusive for enterprises |
... | ... | @@ -26,6 +34,7 @@ class ProfileDesignController < BoxOrganizerController |
26 | 34 | blocks << HighlightsBlock |
27 | 35 | blocks << FeaturedProductsBlock |
28 | 36 | blocks << FansBlock |
37 | + blocks += plugins.dispatch(:extra_blocks, :type => Enterprise) | |
29 | 38 | end |
30 | 39 | |
31 | 40 | # product block exclusive for enterprises in environments that permits it |
... | ... | @@ -33,7 +42,7 @@ class ProfileDesignController < BoxOrganizerController |
33 | 42 | blocks << ProductsBlock |
34 | 43 | end |
35 | 44 | |
36 | - # block exclusive to profile has blog | |
45 | + # block exclusive to profiles that have blog | |
37 | 46 | if profile.has_blog? |
38 | 47 | blocks << BlogArchivesBlock |
39 | 48 | end | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -97,6 +97,35 @@ class Noosfero::Plugin |
97 | 97 | ERB.new(File.read("#{views_path}/#{file_path}")).result(binding) |
98 | 98 | end |
99 | 99 | |
100 | + def extra_blocks(params = {}) | |
101 | + return [] if self.class.extra_blocks.nil? | |
102 | + blocks = self.class.extra_blocks.map do |block, options| | |
103 | + type = options[:type] | |
104 | + type = type.is_a?(Array) ? type : [type].compact | |
105 | + type = type.map do |x| | |
106 | + x.is_a?(String) ? x.capitalize.constantize : x | |
107 | + end | |
108 | + raise "This is not a valid type" if !type.empty? && ![Person, Community, Enterprise, Environment].detect{|m| type.include?(m)} | |
109 | + | |
110 | + position = options[:position] | |
111 | + position = position.is_a?(Array) ? position : [position].compact | |
112 | + position = position.map{|p| p.to_i} | |
113 | + raise "This is not a valid position" if !position.empty? && ![1,2,3].detect{|m| position.include?(m)} | |
114 | + | |
115 | + if !type.empty? && (params[:type] != :all) | |
116 | + block = type.include?(params[:type]) ? block : nil | |
117 | + end | |
118 | + | |
119 | + if !position.empty? && !params[:position].nil? | |
120 | + block = position.detect{ |p| [params[:position]].flatten.include?(p)} ? block : nil | |
121 | + end | |
122 | + | |
123 | + block | |
124 | + end | |
125 | + blocks.compact! | |
126 | + blocks || [] | |
127 | + end | |
128 | + | |
100 | 129 | # Here the developer may specify the events to which the plugins can |
101 | 130 | # register and must return true or false. The default value must be false. |
102 | 131 | |
... | ... | @@ -351,6 +380,60 @@ class Noosfero::Plugin |
351 | 380 | nil |
352 | 381 | end |
353 | 382 | |
383 | + # -> Adds additional blocks to profiles and environments. | |
384 | + # Your plugin must implements a class method called 'extra_blocks' | |
385 | + # that returns a hash with the following syntax. | |
386 | + # { | |
387 | + # 'block_name' => | |
388 | + # { | |
389 | + # :type => 'for which holder the block will be available', | |
390 | + # :position => 'where the block could be displayed' | |
391 | + # } | |
392 | + # } | |
393 | + # | |
394 | + # Where: | |
395 | + # | |
396 | + # - block_name: Name of the new block added to the blocks list | |
397 | + # - type: Might have some of the values | |
398 | + # - 'environment' or Environment: If the block is available only for Environment models | |
399 | + # - 'community' or Community: If the block is available only for Community models | |
400 | + # - 'enterprise' or Enterprise: If the block is available only for Enterprise models | |
401 | + # - 'person' or Person: If the block is available only for Person models | |
402 | + # - nil: If no type parameter is passed the block will be available for all types | |
403 | + # - position: Is the layout position of the block. It should be: | |
404 | + # - '1' or 1: Area 1 of layout | |
405 | + # - '2' or 2: Area 2 of layout | |
406 | + # - '3' or 3: Area 3 of layout | |
407 | + # - nil: If no position parameter is passed the block will be available for all positions | |
408 | + # | |
409 | + # OBS: Area 1 is where stay the main content of layout. Areas 2 and 3 are the sides of layout. | |
410 | + # | |
411 | + # examples: | |
412 | + # | |
413 | + # def self.extra_blocks(params) | |
414 | + # { | |
415 | + # #Display 'CustomBlock1' only for 'Person' on position '1' | |
416 | + # CustomBlock1 => {:type => 'person', :position => '1' }, | |
417 | + # | |
418 | + # #Display 'CustomBlock2' only for 'Community' on position '2' | |
419 | + # CustomBlock2 => {:type => Community, :position => '2' }, | |
420 | + # | |
421 | + # #Display 'CustomBlock3' only for 'Enterprise' on position '3' | |
422 | + # CustomBlock3 => {:type => 'enterprise', :position => 3 }, | |
423 | + # | |
424 | + # #Display 'CustomBlock2' for 'Environment' and 'Person' on positions '1' and '3' | |
425 | + # CustomBlock4 => {:type => ['environment', Person], :position => ['1','3'] }, | |
426 | + # | |
427 | + # #Display 'CustomBlock5' for all types and all positions | |
428 | + # CustomBlock5 => {}, | |
429 | + # } | |
430 | + # end | |
431 | + # | |
432 | + # OBS: The default value is a empty hash. | |
433 | + def self.extra_blocks | |
434 | + {} | |
435 | + end | |
436 | + | |
354 | 437 | def method_missing(method, *args, &block) |
355 | 438 | # This is a generic hotspot for all controllers on Noosfero. |
356 | 439 | # If any plugin wants to define filters to run on any controller, the name of | ... | ... |
test/functional/environment_design_controller_test.rb
... | ... | @@ -12,22 +12,23 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
12 | 12 | @controller = EnvironmentDesignController.new |
13 | 13 | @request = ActionController::TestRequest.new |
14 | 14 | @response = ActionController::TestResponse.new |
15 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
15 | 16 | end |
16 | 17 | |
17 | 18 | def test_local_files_reference |
18 | 19 | assert_local_files_reference |
19 | 20 | end |
20 | - | |
21 | + | |
21 | 22 | def test_valid_xhtml |
22 | 23 | assert_valid_xhtml |
23 | 24 | end |
24 | - | |
25 | + | |
25 | 26 | should 'indicate only actual blocks as such' do |
26 | 27 | assert(@controller.available_blocks.all? {|item| item.new.is_a? Block}) |
27 | 28 | end |
28 | 29 | |
29 | 30 | ALL_BLOCKS.map do |block| |
30 | - define_method "test_should_#{block.to_s}_is_available" do | |
31 | + define_method "test_should_#{block.to_s}_is_available" do | |
31 | 32 | assert_includes @controller.available_blocks,block |
32 | 33 | end |
33 | 34 | end |
... | ... | @@ -191,7 +192,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
191 | 192 | |
192 | 193 | assert_tag :tag => 'a', :attributes => {:href => '/admin'}, :child => {:tag => 'span', :content => "Back to control panel"} |
193 | 194 | end |
194 | - | |
195 | + | |
195 | 196 | should 'render add a new block functionality' do |
196 | 197 | login_as(create_admin_user(Environment.default)) |
197 | 198 | get :add_block |
... | ... | @@ -199,4 +200,170 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
199 | 200 | assert_response :success |
200 | 201 | assert_template 'add_block' |
201 | 202 | end |
203 | + | |
204 | + should 'a environment block plugin add new blocks for environments' do | |
205 | + class CustomBlock1 < Block; end; | |
206 | + | |
207 | + class TestBlockPlugin < Noosfero::Plugin | |
208 | + def self.extra_blocks | |
209 | + { | |
210 | + CustomBlock1 => {:type => Environment}, | |
211 | + } | |
212 | + end | |
213 | + end | |
214 | + | |
215 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
216 | + assert @controller.available_blocks.include?(CustomBlock1) | |
217 | + end | |
218 | + | |
219 | + should 'a person, enterprise and community blocks plugins do not add new blocks for environments' do | |
220 | + class CustomBlock1 < Block; end; | |
221 | + class CustomBlock2 < Block; end; | |
222 | + class CustomBlock3 < Block; end; | |
223 | + class CustomBlock4 < Block; end; | |
224 | + | |
225 | + class TestBlockPlugin < Noosfero::Plugin | |
226 | + def self.extra_blocks | |
227 | + { | |
228 | + CustomBlock1 => {:type => Environment}, | |
229 | + CustomBlock2 => {:type => Enterprise}, | |
230 | + CustomBlock3 => {:type => Community}, | |
231 | + CustomBlock4 => {:type => Person}, | |
232 | + } | |
233 | + end | |
234 | + end | |
235 | + | |
236 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
237 | + assert @controller.available_blocks.include?(CustomBlock1) | |
238 | + assert !@controller.available_blocks.include?(CustomBlock2) | |
239 | + assert !@controller.available_blocks.include?(CustomBlock3) | |
240 | + assert !@controller.available_blocks.include?(CustomBlock4) | |
241 | + end | |
242 | + | |
243 | + should 'a block plugin with center position add new blocks only in this position' do | |
244 | + class CustomBlock1 < Block; end; | |
245 | + class CustomBlock2 < Block; end; | |
246 | + class CustomBlock3 < Block; end; | |
247 | + class CustomBlock4 < Block; end; | |
248 | + class CustomBlock5 < Block; end; | |
249 | + class CustomBlock6 < Block; end; | |
250 | + class CustomBlock7 < Block; end; | |
251 | + class CustomBlock8 < Block; end; | |
252 | + class CustomBlock9 < Block; end; | |
253 | + | |
254 | + class TestBlockPlugin < Noosfero::Plugin | |
255 | + def self.extra_blocks | |
256 | + { | |
257 | + CustomBlock1 => {:type => Environment, :position => [1]}, | |
258 | + CustomBlock2 => {:type => Environment, :position => 1}, | |
259 | + CustomBlock3 => {:type => Environment, :position => '1'}, | |
260 | + CustomBlock4 => {:type => Environment, :position => [2]}, | |
261 | + CustomBlock5 => {:type => Environment, :position => 2}, | |
262 | + CustomBlock6 => {:type => Environment, :position => '2'}, | |
263 | + CustomBlock7 => {:type => Environment, :position => [3]}, | |
264 | + CustomBlock8 => {:type => Environment, :position => 3}, | |
265 | + CustomBlock9 => {:type => Environment, :position => '3'}, | |
266 | + } | |
267 | + end | |
268 | + end | |
269 | + | |
270 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
271 | + login_as(create_admin_user(Environment.default)) | |
272 | + get :add_block | |
273 | + | |
274 | + assert_response :success | |
275 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
276 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
277 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
278 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
279 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) | |
280 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) | |
281 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) | |
282 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) | |
283 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) | |
284 | + end | |
285 | + | |
286 | + should 'a block plugin with side position add new blocks only in this position' do | |
287 | + class CustomBlock1 < Block; end; | |
288 | + class CustomBlock2 < Block; end; | |
289 | + class CustomBlock3 < Block; end; | |
290 | + class CustomBlock4 < Block; end; | |
291 | + class CustomBlock5 < Block; end; | |
292 | + class CustomBlock6 < Block; end; | |
293 | + class CustomBlock7 < Block; end; | |
294 | + class CustomBlock8 < Block; end; | |
295 | + class CustomBlock9 < Block; end; | |
296 | + | |
297 | + class TestBlockPlugin < Noosfero::Plugin | |
298 | + def self.extra_blocks | |
299 | + { | |
300 | + CustomBlock1 => {:type => Environment, :position => [1]}, | |
301 | + CustomBlock2 => {:type => Environment, :position => 1}, | |
302 | + CustomBlock3 => {:type => Environment, :position => '1'}, | |
303 | + CustomBlock4 => {:type => Environment, :position => [2]}, | |
304 | + CustomBlock5 => {:type => Environment, :position => 2}, | |
305 | + CustomBlock6 => {:type => Environment, :position => '2'}, | |
306 | + CustomBlock7 => {:type => Environment, :position => [3]}, | |
307 | + CustomBlock8 => {:type => Environment, :position => 3}, | |
308 | + CustomBlock9 => {:type => Environment, :position => '3'}, | |
309 | + } | |
310 | + end | |
311 | + end | |
312 | + | |
313 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
314 | + login_as(create_admin_user(Environment.default)) | |
315 | + get :add_block | |
316 | + assert_response :success | |
317 | + | |
318 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) | |
319 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) | |
320 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) | |
321 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) | |
322 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
323 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
324 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
325 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
326 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | |
327 | + end | |
328 | + | |
329 | + should 'a block plugin cannot be listed for unspecified types' do | |
330 | + class CustomBlock1 < Block; end; | |
331 | + class CustomBlock2 < Block; end; | |
332 | + class CustomBlock3 < Block; end; | |
333 | + class CustomBlock4 < Block; end; | |
334 | + class CustomBlock5 < Block; end; | |
335 | + class CustomBlock6 < Block; end; | |
336 | + class CustomBlock7 < Block; end; | |
337 | + class CustomBlock8 < Block; end; | |
338 | + | |
339 | + class TestBlockPlugin < Noosfero::Plugin | |
340 | + def self.extra_blocks | |
341 | + { | |
342 | + CustomBlock1 => {:type => Person, :position => 1}, | |
343 | + CustomBlock2 => {:type => Community, :position => 1}, | |
344 | + CustomBlock3 => {:type => Enterprise, :position => 1}, | |
345 | + CustomBlock4 => {:type => Environment, :position => 1}, | |
346 | + CustomBlock5 => {:type => Person, :position => 2}, | |
347 | + CustomBlock6 => {:type => Community, :position => 3}, | |
348 | + CustomBlock7 => {:type => Enterprise, :position => 2}, | |
349 | + CustomBlock8 => {:type => Environment, :position => 3}, | |
350 | + } | |
351 | + end | |
352 | + end | |
353 | + | |
354 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
355 | + login_as(create_admin_user(Environment.default)) | |
356 | + get :add_block | |
357 | + assert_response :success | |
358 | + | |
359 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
360 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
361 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
362 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
363 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
364 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
365 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
366 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
367 | + end | |
368 | + | |
202 | 369 | end | ... | ... |
test/functional/profile_design_controller_test.rb
... | ... | @@ -4,7 +4,7 @@ require 'profile_design_controller' |
4 | 4 | class ProfileDesignController; def rescue_action(e) raise e end; end |
5 | 5 | |
6 | 6 | class ProfileDesignControllerTest < ActionController::TestCase |
7 | - | |
7 | + | |
8 | 8 | COMMOM_BLOCKS = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] |
9 | 9 | PERSON_BLOCKS = COMMOM_BLOCKS + [FriendsBlock, FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ] |
10 | 10 | PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] |
... | ... | @@ -21,7 +21,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
21 | 21 | |
22 | 22 | @profile = @holder = create_user('designtestuser').person |
23 | 23 | holder.save! |
24 | - | |
24 | + | |
25 | 25 | @box1 = Box.new |
26 | 26 | @box2 = Box.new |
27 | 27 | @box3 = Box.new |
... | ... | @@ -38,7 +38,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
38 | 38 | @b2 = Block.new |
39 | 39 | @box1.blocks << @b2 |
40 | 40 | @b2.save! |
41 | - | |
41 | + | |
42 | 42 | ###### BOX 2 |
43 | 43 | @b3 = Block.new |
44 | 44 | @box2.blocks << @b3 |
... | ... | @@ -55,7 +55,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
55 | 55 | @b6 = Block.new |
56 | 56 | @box2.blocks << @b6 |
57 | 57 | @b6.save! |
58 | - | |
58 | + | |
59 | 59 | ###### BOX 3 |
60 | 60 | @b7 = Block.new |
61 | 61 | @box3.blocks << @b7 |
... | ... | @@ -79,13 +79,13 @@ class ProfileDesignControllerTest < ActionController::TestCase |
79 | 79 | def test_local_files_reference |
80 | 80 | assert_local_files_reference :get, :index, :profile => 'designtestuser' |
81 | 81 | end |
82 | - | |
82 | + | |
83 | 83 | def test_valid_xhtml |
84 | 84 | assert_valid_xhtml |
85 | 85 | end |
86 | - | |
86 | + | |
87 | 87 | ###################################################### |
88 | - # BEGIN - tests for BoxOrganizerController features | |
88 | + # BEGIN - tests for BoxOrganizerController features | |
89 | 89 | ###################################################### |
90 | 90 | def test_should_move_block_to_the_end_of_another_block |
91 | 91 | get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" |
... | ... | @@ -177,12 +177,135 @@ class ProfileDesignControllerTest < ActionController::TestCase |
177 | 177 | end |
178 | 178 | end |
179 | 179 | |
180 | + should 'a block plugin with center position add new blocks only in this position' do | |
181 | + class CustomBlock1 < Block; end; | |
182 | + class CustomBlock2 < Block; end; | |
183 | + class CustomBlock3 < Block; end; | |
184 | + class CustomBlock4 < Block; end; | |
185 | + class CustomBlock5 < Block; end; | |
186 | + class CustomBlock6 < Block; end; | |
187 | + class CustomBlock7 < Block; end; | |
188 | + class CustomBlock8 < Block; end; | |
189 | + class CustomBlock9 < Block; end; | |
190 | + | |
191 | + class TestBlockPlugin < Noosfero::Plugin | |
192 | + def self.extra_blocks | |
193 | + { | |
194 | + CustomBlock1 => {:type => Person, :position => [1]}, | |
195 | + CustomBlock2 => {:type => Person, :position => 1}, | |
196 | + CustomBlock3 => {:type => Person, :position => '1'}, | |
197 | + CustomBlock4 => {:type => Person, :position => [2]}, | |
198 | + CustomBlock5 => {:type => Person, :position => 2}, | |
199 | + CustomBlock6 => {:type => Person, :position => '2'}, | |
200 | + CustomBlock7 => {:type => Person, :position => [3]}, | |
201 | + CustomBlock8 => {:type => Person, :position => 3}, | |
202 | + CustomBlock9 => {:type => Person, :position => '3'}, | |
203 | + } | |
204 | + end | |
205 | + end | |
206 | + | |
207 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
208 | + get :add_block, :profile => 'designtestuser' | |
209 | + assert_response :success | |
210 | + | |
211 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
212 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
213 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
214 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
215 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) | |
216 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) | |
217 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) | |
218 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) | |
219 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) | |
220 | + end | |
221 | + | |
222 | + should 'a block plugin with side position add new blocks only in this position' do | |
223 | + class CustomBlock1 < Block; end; | |
224 | + class CustomBlock2 < Block; end; | |
225 | + class CustomBlock3 < Block; end; | |
226 | + class CustomBlock4 < Block; end; | |
227 | + class CustomBlock5 < Block; end; | |
228 | + class CustomBlock6 < Block; end; | |
229 | + class CustomBlock7 < Block; end; | |
230 | + class CustomBlock8 < Block; end; | |
231 | + class CustomBlock9 < Block; end; | |
232 | + | |
233 | + class TestBlockPlugin < Noosfero::Plugin | |
234 | + def self.extra_blocks | |
235 | + { | |
236 | + CustomBlock1 => {:type => Person, :position => [1]}, | |
237 | + CustomBlock2 => {:type => Person, :position => 1}, | |
238 | + CustomBlock3 => {:type => Person, :position => '1'}, | |
239 | + CustomBlock4 => {:type => Person, :position => [2]}, | |
240 | + CustomBlock5 => {:type => Person, :position => 2}, | |
241 | + CustomBlock6 => {:type => Person, :position => '2'}, | |
242 | + CustomBlock7 => {:type => Person, :position => [3]}, | |
243 | + CustomBlock8 => {:type => Person, :position => 3}, | |
244 | + CustomBlock9 => {:type => Person, :position => '3'}, | |
245 | + } | |
246 | + end | |
247 | + end | |
248 | + | |
249 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
250 | + get :add_block, :profile => 'designtestuser' | |
251 | + assert_response :success | |
252 | + | |
253 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) | |
254 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) | |
255 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) | |
256 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) | |
257 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
258 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
259 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
260 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
261 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | |
262 | + end | |
263 | + | |
264 | + should 'a block plugin cannot be listed for unspecified types' do | |
265 | + class CustomBlock1 < Block; end; | |
266 | + class CustomBlock2 < Block; end; | |
267 | + class CustomBlock3 < Block; end; | |
268 | + class CustomBlock4 < Block; end; | |
269 | + class CustomBlock5 < Block; end; | |
270 | + class CustomBlock6 < Block; end; | |
271 | + class CustomBlock7 < Block; end; | |
272 | + class CustomBlock8 < Block; end; | |
273 | + | |
274 | + class TestBlockPlugin < Noosfero::Plugin | |
275 | + def self.extra_blocks | |
276 | + { | |
277 | + CustomBlock1 => {:type => Person, :position => 1}, | |
278 | + CustomBlock2 => {:type => Community, :position => 1}, | |
279 | + CustomBlock3 => {:type => Enterprise, :position => 1}, | |
280 | + CustomBlock4 => {:type => Environment, :position => 1}, | |
281 | + CustomBlock5 => {:type => Person, :position => 2}, | |
282 | + CustomBlock6 => {:type => Community, :position => 3}, | |
283 | + CustomBlock7 => {:type => Enterprise, :position => 2}, | |
284 | + CustomBlock8 => {:type => Environment, :position => 3}, | |
285 | + } | |
286 | + end | |
287 | + end | |
288 | + | |
289 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
290 | + get :add_block, :profile => 'designtestuser' | |
291 | + assert_response :success | |
292 | + | |
293 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
294 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
295 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
296 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
297 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
298 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
299 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
300 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
301 | + end | |
302 | + | |
180 | 303 | ###################################################### |
181 | - # END - tests for BoxOrganizerController features | |
304 | + # END - tests for BoxOrganizerController features | |
182 | 305 | ###################################################### |
183 | 306 | |
184 | 307 | ###################################################### |
185 | - # BEGIN - tests for ProfileDesignController features | |
308 | + # BEGIN - tests for ProfileDesignController features | |
186 | 309 | ###################################################### |
187 | 310 | |
188 | 311 | should 'display popup for adding a new block' do |
... | ... | @@ -285,10 +408,10 @@ class ProfileDesignControllerTest < ActionController::TestCase |
285 | 408 | |
286 | 409 | should 'create back link to profile control panel' do |
287 | 410 | p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile') |
288 | - | |
411 | + | |
289 | 412 | login_as(create_user_with_permission('test_user','edit_profile_design',p).identifier ) |
290 | 413 | get :index, :profile => p.identifier |
291 | - | |
414 | + | |
292 | 415 | assert_tag :tag => 'a', :attributes => {:href => '/myprofile/test_profile'} |
293 | 416 | end |
294 | 417 | |
... | ... | @@ -349,6 +472,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
349 | 472 | profile = mock |
350 | 473 | profile.stubs(:has_members?).returns(false) |
351 | 474 | profile.stubs(:person?).returns(true) |
475 | + profile.stubs(:community?).returns(true) | |
352 | 476 | profile.stubs(:enterprise?).returns(false) |
353 | 477 | profile.stubs(:has_blog?).returns(false) |
354 | 478 | profile.stubs(:is_admin?).with(anything).returns(false) |
... | ... | @@ -357,6 +481,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
357 | 481 | environment.stubs(:enabled?).returns(false) |
358 | 482 | @controller.stubs(:profile).returns(profile) |
359 | 483 | @controller.stubs(:user).returns(profile) |
484 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
360 | 485 | assert_equal PERSON_BLOCKS, @controller.available_blocks |
361 | 486 | end |
362 | 487 | |
... | ... | @@ -364,6 +489,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
364 | 489 | profile = mock |
365 | 490 | profile.stubs(:has_members?).returns(true) |
366 | 491 | profile.stubs(:person?).returns(true) |
492 | + profile.stubs(:community?).returns(true) | |
367 | 493 | profile.stubs(:enterprise?).returns(false) |
368 | 494 | profile.stubs(:has_blog?).returns(false) |
369 | 495 | profile.stubs(:is_admin?).with(anything).returns(false) |
... | ... | @@ -372,6 +498,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
372 | 498 | environment.stubs(:enabled?).returns(false) |
373 | 499 | @controller.stubs(:profile).returns(profile) |
374 | 500 | @controller.stubs(:user).returns(profile) |
501 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
375 | 502 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS |
376 | 503 | end |
377 | 504 | |
... | ... | @@ -379,6 +506,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
379 | 506 | profile = mock |
380 | 507 | profile.stubs(:has_members?).returns(false) |
381 | 508 | profile.stubs(:person?).returns(true) |
509 | + profile.stubs(:community?).returns(true) | |
382 | 510 | profile.stubs(:enterprise?).returns(false) |
383 | 511 | profile.stubs(:has_blog?).returns(true) |
384 | 512 | profile.stubs(:is_admin?).with(anything).returns(false) |
... | ... | @@ -387,6 +515,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
387 | 515 | environment.stubs(:enabled?).returns(false) |
388 | 516 | @controller.stubs(:profile).returns(profile) |
389 | 517 | @controller.stubs(:user).returns(profile) |
518 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
390 | 519 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG |
391 | 520 | end |
392 | 521 | |
... | ... | @@ -394,6 +523,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
394 | 523 | profile = mock |
395 | 524 | profile.stubs(:has_members?).returns(false) |
396 | 525 | profile.stubs(:person?).returns(false) |
526 | + profile.stubs(:community?).returns(true) | |
397 | 527 | profile.stubs(:enterprise?).returns(true) |
398 | 528 | profile.stubs(:has_blog?).returns(false) |
399 | 529 | profile.stubs(:is_admin?).with(anything).returns(false) |
... | ... | @@ -402,6 +532,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
402 | 532 | environment.stubs(:enabled?).returns(true) |
403 | 533 | @controller.stubs(:profile).returns(profile) |
404 | 534 | @controller.stubs(:user).returns(profile) |
535 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
405 | 536 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS |
406 | 537 | end |
407 | 538 | |
... | ... | @@ -409,6 +540,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
409 | 540 | profile = mock |
410 | 541 | profile.stubs(:has_members?).returns(false) |
411 | 542 | profile.stubs(:person?).returns(false) |
543 | + profile.stubs(:community?).returns(true) | |
412 | 544 | profile.stubs(:enterprise?).returns(true) |
413 | 545 | profile.stubs(:has_blog?).returns(false) |
414 | 546 | profile.stubs(:is_admin?).with(anything).returns(false) |
... | ... | @@ -417,6 +549,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
417 | 549 | environment.stubs(:enabled?).returns(false) |
418 | 550 | @controller.stubs(:profile).returns(profile) |
419 | 551 | @controller.stubs(:user).returns(profile) |
552 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
420 | 553 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE |
421 | 554 | end |
422 | 555 | |
... | ... | @@ -441,4 +574,144 @@ class ProfileDesignControllerTest < ActionController::TestCase |
441 | 574 | assert_tag :tag => 'option', :attributes => {:value => selected_article.id, :selected => 'selected'} |
442 | 575 | end |
443 | 576 | |
577 | + should 'the block plugin add a new block' do | |
578 | + profile = mock | |
579 | + profile.stubs(:has_members?).returns(false) | |
580 | + profile.stubs(:person?).returns(true) | |
581 | + profile.stubs(:community?).returns(true) | |
582 | + profile.stubs(:enterprise?).returns(false) | |
583 | + profile.stubs(:has_blog?).returns(false) | |
584 | + profile.stubs(:is_admin?).with(anything).returns(false) | |
585 | + environment = mock | |
586 | + profile.stubs(:environment).returns(environment) | |
587 | + environment.stubs(:enabled?).returns(false) | |
588 | + @controller.stubs(:profile).returns(profile) | |
589 | + @controller.stubs(:user).returns(profile) | |
590 | + | |
591 | + class CustomBlock1 < Block; end; | |
592 | + | |
593 | + class TestBlockPlugin < Noosfero::Plugin | |
594 | + def self.extra_blocks | |
595 | + { | |
596 | + CustomBlock1 => {}, | |
597 | + } | |
598 | + end | |
599 | + end | |
600 | + | |
601 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
602 | + assert @controller.available_blocks.include?(CustomBlock1) | |
603 | + end | |
604 | + | |
605 | + should 'a person block plugin add new blocks for person profile' do | |
606 | + profile = mock | |
607 | + profile.stubs(:has_members?).returns(false) | |
608 | + profile.stubs(:person?).returns(true) | |
609 | + profile.stubs(:community?).returns(false) | |
610 | + profile.stubs(:enterprise?).returns(false) | |
611 | + profile.stubs(:has_blog?).returns(false) | |
612 | + profile.stubs(:is_admin?).with(anything).returns(false) | |
613 | + environment = mock | |
614 | + profile.stubs(:environment).returns(environment) | |
615 | + environment.stubs(:enabled?).returns(false) | |
616 | + @controller.stubs(:profile).returns(profile) | |
617 | + @controller.stubs(:user).returns(profile) | |
618 | + | |
619 | + class CustomBlock1 < Block; end; | |
620 | + | |
621 | + class TestBlockPlugin < Noosfero::Plugin | |
622 | + def self.extra_blocks | |
623 | + { | |
624 | + CustomBlock1 => {:type => Person}, | |
625 | + } | |
626 | + end | |
627 | + end | |
628 | + | |
629 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
630 | + assert @controller.available_blocks.include?(CustomBlock1) | |
631 | + end | |
632 | + | |
633 | + should 'a community block plugin add new blocks for community profile' do | |
634 | + profile = mock | |
635 | + profile.stubs(:has_members?).returns(false) | |
636 | + profile.stubs(:person?).returns(false) | |
637 | + profile.stubs(:community?).returns(true) | |
638 | + profile.stubs(:enterprise?).returns(false) | |
639 | + profile.stubs(:has_blog?).returns(false) | |
640 | + profile.stubs(:is_admin?).with(anything).returns(false) | |
641 | + environment = mock | |
642 | + profile.stubs(:environment).returns(environment) | |
643 | + environment.stubs(:enabled?).returns(false) | |
644 | + @controller.stubs(:profile).returns(profile) | |
645 | + @controller.stubs(:user).returns(profile) | |
646 | + | |
647 | + class CustomBlock1 < Block; end; | |
648 | + | |
649 | + class TestBlockPlugin < Noosfero::Plugin | |
650 | + def self.extra_blocks | |
651 | + { | |
652 | + CustomBlock1 => {:type => Community}, | |
653 | + } | |
654 | + end | |
655 | + end | |
656 | + | |
657 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
658 | + assert @controller.available_blocks.include?(CustomBlock1) | |
659 | + end | |
660 | + | |
661 | + should 'a enterprise block plugin add new blocks for enterprise profile' do | |
662 | + profile = mock | |
663 | + profile.stubs(:has_members?).returns(false) | |
664 | + profile.stubs(:person?).returns(false) | |
665 | + profile.stubs(:community?).returns(false) | |
666 | + profile.stubs(:enterprise?).returns(true) | |
667 | + profile.stubs(:has_blog?).returns(false) | |
668 | + profile.stubs(:is_admin?).with(anything).returns(false) | |
669 | + environment = mock | |
670 | + profile.stubs(:environment).returns(environment) | |
671 | + environment.stubs(:enabled?).returns(false) | |
672 | + @controller.stubs(:profile).returns(profile) | |
673 | + @controller.stubs(:user).returns(profile) | |
674 | + | |
675 | + class CustomBlock1 < Block; end; | |
676 | + | |
677 | + class TestBlockPlugin < Noosfero::Plugin | |
678 | + def self.extra_blocks | |
679 | + { | |
680 | + CustomBlock1 => {:type => Enterprise}, | |
681 | + } | |
682 | + end | |
683 | + end | |
684 | + | |
685 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
686 | + assert @controller.available_blocks.include?(CustomBlock1) | |
687 | + end | |
688 | + | |
689 | + should 'an environment block plugin not add new blocks for enterprise, person or community profiles' do | |
690 | + profile = mock | |
691 | + profile.stubs(:has_members?).returns(false) | |
692 | + profile.stubs(:person?).returns(true) | |
693 | + profile.stubs(:community?).returns(true) | |
694 | + profile.stubs(:enterprise?).returns(true) | |
695 | + profile.stubs(:has_blog?).returns(false) | |
696 | + profile.stubs(:is_admin?).with(anything).returns(false) | |
697 | + environment = mock | |
698 | + profile.stubs(:environment).returns(environment) | |
699 | + environment.stubs(:enabled?).returns(false) | |
700 | + @controller.stubs(:profile).returns(profile) | |
701 | + @controller.stubs(:user).returns(profile) | |
702 | + | |
703 | + class CustomBlock1 < Block; end; | |
704 | + | |
705 | + class TestBlockPlugin < Noosfero::Plugin | |
706 | + def self.extra_blocks | |
707 | + { | |
708 | + CustomBlock1 => {:type => Environment}, | |
709 | + } | |
710 | + end | |
711 | + end | |
712 | + | |
713 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
714 | + assert !@controller.available_blocks.include?(CustomBlock1) | |
715 | + end | |
716 | + | |
444 | 717 | end | ... | ... |
test/unit/plugin_test.rb
... | ... | @@ -26,4 +26,476 @@ class PluginTest < ActiveSupport::TestCase |
26 | 26 | assert_equal({:controller => 'plugin_test/plugin1_admin', :action => 'index'}, Plugin1.admin_url) |
27 | 27 | end |
28 | 28 | |
29 | + should 'returns empty hash for class method extra_blocks by default if no blocks are defined on plugin' do | |
30 | + | |
31 | + class SomePlugin1 < Noosfero::Plugin | |
32 | + end | |
33 | + | |
34 | + assert_equal({}, SomePlugin1.extra_blocks) | |
35 | + end | |
36 | + | |
37 | + should 'returns empty array for instance method extra_blocks by default if no blocks are defined on plugin' do | |
38 | + class Plugin1 < Noosfero::Plugin | |
39 | + def self.extra_blocks | |
40 | + end | |
41 | + end | |
42 | + p = Plugin1.new | |
43 | + assert_equal([], p.extra_blocks) | |
44 | + end | |
45 | + | |
46 | + should 'returns empty array for instance method extra_blocks by default if nil is returned' do | |
47 | + class Plugin1 < Noosfero::Plugin | |
48 | + def self.extra_blocks | |
49 | + nil | |
50 | + end | |
51 | + end | |
52 | + p = Plugin1.new | |
53 | + assert_equal([], p.extra_blocks) | |
54 | + end | |
55 | + | |
56 | + should 'returns the blocks implemented by plugin' do | |
57 | + class CustomBlock1 < Block; end; | |
58 | + class CustomBlock2 < Block; end; | |
59 | + | |
60 | + class Plugin1 < Noosfero::Plugin | |
61 | + def self.extra_blocks | |
62 | + { | |
63 | + CustomBlock1 => {}, | |
64 | + CustomBlock2 => {} | |
65 | + } | |
66 | + end | |
67 | + end | |
68 | + p = Plugin1.new | |
69 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks) | |
70 | + assert_equal([], p.extra_blocks - [CustomBlock1, CustomBlock2]) | |
71 | + end | |
72 | + | |
73 | + should 'returns only person block and non defined types block if type person is specified' do | |
74 | + class CustomBlock1 < Block; end; | |
75 | + class CustomBlock2 < Block; end; | |
76 | + class CustomBlock3 < Block; end; | |
77 | + class CustomBlock4 < Block; end; | |
78 | + class CustomBlock5 < Block; end; | |
79 | + | |
80 | + class Plugin1 < Noosfero::Plugin | |
81 | + def self.extra_blocks | |
82 | + { | |
83 | + CustomBlock1 => {:type => 'person'}, | |
84 | + CustomBlock2 => {}, | |
85 | + CustomBlock3 => {:type => 'enterprise'}, | |
86 | + CustomBlock4 => {:type => 'community'}, | |
87 | + CustomBlock5 => {:type => 'environment'}, | |
88 | + } | |
89 | + end | |
90 | + end | |
91 | + p = Plugin1.new | |
92 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:type => Person)) | |
93 | + assert_equal([], p.extra_blocks(:type => Person) - [CustomBlock1, CustomBlock2]) | |
94 | + end | |
95 | + | |
96 | + should 'returns only community block and non defined types block if type community is specified' do | |
97 | + class CustomBlock1 < Block; end; | |
98 | + class CustomBlock2 < Block; end; | |
99 | + class CustomBlock3 < Block; end; | |
100 | + class CustomBlock4 < Block; end; | |
101 | + class CustomBlock5 < Block; end; | |
102 | + | |
103 | + class Plugin1 < Noosfero::Plugin | |
104 | + def self.extra_blocks | |
105 | + { | |
106 | + CustomBlock1 => {:type => 'community'}, | |
107 | + CustomBlock2 => {}, | |
108 | + CustomBlock3 => {:type => 'person'}, | |
109 | + CustomBlock4 => {:type => 'enterprise'}, | |
110 | + CustomBlock5 => {:type => 'environment'}, | |
111 | + } | |
112 | + end | |
113 | + end | |
114 | + p = Plugin1.new | |
115 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:type => Community)) | |
116 | + assert_equal([], p.extra_blocks(:type => Community) - [CustomBlock1, CustomBlock2]) | |
117 | + end | |
118 | + | |
119 | + should 'returns only enterprise block and non defined types block if type enterprise is specified' do | |
120 | + class CustomBlock1 < Block; end; | |
121 | + class CustomBlock2 < Block; end; | |
122 | + class CustomBlock3 < Block; end; | |
123 | + class CustomBlock4 < Block; end; | |
124 | + class CustomBlock5 < Block; end; | |
125 | + | |
126 | + class Plugin1 < Noosfero::Plugin | |
127 | + def self.extra_blocks | |
128 | + { | |
129 | + CustomBlock1 => {:type => 'enterprise'}, | |
130 | + CustomBlock2 => {}, | |
131 | + CustomBlock3 => {:type => 'person'}, | |
132 | + CustomBlock4 => {:type => 'community'}, | |
133 | + CustomBlock5 => {:type => 'environment'}, | |
134 | + } | |
135 | + end | |
136 | + end | |
137 | + p = Plugin1.new | |
138 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:type => Enterprise)) | |
139 | + assert_equal([], p.extra_blocks(:type => Enterprise) - [CustomBlock1, CustomBlock2]) | |
140 | + end | |
141 | + | |
142 | + should 'returns only environment block and non defined types block if type environment is specified' do | |
143 | + class CustomBlock1 < Block; end; | |
144 | + class CustomBlock2 < Block; end; | |
145 | + class CustomBlock3 < Block; end; | |
146 | + class CustomBlock4 < Block; end; | |
147 | + class CustomBlock5 < Block; end; | |
148 | + | |
149 | + class Plugin1 < Noosfero::Plugin | |
150 | + def self.extra_blocks | |
151 | + { | |
152 | + CustomBlock1 => {:type => 'environment'}, | |
153 | + CustomBlock2 => {}, | |
154 | + CustomBlock3 => {:type => 'enterprise'}, | |
155 | + CustomBlock4 => {:type => 'community'}, | |
156 | + CustomBlock5 => {:type => 'person'}, | |
157 | + } | |
158 | + end | |
159 | + end | |
160 | + p = Plugin1.new | |
161 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:type => Environment)) | |
162 | + assert_equal([], p.extra_blocks(:type => Environment) - [CustomBlock1, CustomBlock2]) | |
163 | + end | |
164 | + | |
165 | + should 'returns array of blocks of a specified type' do | |
166 | + class CustomBlock1 < Block; end; | |
167 | + class CustomBlock2 < Block; end; | |
168 | + class CustomBlock3 < Block; end; | |
169 | + class CustomBlock4 < Block; end; | |
170 | + class CustomBlock5 < Block; end; | |
171 | + | |
172 | + class Plugin1 < Noosfero::Plugin | |
173 | + def self.extra_blocks | |
174 | + { | |
175 | + CustomBlock1 => {:type => 'person'}, | |
176 | + CustomBlock2 => {:type => 'person'}, | |
177 | + CustomBlock3 => {:type => 'environment'}, | |
178 | + CustomBlock4 => {:type => 'enterprise'}, | |
179 | + CustomBlock5 => {:type => 'community'}, | |
180 | + } | |
181 | + end | |
182 | + end | |
183 | + p = Plugin1.new | |
184 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:type => Person)) | |
185 | + assert_equal([], p.extra_blocks(:type => Person) - [CustomBlock1, CustomBlock2]) | |
186 | + end | |
187 | + | |
188 | + should 'returns all blocks without type if no type is specified' do | |
189 | + class CustomBlock1 < Block; end; | |
190 | + class CustomBlock2 < Block; end; | |
191 | + class CustomBlock3 < Block; end; | |
192 | + class CustomBlock4 < Block; end; | |
193 | + class CustomBlock5 < Block; end; | |
194 | + class CustomBlock6 < Block; end; | |
195 | + | |
196 | + class Plugin1 < Noosfero::Plugin | |
197 | + def self.extra_blocks | |
198 | + { | |
199 | + CustomBlock1 => {:type => 'person'}, | |
200 | + CustomBlock2 => {:type => 'environment'}, | |
201 | + CustomBlock3 => {:type => 'enterprise'}, | |
202 | + CustomBlock4 => {:type => 'community'}, | |
203 | + CustomBlock5 => {}, | |
204 | + CustomBlock6 => {}, | |
205 | + } | |
206 | + end | |
207 | + end | |
208 | + p = Plugin1.new | |
209 | + assert_equal([], [CustomBlock5, CustomBlock6] - p.extra_blocks) | |
210 | + assert_equal([], p.extra_blocks - [CustomBlock5, CustomBlock6]) | |
211 | + end | |
212 | + | |
213 | + should 'returns all blocks if type all is specified as parameter' do | |
214 | + class CustomBlock1 < Block; end; | |
215 | + class CustomBlock2 < Block; end; | |
216 | + class CustomBlock3 < Block; end; | |
217 | + class CustomBlock4 < Block; end; | |
218 | + class CustomBlock5 < Block; end; | |
219 | + class CustomBlock6 < Block; end; | |
220 | + | |
221 | + class Plugin1 < Noosfero::Plugin | |
222 | + def self.extra_blocks | |
223 | + { | |
224 | + CustomBlock1 => {:type => 'person'}, | |
225 | + CustomBlock2 => {:type => 'environment'}, | |
226 | + CustomBlock3 => {:type => 'enterprise'}, | |
227 | + CustomBlock4 => {:type => 'community'}, | |
228 | + CustomBlock5 => {}, | |
229 | + CustomBlock6 => {}, | |
230 | + } | |
231 | + end | |
232 | + end | |
233 | + p = Plugin1.new | |
234 | + assert_equal([], [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4, CustomBlock5, CustomBlock6] - p.extra_blocks(:type => :all)) | |
235 | + assert_equal([], p.extra_blocks(:type => :all) - [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4, CustomBlock5, CustomBlock6]) | |
236 | + end | |
237 | + | |
238 | + | |
239 | + should 'returns blocks of specified types' do | |
240 | + class CustomBlock1 < Block; end; | |
241 | + class CustomBlock2 < Block; end; | |
242 | + class CustomBlock3 < Block; end; | |
243 | + class CustomBlock4 < Block; end; | |
244 | + | |
245 | + class Plugin1 < Noosfero::Plugin | |
246 | + def self.extra_blocks | |
247 | + { | |
248 | + CustomBlock1 => {:type => ['person', 'environment']}, | |
249 | + CustomBlock2 => {:type => 'environment'}, | |
250 | + CustomBlock3 => {:type => 'enterprise'}, | |
251 | + CustomBlock4 => {:type => 'community'}, | |
252 | + } | |
253 | + end | |
254 | + end | |
255 | + p = Plugin1.new | |
256 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:type => Environment)) | |
257 | + assert_equal([], p.extra_blocks(:type => Environment) - [CustomBlock1, CustomBlock2]) | |
258 | + end | |
259 | + | |
260 | + should 'returns blocks of with types passed as string or constant' do | |
261 | + class CustomBlock1 < Block; end; | |
262 | + class CustomBlock2 < Block; end; | |
263 | + class CustomBlock3 < Block; end; | |
264 | + class CustomBlock4 < Block; end; | |
265 | + class CustomBlock5 < Block; end; | |
266 | + | |
267 | + class Plugin1 < Noosfero::Plugin | |
268 | + def self.extra_blocks | |
269 | + { | |
270 | + CustomBlock1 => {:type => ['person', 'environment']}, | |
271 | + CustomBlock2 => {:type => 'environment'}, | |
272 | + CustomBlock3 => {:type => Environment}, | |
273 | + CustomBlock4 => {:type => [Environment]}, | |
274 | + CustomBlock5 => {:type => 'person'}, | |
275 | + } | |
276 | + end | |
277 | + end | |
278 | + p = Plugin1.new | |
279 | + assert_equal([], [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4] - p.extra_blocks(:type => Environment)) | |
280 | + assert_equal([], p.extra_blocks(:type => Environment) - [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4]) | |
281 | + end | |
282 | + | |
283 | + should 'through exception if undefined type is specified as parameter' do | |
284 | + class CustomBlock1 < Block; end; | |
285 | + | |
286 | + class Plugin1 < Noosfero::Plugin | |
287 | + def self.extra_blocks | |
288 | + { | |
289 | + CustomBlock1 => {:type => 'undefined_type'}, | |
290 | + } | |
291 | + end | |
292 | + end | |
293 | + p = Plugin1.new | |
294 | + | |
295 | + assert_raise NameError do | |
296 | + p.extra_blocks | |
297 | + end | |
298 | + end | |
299 | + | |
300 | + should 'returns only position 1 block and non defined position block if position 1 is specified' do | |
301 | + class CustomBlock1 < Block; end; | |
302 | + class CustomBlock2 < Block; end; | |
303 | + class CustomBlock3 < Block; end; | |
304 | + class CustomBlock4 < Block; end; | |
305 | + | |
306 | + class Plugin1 < Noosfero::Plugin | |
307 | + def self.extra_blocks | |
308 | + { | |
309 | + CustomBlock1 => {:position => 1}, | |
310 | + CustomBlock2 => {}, | |
311 | + CustomBlock3 => {:position => 3}, | |
312 | + CustomBlock4 => {:position => 2}, | |
313 | + } | |
314 | + end | |
315 | + end | |
316 | + p = Plugin1.new | |
317 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:position => 1)) | |
318 | + assert_equal([], p.extra_blocks(:position => 1) - [CustomBlock1, CustomBlock2]) | |
319 | + end | |
320 | + | |
321 | + should 'returns only position 2 block and non defined position block if position 2 is specified' do | |
322 | + class CustomBlock1 < Block; end; | |
323 | + class CustomBlock2 < Block; end; | |
324 | + class CustomBlock3 < Block; end; | |
325 | + class CustomBlock4 < Block; end; | |
326 | + | |
327 | + class Plugin1 < Noosfero::Plugin | |
328 | + def self.extra_blocks | |
329 | + { | |
330 | + CustomBlock1 => {:position => 2}, | |
331 | + CustomBlock2 => {}, | |
332 | + CustomBlock3 => {:position => 3}, | |
333 | + CustomBlock4 => {:position => 1}, | |
334 | + } | |
335 | + end | |
336 | + end | |
337 | + p = Plugin1.new | |
338 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:position => 2)) | |
339 | + assert_equal([], p.extra_blocks(:position => 2) - [CustomBlock1, CustomBlock2]) | |
340 | + end | |
341 | + | |
342 | + should 'returns only position 3 block and non defined position block if position 3 is specified' do | |
343 | + class CustomBlock1 < Block; end; | |
344 | + class CustomBlock2 < Block; end; | |
345 | + class CustomBlock3 < Block; end; | |
346 | + class CustomBlock4 < Block; end; | |
347 | + | |
348 | + class Plugin1 < Noosfero::Plugin | |
349 | + def self.extra_blocks | |
350 | + { | |
351 | + CustomBlock1 => {:position => 3}, | |
352 | + CustomBlock2 => {}, | |
353 | + CustomBlock3 => {:position => 1}, | |
354 | + CustomBlock4 => {:position => 2}, | |
355 | + } | |
356 | + end | |
357 | + end | |
358 | + p = Plugin1.new | |
359 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:position => 3)) | |
360 | + assert_equal([], p.extra_blocks(:position => 3) - [CustomBlock1, CustomBlock2]) | |
361 | + end | |
362 | + | |
363 | + should 'returns array of blocks of a specified position' do | |
364 | + class CustomBlock1 < Block; end; | |
365 | + class CustomBlock2 < Block; end; | |
366 | + class CustomBlock3 < Block; end; | |
367 | + class CustomBlock4 < Block; end; | |
368 | + | |
369 | + class Plugin1 < Noosfero::Plugin | |
370 | + def self.extra_blocks | |
371 | + { | |
372 | + CustomBlock1 => {:position => 1 }, | |
373 | + CustomBlock2 => {:position => 1 }, | |
374 | + CustomBlock3 => {:position => 2}, | |
375 | + CustomBlock4 => {:position => 3}, | |
376 | + } | |
377 | + end | |
378 | + end | |
379 | + p = Plugin1.new | |
380 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:position => 1)) | |
381 | + assert_equal([], p.extra_blocks(:position => 1) - [CustomBlock1, CustomBlock2]) | |
382 | + end | |
383 | + | |
384 | + should 'returns array of blocks of a specified position wihout any type' do | |
385 | + class CustomBlock1 < Block; end; | |
386 | + class CustomBlock2 < Block; end; | |
387 | + class CustomBlock3 < Block; end; | |
388 | + class CustomBlock4 < Block; end; | |
389 | + class CustomBlock5 < Block; end; | |
390 | + class CustomBlock6 < Block; end; | |
391 | + class CustomBlock7 < Block; end; | |
392 | + class CustomBlock8 < Block; end; | |
393 | + class CustomBlock9 < Block; end; | |
394 | + class CustomBlock10 < Block; end; | |
395 | + | |
396 | + class Plugin1 < Noosfero::Plugin | |
397 | + def self.extra_blocks | |
398 | + { | |
399 | + CustomBlock1 => {:type => Person, :position => 1 }, | |
400 | + CustomBlock2 => {:type => Community, :position => 1 }, | |
401 | + CustomBlock3 => {:type => Enterprise, :position => 1 }, | |
402 | + CustomBlock4 => {:type => Environment, :position => 1 }, | |
403 | + CustomBlock5 => {:position => 1 }, | |
404 | + CustomBlock6 => {:type => Person, :position => [1,2,3] }, | |
405 | + CustomBlock7 => {:type => Community, :position => [1,2,3] }, | |
406 | + CustomBlock8 => {:type => Enterprise, :position => [1,2,3] }, | |
407 | + CustomBlock9 => {:type => Environment, :position => [1,2,3] }, | |
408 | + CustomBlock10 => {:position => [1,2,3] }, | |
409 | + } | |
410 | + end | |
411 | + end | |
412 | + p = Plugin1.new | |
413 | + assert_equal([], [CustomBlock5, CustomBlock10] - p.extra_blocks(:position => 1)) | |
414 | + assert_equal([], p.extra_blocks(:position => 1) - [CustomBlock5, CustomBlock10]) | |
415 | + end | |
416 | + | |
417 | + should 'returns blocks of all position if no position is specified' do | |
418 | + class CustomBlock1 < Block; end; | |
419 | + class CustomBlock2 < Block; end; | |
420 | + class CustomBlock3 < Block; end; | |
421 | + class CustomBlock4 < Block; end; | |
422 | + | |
423 | + class Plugin1 < Noosfero::Plugin | |
424 | + def self.extra_blocks | |
425 | + { | |
426 | + CustomBlock1 => {:position => 1 }, | |
427 | + CustomBlock2 => {:position => 2}, | |
428 | + CustomBlock3 => {:position => 3}, | |
429 | + CustomBlock4 => {}, | |
430 | + } | |
431 | + end | |
432 | + end | |
433 | + p = Plugin1.new | |
434 | + assert_equal([], [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4] - p.extra_blocks) | |
435 | + assert_equal([], p.extra_blocks - [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4]) | |
436 | + end | |
437 | + | |
438 | + should 'returns blocks of specified positions' do | |
439 | + class CustomBlock1 < Block; end; | |
440 | + class CustomBlock2 < Block; end; | |
441 | + class CustomBlock3 < Block; end; | |
442 | + | |
443 | + class Plugin1 < Noosfero::Plugin | |
444 | + def self.extra_blocks | |
445 | + { | |
446 | + CustomBlock1 => {:position => [1, 2]}, | |
447 | + CustomBlock2 => {:position => 2}, | |
448 | + CustomBlock3 => {:position => 3}, | |
449 | + } | |
450 | + end | |
451 | + end | |
452 | + p = Plugin1.new | |
453 | + assert_equal([], [CustomBlock1, CustomBlock2] - p.extra_blocks(:position => 2)) | |
454 | + assert_equal([], p.extra_blocks(:position => 2) - [CustomBlock1, CustomBlock2]) | |
455 | + end | |
456 | + | |
457 | + should 'returns blocks of with positions passed as string or numbers' do | |
458 | + class CustomBlock1 < Block; end; | |
459 | + class CustomBlock2 < Block; end; | |
460 | + class CustomBlock3 < Block; end; | |
461 | + class CustomBlock4 < Block; end; | |
462 | + class CustomBlock5 < Block; end; | |
463 | + | |
464 | + class Plugin1 < Noosfero::Plugin | |
465 | + def self.extra_blocks | |
466 | + { | |
467 | + CustomBlock1 => {:position => [1, '2']}, | |
468 | + CustomBlock2 => {:position => '2'}, | |
469 | + CustomBlock3 => {:position => 2}, | |
470 | + CustomBlock4 => {:position => [2]}, | |
471 | + CustomBlock5 => {:position => '1'}, | |
472 | + } | |
473 | + end | |
474 | + end | |
475 | + p = Plugin1.new | |
476 | + assert_equal([], [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4] - p.extra_blocks(:position => 2)) | |
477 | + assert_equal([], p.extra_blocks(:position => 2) - [CustomBlock1, CustomBlock2, CustomBlock3, CustomBlock4]) | |
478 | + end | |
479 | + | |
480 | + should 'through exception if undefined position is specified as parameter' do | |
481 | + class CustomBlock1 < Block; end; | |
482 | + | |
483 | + class Plugin1 < Noosfero::Plugin | |
484 | + def self.extra_blocks | |
485 | + { | |
486 | + CustomBlock1 => {:type => 'undefined_type'}, | |
487 | + } | |
488 | + end | |
489 | + end | |
490 | + p = Plugin1.new | |
491 | + | |
492 | + assert_raise NameError do | |
493 | + p.extra_blocks | |
494 | + end | |
495 | + end | |
496 | + | |
497 | + | |
498 | + | |
499 | + | |
500 | + | |
29 | 501 | end | ... | ... |