Commit af3c320b6dbddeda28cf2c4e8e6454c46a8d3d45
1 parent
18ea9ebe
Exists in
master
and in
29 other branches
adding hotspots to make possible add other blocks
Showing
7 changed files
with
930 additions
and
2 deletions
Show diff stats
app/controllers/admin/environment_design_controller.rb
@@ -4,6 +4,7 @@ class EnvironmentDesignController < BoxOrganizerController | @@ -4,6 +4,7 @@ class EnvironmentDesignController < BoxOrganizerController | ||
4 | 4 | ||
5 | def available_blocks | 5 | def available_blocks |
6 | @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock ] | 6 | @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock ] |
7 | + @available_blocks = @available_blocks + plugins.dispatch(:extra_blocks, :type => Environment) | ||
7 | end | 8 | end |
8 | 9 | ||
9 | end | 10 | end |
app/controllers/box_organizer_controller.rb
@@ -68,8 +68,8 @@ class BoxOrganizerController < ApplicationController | @@ -68,8 +68,8 @@ class BoxOrganizerController < ApplicationController | ||
68 | raise ArgumentError.new("Type %s is not allowed. Go away." % type) | 68 | raise ArgumentError.new("Type %s is not allowed. Go away." % type) |
69 | end | 69 | end |
70 | else | 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 => :all, :position => 1) |
72 | + @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => :all, :position => [2,3]) | ||
73 | @boxes = boxes_holder.boxes | 73 | @boxes = boxes_holder.boxes |
74 | render :action => 'add_block', :layout => false | 74 | render :action => 'add_block', :layout => false |
75 | end | 75 | end |
app/controllers/my_profile/profile_design_controller.rb
@@ -7,6 +7,8 @@ class ProfileDesignController < BoxOrganizerController | @@ -7,6 +7,8 @@ class ProfileDesignController < BoxOrganizerController | ||
7 | def available_blocks | 7 | def available_blocks |
8 | blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] | 8 | blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] |
9 | 9 | ||
10 | + blocks = blocks + plugins.dispatch(:extra_blocks) | ||
11 | + | ||
10 | # blocks exclusive for organizations | 12 | # blocks exclusive for organizations |
11 | if profile.has_members? | 13 | if profile.has_members? |
12 | blocks << MembersBlock | 14 | blocks << MembersBlock |
@@ -18,6 +20,12 @@ class ProfileDesignController < BoxOrganizerController | @@ -18,6 +20,12 @@ class ProfileDesignController < BoxOrganizerController | ||
18 | blocks << FavoriteEnterprisesBlock | 20 | blocks << FavoriteEnterprisesBlock |
19 | blocks << CommunitiesBlock | 21 | blocks << CommunitiesBlock |
20 | blocks << EnterprisesBlock | 22 | blocks << EnterprisesBlock |
23 | + blocks = blocks + plugins.dispatch(:extra_blocks, :type => Person) | ||
24 | + end | ||
25 | + | ||
26 | + # blocks exclusive to person | ||
27 | + if profile.community? | ||
28 | + blocks = blocks + plugins.dispatch(:extra_blocks, :type => Community) | ||
21 | end | 29 | end |
22 | 30 | ||
23 | # blocks exclusive for enterprises | 31 | # blocks exclusive for enterprises |
@@ -26,6 +34,7 @@ class ProfileDesignController < BoxOrganizerController | @@ -26,6 +34,7 @@ class ProfileDesignController < BoxOrganizerController | ||
26 | blocks << HighlightsBlock | 34 | blocks << HighlightsBlock |
27 | blocks << FeaturedProductsBlock | 35 | blocks << FeaturedProductsBlock |
28 | blocks << FansBlock | 36 | blocks << FansBlock |
37 | + blocks = blocks + plugins.dispatch(:extra_blocks, :type => Enterprise) | ||
29 | end | 38 | end |
30 | 39 | ||
31 | # product block exclusive for enterprises in environments that permits it | 40 | # product block exclusive for enterprises in environments that permits it |
lib/noosfero/plugin.rb
@@ -97,6 +97,35 @@ class Noosfero::Plugin | @@ -97,6 +97,35 @@ class Noosfero::Plugin | ||
97 | ERB.new(File.read("#{views_path}/#{file_path}")).result(binding) | 97 | ERB.new(File.read("#{views_path}/#{file_path}")).result(binding) |
98 | end | 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 | # Here the developer may specify the events to which the plugins can | 129 | # Here the developer may specify the events to which the plugins can |
101 | # register and must return true or false. The default value must be false. | 130 | # register and must return true or false. The default value must be false. |
102 | 131 | ||
@@ -351,6 +380,60 @@ class Noosfero::Plugin | @@ -351,6 +380,60 @@ class Noosfero::Plugin | ||
351 | nil | 380 | nil |
352 | end | 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: Could 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 | def method_missing(method, *args, &block) | 437 | def method_missing(method, *args, &block) |
355 | # This is a generic hotspot for all controllers on Noosfero. | 438 | # This is a generic hotspot for all controllers on Noosfero. |
356 | # If any plugin wants to define filters to run on any controller, the name of | 439 | # If any plugin wants to define filters to run on any controller, the name of |
test/functional/environment_design_controller_test.rb
@@ -12,6 +12,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -12,6 +12,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
12 | @controller = EnvironmentDesignController.new | 12 | @controller = EnvironmentDesignController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
14 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
15 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
15 | end | 16 | end |
16 | 17 | ||
17 | def test_local_files_reference | 18 | def test_local_files_reference |
@@ -192,4 +193,131 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -192,4 +193,131 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
192 | assert_response :success | 193 | assert_response :success |
193 | assert_template 'add_block' | 194 | assert_template 'add_block' |
194 | end | 195 | end |
196 | + | ||
197 | + should 'a environment block plugin add new blocks for environments' do | ||
198 | + class CustomBlock1 < Block; end; | ||
199 | + | ||
200 | + class TestBlockPlugin < Noosfero::Plugin | ||
201 | + def self.extra_blocks | ||
202 | + { | ||
203 | + CustomBlock1 => {:type => Environment}, | ||
204 | + } | ||
205 | + end | ||
206 | + end | ||
207 | + | ||
208 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
209 | + assert @controller.available_blocks.include?(CustomBlock1) | ||
210 | + end | ||
211 | + | ||
212 | + should 'a person, enterprise and community blocks plugins do not add new blocks for environments' do | ||
213 | + class CustomBlock1 < Block; end; | ||
214 | + class CustomBlock2 < Block; end; | ||
215 | + class CustomBlock3 < Block; end; | ||
216 | + class CustomBlock4 < Block; end; | ||
217 | + | ||
218 | + class TestBlockPlugin < Noosfero::Plugin | ||
219 | + def self.extra_blocks | ||
220 | + { | ||
221 | + CustomBlock1 => {:type => Environment}, | ||
222 | + CustomBlock2 => {:type => Enterprise}, | ||
223 | + CustomBlock3 => {:type => Community}, | ||
224 | + CustomBlock4 => {:type => Person}, | ||
225 | + } | ||
226 | + end | ||
227 | + end | ||
228 | + | ||
229 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
230 | + assert @controller.available_blocks.include?(CustomBlock1) | ||
231 | + assert !@controller.available_blocks.include?(CustomBlock2) | ||
232 | + assert !@controller.available_blocks.include?(CustomBlock3) | ||
233 | + assert !@controller.available_blocks.include?(CustomBlock4) | ||
234 | + end | ||
235 | + | ||
236 | + should 'a block plugin with center position add new blocks only in this position' do | ||
237 | + class CustomBlock1 < Block; end; | ||
238 | + class CustomBlock2 < Block; end; | ||
239 | + class CustomBlock3 < Block; end; | ||
240 | + class CustomBlock4 < Block; end; | ||
241 | + class CustomBlock5 < Block; end; | ||
242 | + class CustomBlock6 < Block; end; | ||
243 | + class CustomBlock7 < Block; end; | ||
244 | + class CustomBlock8 < Block; end; | ||
245 | + class CustomBlock9 < Block; end; | ||
246 | + | ||
247 | + class TestBlockPlugin < Noosfero::Plugin | ||
248 | + def self.extra_blocks | ||
249 | + { | ||
250 | + CustomBlock1 => {:type => Person, :position => [1]}, | ||
251 | + CustomBlock2 => {:type => Enterprise, :position => 1}, | ||
252 | + CustomBlock3 => {:type => Community, :position => '1'}, | ||
253 | + CustomBlock4 => {:type => Person, :position => [2]}, | ||
254 | + CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
255 | + CustomBlock6 => {:type => Community, :position => '2'}, | ||
256 | + CustomBlock7 => {:type => Person, :position => [3]}, | ||
257 | + CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
258 | + CustomBlock9 => {:type => Community, :position => '3'}, | ||
259 | + } | ||
260 | + end | ||
261 | + end | ||
262 | + | ||
263 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
264 | + login_as(create_admin_user(Environment.default)) | ||
265 | + get :add_block | ||
266 | + | ||
267 | + assert_response :success | ||
268 | + | ||
269 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | ||
270 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | ||
271 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | ||
272 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | ||
273 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) | ||
274 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) | ||
275 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) | ||
276 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) | ||
277 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) | ||
278 | + end | ||
279 | + | ||
280 | + should 'a block plugin with side position add new blocks only in this position' do | ||
281 | + class CustomBlock1 < Block; end; | ||
282 | + class CustomBlock2 < Block; end; | ||
283 | + class CustomBlock3 < Block; end; | ||
284 | + class CustomBlock4 < Block; end; | ||
285 | + class CustomBlock5 < Block; end; | ||
286 | + class CustomBlock6 < Block; end; | ||
287 | + class CustomBlock7 < Block; end; | ||
288 | + class CustomBlock8 < Block; end; | ||
289 | + class CustomBlock9 < Block; end; | ||
290 | + | ||
291 | + class TestBlockPlugin < Noosfero::Plugin | ||
292 | + def self.extra_blocks | ||
293 | + { | ||
294 | + CustomBlock1 => {:type => Person, :position => [1]}, | ||
295 | + CustomBlock2 => {:type => Enterprise, :position => 1}, | ||
296 | + CustomBlock3 => {:type => Community, :position => '1'}, | ||
297 | + CustomBlock4 => {:type => Person, :position => [2]}, | ||
298 | + CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
299 | + CustomBlock6 => {:type => Community, :position => '2'}, | ||
300 | + CustomBlock7 => {:type => Person, :position => [3]}, | ||
301 | + CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
302 | + CustomBlock9 => {:type => Community, :position => '3'}, | ||
303 | + } | ||
304 | + end | ||
305 | + end | ||
306 | + | ||
307 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
308 | + login_as(create_admin_user(Environment.default)) | ||
309 | + get :add_block | ||
310 | + assert_response :success | ||
311 | + | ||
312 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) | ||
313 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) | ||
314 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) | ||
315 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) | ||
316 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | ||
317 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | ||
318 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | ||
319 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | ||
320 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | ||
321 | + end | ||
322 | + | ||
195 | end | 323 | end |
test/functional/profile_design_controller_test.rb
@@ -177,6 +177,91 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -177,6 +177,91 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
177 | end | 177 | end |
178 | end | 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 => Enterprise, :position => 1}, | ||
196 | + CustomBlock3 => {:type => Community, :position => '1'}, | ||
197 | + CustomBlock4 => {:type => Person, :position => [2]}, | ||
198 | + CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
199 | + CustomBlock6 => {:type => Community, :position => '2'}, | ||
200 | + CustomBlock7 => {:type => Person, :position => [3]}, | ||
201 | + CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
202 | + CustomBlock9 => {:type => Community, :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 => Enterprise, :position => 1}, | ||
238 | + CustomBlock3 => {:type => Community, :position => '1'}, | ||
239 | + CustomBlock4 => {:type => Person, :position => [2]}, | ||
240 | + CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
241 | + CustomBlock6 => {:type => Community, :position => '2'}, | ||
242 | + CustomBlock7 => {:type => Person, :position => [3]}, | ||
243 | + CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
244 | + CustomBlock9 => {:type => Community, :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 | + | ||
180 | ###################################################### | 265 | ###################################################### |
181 | # END - tests for BoxOrganizerController features | 266 | # END - tests for BoxOrganizerController features |
182 | ###################################################### | 267 | ###################################################### |
@@ -349,6 +434,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -349,6 +434,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
349 | profile = mock | 434 | profile = mock |
350 | profile.stubs(:has_members?).returns(false) | 435 | profile.stubs(:has_members?).returns(false) |
351 | profile.stubs(:person?).returns(true) | 436 | profile.stubs(:person?).returns(true) |
437 | + profile.stubs(:community?).returns(true) | ||
352 | profile.stubs(:enterprise?).returns(false) | 438 | profile.stubs(:enterprise?).returns(false) |
353 | profile.stubs(:has_blog?).returns(false) | 439 | profile.stubs(:has_blog?).returns(false) |
354 | profile.stubs(:is_admin?).with(anything).returns(false) | 440 | profile.stubs(:is_admin?).with(anything).returns(false) |
@@ -357,6 +443,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -357,6 +443,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
357 | environment.stubs(:enabled?).returns(false) | 443 | environment.stubs(:enabled?).returns(false) |
358 | @controller.stubs(:profile).returns(profile) | 444 | @controller.stubs(:profile).returns(profile) |
359 | @controller.stubs(:user).returns(profile) | 445 | @controller.stubs(:user).returns(profile) |
446 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
360 | assert_equal PERSON_BLOCKS, @controller.available_blocks | 447 | assert_equal PERSON_BLOCKS, @controller.available_blocks |
361 | end | 448 | end |
362 | 449 | ||
@@ -364,6 +451,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -364,6 +451,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
364 | profile = mock | 451 | profile = mock |
365 | profile.stubs(:has_members?).returns(true) | 452 | profile.stubs(:has_members?).returns(true) |
366 | profile.stubs(:person?).returns(true) | 453 | profile.stubs(:person?).returns(true) |
454 | + profile.stubs(:community?).returns(true) | ||
367 | profile.stubs(:enterprise?).returns(false) | 455 | profile.stubs(:enterprise?).returns(false) |
368 | profile.stubs(:has_blog?).returns(false) | 456 | profile.stubs(:has_blog?).returns(false) |
369 | profile.stubs(:is_admin?).with(anything).returns(false) | 457 | profile.stubs(:is_admin?).with(anything).returns(false) |
@@ -372,6 +460,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -372,6 +460,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
372 | environment.stubs(:enabled?).returns(false) | 460 | environment.stubs(:enabled?).returns(false) |
373 | @controller.stubs(:profile).returns(profile) | 461 | @controller.stubs(:profile).returns(profile) |
374 | @controller.stubs(:user).returns(profile) | 462 | @controller.stubs(:user).returns(profile) |
463 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
375 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS | 464 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS |
376 | end | 465 | end |
377 | 466 | ||
@@ -379,6 +468,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -379,6 +468,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
379 | profile = mock | 468 | profile = mock |
380 | profile.stubs(:has_members?).returns(false) | 469 | profile.stubs(:has_members?).returns(false) |
381 | profile.stubs(:person?).returns(true) | 470 | profile.stubs(:person?).returns(true) |
471 | + profile.stubs(:community?).returns(true) | ||
382 | profile.stubs(:enterprise?).returns(false) | 472 | profile.stubs(:enterprise?).returns(false) |
383 | profile.stubs(:has_blog?).returns(true) | 473 | profile.stubs(:has_blog?).returns(true) |
384 | profile.stubs(:is_admin?).with(anything).returns(false) | 474 | profile.stubs(:is_admin?).with(anything).returns(false) |
@@ -387,6 +477,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -387,6 +477,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
387 | environment.stubs(:enabled?).returns(false) | 477 | environment.stubs(:enabled?).returns(false) |
388 | @controller.stubs(:profile).returns(profile) | 478 | @controller.stubs(:profile).returns(profile) |
389 | @controller.stubs(:user).returns(profile) | 479 | @controller.stubs(:user).returns(profile) |
480 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
390 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG | 481 | assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG |
391 | end | 482 | end |
392 | 483 | ||
@@ -394,6 +485,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -394,6 +485,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
394 | profile = mock | 485 | profile = mock |
395 | profile.stubs(:has_members?).returns(false) | 486 | profile.stubs(:has_members?).returns(false) |
396 | profile.stubs(:person?).returns(false) | 487 | profile.stubs(:person?).returns(false) |
488 | + profile.stubs(:community?).returns(true) | ||
397 | profile.stubs(:enterprise?).returns(true) | 489 | profile.stubs(:enterprise?).returns(true) |
398 | profile.stubs(:has_blog?).returns(false) | 490 | profile.stubs(:has_blog?).returns(false) |
399 | profile.stubs(:is_admin?).with(anything).returns(false) | 491 | profile.stubs(:is_admin?).with(anything).returns(false) |
@@ -402,6 +494,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -402,6 +494,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
402 | environment.stubs(:enabled?).returns(true) | 494 | environment.stubs(:enabled?).returns(true) |
403 | @controller.stubs(:profile).returns(profile) | 495 | @controller.stubs(:profile).returns(profile) |
404 | @controller.stubs(:user).returns(profile) | 496 | @controller.stubs(:user).returns(profile) |
497 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
405 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS | 498 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS |
406 | end | 499 | end |
407 | 500 | ||
@@ -409,6 +502,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -409,6 +502,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
409 | profile = mock | 502 | profile = mock |
410 | profile.stubs(:has_members?).returns(false) | 503 | profile.stubs(:has_members?).returns(false) |
411 | profile.stubs(:person?).returns(false) | 504 | profile.stubs(:person?).returns(false) |
505 | + profile.stubs(:community?).returns(true) | ||
412 | profile.stubs(:enterprise?).returns(true) | 506 | profile.stubs(:enterprise?).returns(true) |
413 | profile.stubs(:has_blog?).returns(false) | 507 | profile.stubs(:has_blog?).returns(false) |
414 | profile.stubs(:is_admin?).with(anything).returns(false) | 508 | profile.stubs(:is_admin?).with(anything).returns(false) |
@@ -417,6 +511,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -417,6 +511,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
417 | environment.stubs(:enabled?).returns(false) | 511 | environment.stubs(:enabled?).returns(false) |
418 | @controller.stubs(:profile).returns(profile) | 512 | @controller.stubs(:profile).returns(profile) |
419 | @controller.stubs(:user).returns(profile) | 513 | @controller.stubs(:user).returns(profile) |
514 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | ||
420 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE | 515 | assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE |
421 | end | 516 | end |
422 | 517 | ||
@@ -441,4 +536,144 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -441,4 +536,144 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
441 | assert_tag :tag => 'option', :attributes => {:value => selected_article.id, :selected => 'selected'} | 536 | assert_tag :tag => 'option', :attributes => {:value => selected_article.id, :selected => 'selected'} |
442 | end | 537 | end |
443 | 538 | ||
539 | + should 'the block plugin add a new block' do | ||
540 | + profile = mock | ||
541 | + profile.stubs(:has_members?).returns(false) | ||
542 | + profile.stubs(:person?).returns(true) | ||
543 | + profile.stubs(:community?).returns(true) | ||
544 | + profile.stubs(:enterprise?).returns(false) | ||
545 | + profile.stubs(:has_blog?).returns(false) | ||
546 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
547 | + environment = mock | ||
548 | + profile.stubs(:environment).returns(environment) | ||
549 | + environment.stubs(:enabled?).returns(false) | ||
550 | + @controller.stubs(:profile).returns(profile) | ||
551 | + @controller.stubs(:user).returns(profile) | ||
552 | + | ||
553 | + class CustomBlock1 < Block; end; | ||
554 | + | ||
555 | + class TestBlockPlugin < Noosfero::Plugin | ||
556 | + def self.extra_blocks | ||
557 | + { | ||
558 | + CustomBlock1 => {}, | ||
559 | + } | ||
560 | + end | ||
561 | + end | ||
562 | + | ||
563 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
564 | + assert @controller.available_blocks.include?(CustomBlock1) | ||
565 | + end | ||
566 | + | ||
567 | + should 'a person block plugin add new blocks for person profile' do | ||
568 | + profile = mock | ||
569 | + profile.stubs(:has_members?).returns(false) | ||
570 | + profile.stubs(:person?).returns(true) | ||
571 | + profile.stubs(:community?).returns(false) | ||
572 | + profile.stubs(:enterprise?).returns(false) | ||
573 | + profile.stubs(:has_blog?).returns(false) | ||
574 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
575 | + environment = mock | ||
576 | + profile.stubs(:environment).returns(environment) | ||
577 | + environment.stubs(:enabled?).returns(false) | ||
578 | + @controller.stubs(:profile).returns(profile) | ||
579 | + @controller.stubs(:user).returns(profile) | ||
580 | + | ||
581 | + class CustomBlock1 < Block; end; | ||
582 | + | ||
583 | + class TestBlockPlugin < Noosfero::Plugin | ||
584 | + def self.extra_blocks | ||
585 | + { | ||
586 | + CustomBlock1 => {:type => Person}, | ||
587 | + } | ||
588 | + end | ||
589 | + end | ||
590 | + | ||
591 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
592 | + assert @controller.available_blocks.include?(CustomBlock1) | ||
593 | + end | ||
594 | + | ||
595 | + should 'a community block plugin add new blocks for community profile' do | ||
596 | + profile = mock | ||
597 | + profile.stubs(:has_members?).returns(false) | ||
598 | + profile.stubs(:person?).returns(false) | ||
599 | + profile.stubs(:community?).returns(true) | ||
600 | + profile.stubs(:enterprise?).returns(false) | ||
601 | + profile.stubs(:has_blog?).returns(false) | ||
602 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
603 | + environment = mock | ||
604 | + profile.stubs(:environment).returns(environment) | ||
605 | + environment.stubs(:enabled?).returns(false) | ||
606 | + @controller.stubs(:profile).returns(profile) | ||
607 | + @controller.stubs(:user).returns(profile) | ||
608 | + | ||
609 | + class CustomBlock1 < Block; end; | ||
610 | + | ||
611 | + class TestBlockPlugin < Noosfero::Plugin | ||
612 | + def self.extra_blocks | ||
613 | + { | ||
614 | + CustomBlock1 => {:type => Community}, | ||
615 | + } | ||
616 | + end | ||
617 | + end | ||
618 | + | ||
619 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
620 | + assert @controller.available_blocks.include?(CustomBlock1) | ||
621 | + end | ||
622 | + | ||
623 | + should 'a enterprise block plugin add new blocks for enterprise profile' do | ||
624 | + profile = mock | ||
625 | + profile.stubs(:has_members?).returns(false) | ||
626 | + profile.stubs(:person?).returns(false) | ||
627 | + profile.stubs(:community?).returns(false) | ||
628 | + profile.stubs(:enterprise?).returns(true) | ||
629 | + profile.stubs(:has_blog?).returns(false) | ||
630 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
631 | + environment = mock | ||
632 | + profile.stubs(:environment).returns(environment) | ||
633 | + environment.stubs(:enabled?).returns(false) | ||
634 | + @controller.stubs(:profile).returns(profile) | ||
635 | + @controller.stubs(:user).returns(profile) | ||
636 | + | ||
637 | + class CustomBlock1 < Block; end; | ||
638 | + | ||
639 | + class TestBlockPlugin < Noosfero::Plugin | ||
640 | + def self.extra_blocks | ||
641 | + { | ||
642 | + CustomBlock1 => {:type => Enterprise}, | ||
643 | + } | ||
644 | + end | ||
645 | + end | ||
646 | + | ||
647 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
648 | + assert @controller.available_blocks.include?(CustomBlock1) | ||
649 | + end | ||
650 | + | ||
651 | + should 'an environment block plugin not add new blocks for enterprise, person or community profiles' do | ||
652 | + profile = mock | ||
653 | + profile.stubs(:has_members?).returns(false) | ||
654 | + profile.stubs(:person?).returns(true) | ||
655 | + profile.stubs(:community?).returns(true) | ||
656 | + profile.stubs(:enterprise?).returns(true) | ||
657 | + profile.stubs(:has_blog?).returns(false) | ||
658 | + profile.stubs(:is_admin?).with(anything).returns(false) | ||
659 | + environment = mock | ||
660 | + profile.stubs(:environment).returns(environment) | ||
661 | + environment.stubs(:enabled?).returns(false) | ||
662 | + @controller.stubs(:profile).returns(profile) | ||
663 | + @controller.stubs(:user).returns(profile) | ||
664 | + | ||
665 | + class CustomBlock1 < Block; end; | ||
666 | + | ||
667 | + class TestBlockPlugin < Noosfero::Plugin | ||
668 | + def self.extra_blocks | ||
669 | + { | ||
670 | + CustomBlock1 => {:type => Environment}, | ||
671 | + } | ||
672 | + end | ||
673 | + end | ||
674 | + | ||
675 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
676 | + assert !@controller.available_blocks.include?(CustomBlock1) | ||
677 | + end | ||
678 | + | ||
444 | end | 679 | end |
test/unit/plugin_test.rb
@@ -26,4 +26,476 @@ class PluginTest < ActiveSupport::TestCase | @@ -26,4 +26,476 @@ class PluginTest < ActiveSupport::TestCase | ||
26 | assert_equal({:controller => 'plugin_test/plugin1_admin', :action => 'index'}, Plugin1.admin_url) | 26 | assert_equal({:controller => 'plugin_test/plugin1_admin', :action => 'index'}, Plugin1.admin_url) |
27 | end | 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 | end | 501 | end |