Commit e3612219c538e60df4a428fabfc36ccf782fa281

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 43432446

adapt functional test to new proposal to add blocks

Showing 1 changed file with 63 additions and 104 deletions   Show diff stats
test/functional/profile_design_controller_test.rb
... ... @@ -78,8 +78,29 @@ class ProfileDesignControllerTest < ActionController::TestCase
78 78 ######################################################
79 79 # BEGIN - tests for BoxOrganizerController features
80 80 ######################################################
  81 +
  82 + def test_should_add_block_to_end_of_another_block
  83 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.class.name}", :target => "end-of-box-#{@box2.id}"
  84 + @box2.reload
  85 + block = @box2.blocks.last
  86 +
  87 + assert_equal @b1.class.name, block.class.name
  88 + assert_equal @box2.blocks.size, block.position
  89 + end
  90 +
  91 + def test_should_add_block_to_begin_of_another_block
  92 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.class.name}", :target => "before-block-#{@b4.id}"
  93 +
  94 + previous_position = @b4.position
  95 +
  96 + @b4.box.reload
  97 + @b4.reload
  98 +
  99 + assert_equal @b4.position, previous_position + 1
  100 + end
  101 +
81 102 def test_should_move_block_to_the_end_of_another_block
82   - get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}"
  103 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}"
83 104  
84 105 @b1.reload
85 106 @box2.reload
... ... @@ -91,7 +112,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
91 112  
92 113 def test_should_move_block_to_the_middle_of_another_block
93 114 # block 4 is in box 2
94   - get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}"
  115 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}"
95 116  
96 117 @b1.reload
97 118 @b4.reload
... ... @@ -102,7 +123,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
102 123 end
103 124  
104 125 def test_block_can_be_moved_up
105   - get :move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}"
  126 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}"
106 127  
107 128 @b4.reload
108 129 @b3.reload
... ... @@ -114,7 +135,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
114 135 assert_equal [1,2,3], [@b3,@b4,@b5].map {|item| item.position}
115 136  
116 137 # b3 -> before b5
117   - get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
  138 + get :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
118 139  
119 140 [@b3,@b4,@b5].each do |item|
120 141 item.reload
... ... @@ -123,13 +144,8 @@ class ProfileDesignControllerTest < ActionController::TestCase
123 144 assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position}
124 145 end
125 146  
126   - def test_move_block_should_redirect_when_not_called_via_ajax
127   - get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
128   - assert_redirected_to :action => 'index'
129   - end
130   -
131 147 def test_move_block_should_render_when_called_via_ajax
132   - xml_http_request :get, :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
  148 + xml_http_request :get, :add_or_move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
133 149 assert_template 'move_block'
134 150 end
135 151  
... ... @@ -169,7 +185,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
169 185 end
170 186 end
171 187  
172   - should 'a block plugin with center position add new blocks only in this position' do
  188 + should 'a block plugin add new blocks in any position' do
173 189 class CustomBlock1 < Block; end;
174 190 class CustomBlock2 < Block; end;
175 191 class CustomBlock3 < Block; end;
... ... @@ -197,60 +213,18 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
197 213 end
198 214  
199 215 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
200   - get :add_block, :profile => 'designtestuser'
201   - assert_response :success
202   -
203   - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1)
204   - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2)
205   - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3)
206   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4)
207   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5)
208   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6)
209   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7)
210   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8)
211   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9)
212   - end
213   -
214   - should 'a block plugin with side position add new blocks only in this position' do
215   - class CustomBlock1 < Block; end;
216   - class CustomBlock2 < Block; end;
217   - class CustomBlock3 < Block; end;
218   - class CustomBlock4 < Block; end;
219   - class CustomBlock5 < Block; end;
220   - class CustomBlock6 < Block; end;
221   - class CustomBlock7 < Block; end;
222   - class CustomBlock8 < Block; end;
223   - class CustomBlock9 < Block; end;
224   -
225   - class TestBlockPlugin < Noosfero::Plugin
226   - def self.extra_blocks
227   - {
228   - CustomBlock1 => {:type => Person, :position => [1]},
229   - CustomBlock2 => {:type => Person, :position => 1},
230   - CustomBlock3 => {:type => Person, :position => '1'},
231   - CustomBlock4 => {:type => Person, :position => [2]},
232   - CustomBlock5 => {:type => Person, :position => 2},
233   - CustomBlock6 => {:type => Person, :position => '2'},
234   - CustomBlock7 => {:type => Person, :position => [3]},
235   - CustomBlock8 => {:type => Person, :position => 3},
236   - CustomBlock9 => {:type => Person, :position => '3'},
237   - }
238   - end
239   - end
240   -
241   - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
242   - get :add_block, :profile => 'designtestuser'
  216 + get :index, :profile => 'designtestuser'
243 217 assert_response :success
244 218  
245   - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1)
246   - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2)
247   - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3)
248   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4)
249   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5)
250   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6)
251   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7)
252   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8)
253   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9)
  219 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock1)
  220 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock2)
  221 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock3)
  222 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock4)
  223 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock5)
  224 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock6)
  225 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock7)
  226 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock8)
  227 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock9)
254 228 end
255 229  
256 230 should 'a block plugin cannot be listed for unspecified types' do
... ... @@ -279,17 +253,17 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
279 253 end
280 254  
281 255 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
282   - get :add_block, :profile => 'designtestuser'
  256 + get :index, :profile => 'designtestuser'
283 257 assert_response :success
284 258  
285   - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1)
286   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2)
287   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3)
288   - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4)
289   - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5)
290   - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6)
291   - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7)
292   - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8)
  259 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock1)
  260 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock2)
  261 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock3)
  262 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock4)
  263 + assert @controller.instance_variable_get('@blocks').include?(CustomBlock5)
  264 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock6)
  265 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock7)
  266 + assert !@controller.instance_variable_get('@blocks').include?(CustomBlock8)
293 267 end
294 268  
295 269 should 'not edit main block with never option' do
... ... @@ -331,6 +305,12 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
331 305 assert_equal json_response.include?("/{profile}/"+article3.path), false
332 306 end
333 307  
  308 + should 'display popup for show block information' do
  309 + get :show_block_type_info, :profile => 'designtestuser', :type => ArticleBlock.name
  310 + assert_response :success
  311 + assert_no_tag :tag => 'body'
  312 + end
  313 +
334 314 ######################################################
335 315 # END - tests for BoxOrganizerController features
336 316 ######################################################
... ... @@ -339,27 +319,6 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
339 319 # BEGIN - tests for ProfileDesignController features
340 320 ######################################################
341 321  
342   - should 'display popup for adding a new block' do
343   - get :add_block, :profile => 'designtestuser'
344   - assert_response :success
345   - assert_no_tag :tag => 'body' # e.g. no layout
346   - end
347   -
348   - should 'actually add a new block' do
349   - assert_difference 'Block.count' do
350   - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => RecentDocumentsBlock.name
351   - assert_redirected_to :action => 'index'
352   - end
353   - end
354   -
355   - should 'not allow to create unknown types' do
356   - assert_no_difference 'Block.count' do
357   - assert_raise ArgumentError do
358   - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite"
359   - end
360   - end
361   - end
362   -
363 322 should 'provide edit screen for blocks' do
364 323 get :edit, :profile => 'designtestuser', :id => @b1.id
365 324 assert_template 'edit'
... ... @@ -432,7 +391,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
432 391 person = create_user_with_permission('test_user', 'edit_profile_design', ent)
433 392 login_as(person.user.login)
434 393  
435   - get :add_block, :profile => 'test_ent'
  394 + get :index, :profile => 'test_ent'
436 395  
437 396 assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'}
438 397 end
... ... @@ -448,18 +407,18 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
448 407  
449 408 should 'offer to create blog archives block only if has blog' do
450 409 holder.articles << Blog.new(:name => 'Blog test', :profile => holder)
451   - get :add_block, :profile => 'designtestuser'
452   - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' }
  410 + get :index, :profile => 'designtestuser'
  411 + assert_tag :tag => 'div', :attributes => { :id => 'block-BlogArchivesBlock' }
453 412 end
454 413  
455 414 should 'not offer to create blog archives block if user dont have blog' do
456   - get :add_block, :profile => 'designtestuser'
457   - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' }
  415 + get :index, :profile => 'designtestuser'
  416 + assert_no_tag :tag => 'div', :attributes => { :id => 'block-BlogArchivesBlock' }
458 417 end
459 418  
460 419 should 'offer to create feed reader block' do
461   - get :add_block, :profile => 'designtestuser'
462   - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'FeedReaderBlock' }
  420 + get :index, :profile => 'designtestuser'
  421 + assert_tag :tag => 'div', :attributes => { :id => 'block-FeedReaderBlock' }
463 422 end
464 423  
465 424 should 'be able to edit FeedReaderBlock' do
... ... @@ -571,15 +530,15 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
571 530 should 'allow admins to add RawHTMLBlock' do
572 531 profile.stubs(:is_admin?).with(profile.environment).returns(true)
573 532 @controller.stubs(:user).returns(profile)
574   - get :add_block, :profile => 'designtestuser'
575   - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' }
  533 + get :index, :profile => 'designtestuser'
  534 + assert_tag :tag => 'div', :attributes => { :id => 'block-RawHTMLBlock' }
576 535 end
577 536  
578 537 should 'not allow normal users to add RawHTMLBlock' do
579 538 profile.stubs(:is_admin?).with(profile.environment).returns(false)
580 539 @controller.stubs(:user).returns(profile)
581   - get :add_block, :profile => 'designtestuser'
582   - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' }
  540 + get :index, :profile => 'designtestuser'
  541 + assert_no_tag :tag => 'div', :attributes => { :id => 'block-RawHTMLBlock' }
583 542 end
584 543  
585 544 should 'editing article block displays right selected article' do
... ...