profile_design_controller_test.rb
28.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
require_relative "../test_helper"
require 'profile_design_controller'
class ProfileDesignController; def rescue_action(e) raise e end; end
class ProfileDesignControllerTest < ActionController::TestCase
COMMOM_BLOCKS = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ]
PERSON_BLOCKS = COMMOM_BLOCKS + [ FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ]
PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock]
ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, FeaturedProductsBlock, FansBlock, ProductCategoriesBlock]
ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE = ENTERPRISE_BLOCKS + [ProductsBlock]
attr_reader :holder
def setup
@controller = ProfileDesignController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@profile = @holder = create_user('designtestuser').person
holder.save!
@box1 = Box.new
@box2 = Box.new
@box3 = Box.new
holder.boxes << @box1
holder.boxes << @box2
holder.boxes << @box3
###### BOX 1
@b1 = ArticleBlock.new
@box1.blocks << @b1
@b1.save!
@b2 = Block.new
@box1.blocks << @b2
@b2.save!
###### BOX 2
@b3 = Block.new
@box2.blocks << @b3
@b3.save!
@b4 = MainBlock.new
@box2.blocks << @b4
@b4.save!
@b5 = Block.new
@box2.blocks << @b5
@b5.save!
@b6 = Block.new
@box2.blocks << @b6
@b6.save!
###### BOX 3
@b7 = Block.new
@box3.blocks << @b7
@b7.save!
@b8 = Block.new
@box3.blocks << @b8
@b8.save!
@request.env['HTTP_REFERER'] = '/editor'
holder.blocks(true)
@controller.stubs(:boxes_holder).returns(holder)
login_as 'designtestuser'
@product_category = fast_create(ProductCategory)
end
attr_reader :profile
######################################################
# BEGIN - tests for BoxOrganizerController features
######################################################
def test_should_move_block_to_the_end_of_another_block
get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}"
@b1.reload
@box2.reload
assert_equal @box2, @b1.box
assert @b1.in_list?
assert_equal @box2.blocks.size, @b1.position # i.e. assert @b1.last?
end
def test_should_move_block_to_the_middle_of_another_block
# block 4 is in box 2
get :move_block, :profile => 'designtestuser', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}"
@b1.reload
@b4.reload
assert_equal @b4.box, @b1.box
assert @b1.in_list?
assert_equal @b4.position - 1, @b1.position
end
def test_block_can_be_moved_up
get :move_block, :profile => 'designtestuser', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}"
@b4.reload
@b3.reload
assert_equal @b3.position - 1, @b4.position
end
def test_block_can_be_moved_down
assert_equal [1,2,3], [@b3,@b4,@b5].map {|item| item.position}
# b3 -> before b5
get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
[@b3,@b4,@b5].each do |item|
item.reload
end
assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position}
end
def test_move_block_should_redirect_when_not_called_via_ajax
get :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
assert_redirected_to :action => 'index'
end
def test_move_block_should_render_when_called_via_ajax
xml_http_request :get, :move_block, :profile => 'designtestuser', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}"
assert_template 'move_block'
end
def test_should_be_able_to_move_block_directly_down
post :move_block_down, :profile => 'designtestuser', :id => @b1.id
assert_response :redirect
@b1.reload
@b2.reload
assert_equal [1,2], [@b2,@b1].map {|item| item.position}
end
def test_should_be_able_to_move_block_directly_up
post :move_block_up, :profile => 'designtestuser', :id => @b2.id
assert_response :redirect
@b1.reload
@b2.reload
assert_equal [1,2], [@b2,@b1].map {|item| item.position}
end
def test_should_remove_block
assert_difference 'Block.count', -1 do
post :remove, :profile => 'designtestuser', :id => @b2.id
assert_response :redirect
assert_redirected_to :action => 'index'
end
end
should 'have options to display blocks' do
get :edit, :profile => 'designtestuser', :id => @b1.id
%w[always home_page_only except_home_page never].each do |option|
assert_tag :select, :attributes => {:name => 'block[display]'},
:descendant => {:tag => 'option', :attributes => {:value => option}}
end
end
should 'a block plugin with center position add new blocks only in this position' do
class CustomBlock1 < Block; end;
class CustomBlock2 < Block; end;
class CustomBlock3 < Block; end;
class CustomBlock4 < Block; end;
class CustomBlock5 < Block; end;
class CustomBlock6 < Block; end;
class CustomBlock7 < Block; end;
class CustomBlock8 < Block; end;
class CustomBlock9 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Person, :position => [1]},
CustomBlock2 => {:type => Person, :position => 1},
CustomBlock3 => {:type => Person, :position => '1'},
CustomBlock4 => {:type => Person, :position => [2]},
CustomBlock5 => {:type => Person, :position => 2},
CustomBlock6 => {:type => Person, :position => '2'},
CustomBlock7 => {:type => Person, :position => [3]},
CustomBlock8 => {:type => Person, :position => 3},
CustomBlock9 => {:type => Person, :position => '3'},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
get :add_block, :profile => 'designtestuser'
assert_response :success
assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1)
assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2)
assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9)
end
should 'a block plugin with side position add new blocks only in this position' do
class CustomBlock1 < Block; end;
class CustomBlock2 < Block; end;
class CustomBlock3 < Block; end;
class CustomBlock4 < Block; end;
class CustomBlock5 < Block; end;
class CustomBlock6 < Block; end;
class CustomBlock7 < Block; end;
class CustomBlock8 < Block; end;
class CustomBlock9 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Person, :position => [1]},
CustomBlock2 => {:type => Person, :position => 1},
CustomBlock3 => {:type => Person, :position => '1'},
CustomBlock4 => {:type => Person, :position => [2]},
CustomBlock5 => {:type => Person, :position => 2},
CustomBlock6 => {:type => Person, :position => '2'},
CustomBlock7 => {:type => Person, :position => [3]},
CustomBlock8 => {:type => Person, :position => 3},
CustomBlock9 => {:type => Person, :position => '3'},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
get :add_block, :profile => 'designtestuser'
assert_response :success
assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1)
assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2)
assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9)
end
should 'a block plugin cannot be listed for unspecified types' do
class CustomBlock1 < Block; end;
class CustomBlock2 < Block; end;
class CustomBlock3 < Block; end;
class CustomBlock4 < Block; end;
class CustomBlock5 < Block; end;
class CustomBlock6 < Block; end;
class CustomBlock7 < Block; end;
class CustomBlock8 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Person, :position => 1},
CustomBlock2 => {:type => Community, :position => 1},
CustomBlock3 => {:type => Enterprise, :position => 1},
CustomBlock4 => {:type => Environment, :position => 1},
CustomBlock5 => {:type => Person, :position => 2},
CustomBlock6 => {:type => Community, :position => 3},
CustomBlock7 => {:type => Enterprise, :position => 2},
CustomBlock8 => {:type => Environment, :position => 3},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
get :add_block, :profile => 'designtestuser'
assert_response :success
assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3)
assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4)
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5)
assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6)
assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7)
assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8)
end
should 'not edit main block with never option' do
get :edit, :profile => 'designtestuser', :id => @b4.id
assert_no_tag :select, :attributes => {:name => 'block[display]'},
:descendant => {:tag => 'option', :attributes => {:value => 'never'}}
end
should 'not edit main block with home_page_only option' do
get :edit, :profile => 'designtestuser', :id => @b4.id
assert_no_tag :select, :attributes => {:name => 'block[display]'},
:descendant => {:tag => 'option', :attributes => {:value => 'home_page_only'}}
end
should 'edit main block with always option' do
get :edit, :profile => 'designtestuser', :id => @b4.id
assert_tag :select, :attributes => {:name => 'block[display]'},
:descendant => {:tag => 'option', :attributes => {:value => 'always'}}
end
should 'edit main block with except_home_page option' do
get :edit, :profile => 'designtestuser', :id => @b4.id
assert_tag :select, :attributes => {:name=> 'block[display]'},
:descendant => {:tag => 'option', :attributes => {:value => 'except_home_page'}}
end
should 'return a list of paths related to the words used in the query search' do
article1 = fast_create(Article, :profile_id => @profile.id, :name => "Some thing")
article2 = fast_create(Article, :profile_id => @profile.id, :name => "Some article")
article3 = fast_create(Article, :profile_id => @profile.id, :name => "Not an article")
xhr :get, :search_autocomplete, :profile => 'designtestuser' , :query => 'Some'
json_response = ActiveSupport::JSON.decode(@response.body)
assert_response :success
assert_equal json_response.include?("/{profile}/"+article1.path), true
assert_equal json_response.include?("/{profile}/"+article2.path), true
assert_equal json_response.include?("/{profile}/"+article3.path), false
end
######################################################
# END - tests for BoxOrganizerController features
######################################################
######################################################
# BEGIN - tests for ProfileDesignController features
######################################################
should 'display popup for adding a new block' do
get :add_block, :profile => 'designtestuser'
assert_response :success
assert_no_tag :tag => 'body' # e.g. no layout
end
should 'actually add a new block' do
assert_difference 'Block.count' do
post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => RecentDocumentsBlock.name
assert_redirected_to :action => 'index'
end
end
should 'not allow to create unknown types' do
assert_no_difference 'Block.count' do
assert_raise ArgumentError do
post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite"
end
end
end
should 'provide edit screen for blocks' do
get :edit, :profile => 'designtestuser', :id => @b1.id
assert_template 'edit'
assert_no_tag :tag => 'body' # e.g. no layout
end
should 'be able to save a block' do
post :save, :profile => 'designtestuser', :id => @b1.id, :block => { :article_id => 999 }
assert_redirected_to :action => 'index'
@b1.reload
assert_equal 999, @b1.article_id
end
should 'be able to edit ProductsBlock' do
block = ProductsBlock.new
enterprise = fast_create(Enterprise, :name => "test", :identifier => 'testenterprise')
enterprise.boxes << Box.new
p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category)
p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category)
enterprise.boxes.first.blocks << block
enterprise.add_admin(holder)
enterprise.blocks(true)
@controller.stubs(:boxes_holder).returns(enterprise)
login_as('designtestuser')
get :edit, :profile => 'testenterprise', :id => block.id
assert_response :success
assert_tag :tag => 'input', :attributes => { :name => "block[product_ids][]", :value => p1.id.to_s }
assert_tag :tag => 'input', :attributes => { :name => "block[product_ids][]", :value => p2.id.to_s }
end
should 'be able to save ProductsBlock' do
block = ProductsBlock.new
enterprise = fast_create(Enterprise, :name => "test", :identifier => 'testenterprise')
enterprise.boxes << Box.new
p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category)
p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category)
enterprise.boxes.first.blocks << block
enterprise.add_admin(holder)
enterprise.blocks(true)
@controller.stubs(:boxes_holder).returns(enterprise)
login_as('designtestuser')
post :save, :profile => 'testenterprise', :id => block.id, :block => { :product_ids => [p1.id.to_s, p2.id.to_s ] }
assert_response :redirect
block.reload
assert_equal [p1.id, p2.id], block.product_ids
end
should 'display back to control panel button' do
get :index, :profile => 'designtestuser'
assert_tag :tag => 'a', :content => 'Back to control panel'
end
should 'not allow products block if environment do not let' do
env = Environment.default
env.disable('products_for_enterprises')
env.save!
ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id)
person = create_user_with_permission('test_user', 'edit_profile_design', ent)
login_as(person.user.login)
get :add_block, :profile => 'test_ent'
assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'}
end
should 'create back link to profile control panel' do
p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile')
login_as(create_user_with_permission('test_user','edit_profile_design',p).identifier )
get :index, :profile => p.identifier
assert_tag :tag => 'a', :attributes => {:href => '/myprofile/test_profile'}
end
should 'offer to create blog archives block only if has blog' do
holder.articles << Blog.new(:name => 'Blog test', :profile => holder)
get :add_block, :profile => 'designtestuser'
assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' }
end
should 'not offer to create blog archives block if user dont have blog' do
get :add_block, :profile => 'designtestuser'
assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' }
end
should 'offer to create feed reader block' do
get :add_block, :profile => 'designtestuser'
assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'FeedReaderBlock' }
end
should 'be able to edit FeedReaderBlock' do
@box1.blocks << FeedReaderBlock.new(:address => 'feed address')
holder.blocks(true)
get :edit, :profile => 'designtestuser', :id => @box1.blocks[-1].id
assert_response :success
assert_tag :tag => 'input', :attributes => { :name => "block[address]", :value => 'feed address' }
assert_tag :tag => 'select', :attributes => { :name => "block[limit]" }
end
should 'be able to save FeedReaderBlock configurations' do
@box1.blocks << FeedReaderBlock.new(:address => 'feed address')
holder.blocks(true)
block = @box1.blocks.last
post :save, :profile => 'designtestuser', :id => block.id, :block => {:address => 'new feed address', :limit => '20'}
block.reload
assert_equal 'new feed address', block.address
assert_equal 20, block.limit
end
should 'require login' do
logout
get :index, :profile => profile.identifier
assert_redirected_to :controller => 'account', :action => 'login'
end
should 'not show sideboxes when render access denied' do
another_profile = create_user('bobmarley').person
get :index, :profile => another_profile.identifier
assert_tag :tag => 'div', :attributes => {:class => 'no-boxes'}
assert_tag :tag => 'div', :attributes => {:id => 'access-denied'}
end
should 'the person blocks are all available' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(true)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(false)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
assert_equal PERSON_BLOCKS, @controller.available_blocks
end
should 'the person with blog blocks are all available' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(true)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(false)
profile.stubs(:has_blog?).returns(true)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_BLOG
end
should 'the enterprise blocks are all available' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(false)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(true)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(true)
environment.stubs(:enabled?).with('products_for_enterprises').returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS
end
should 'the enterprise with products for enterprise enable blocks are all available' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(false)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(true)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(true)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
assert_equal [], @controller.available_blocks - ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE
end
should 'allow admins to add RawHTMLBlock' do
profile.stubs(:is_admin?).with(profile.environment).returns(true)
@controller.stubs(:user).returns(profile)
get :add_block, :profile => 'designtestuser'
assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' }
end
should 'not allow normal users to add RawHTMLBlock' do
profile.stubs(:is_admin?).with(profile.environment).returns(false)
@controller.stubs(:user).returns(profile)
get :add_block, :profile => 'designtestuser'
assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' }
end
should 'editing article block displays right selected article' do
selected_article = fast_create(Article, :profile_id => profile.id)
ArticleBlock.any_instance.stubs(:article).returns(selected_article)
get :edit, :profile => 'designtestuser', :id => @b1.id
assert_tag :tag => 'option', :attributes => {:value => selected_article.id, :selected => 'selected'}
end
should 'the block plugin add a new block' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(true)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(false)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
class CustomBlock1 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
assert @controller.available_blocks.include?(CustomBlock1)
end
should 'a person block plugin add new blocks for person profile' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(true)
profile.stubs(:community?).returns(false)
profile.stubs(:enterprise?).returns(false)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
class CustomBlock1 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Person},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
assert @controller.available_blocks.include?(CustomBlock1)
end
should 'a community block plugin add new blocks for community profile' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(false)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(false)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
class CustomBlock1 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Community},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
assert @controller.available_blocks.include?(CustomBlock1)
end
should 'a enterprise block plugin add new blocks for enterprise profile' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(false)
profile.stubs(:community?).returns(false)
profile.stubs(:enterprise?).returns(true)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
class CustomBlock1 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Enterprise},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
assert @controller.available_blocks.include?(CustomBlock1)
end
should 'an environment block plugin not add new blocks for enterprise, person or community profiles' do
profile = mock
profile.stubs(:has_members?).returns(false)
profile.stubs(:person?).returns(true)
profile.stubs(:community?).returns(true)
profile.stubs(:enterprise?).returns(true)
profile.stubs(:has_blog?).returns(false)
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
class CustomBlock1 < Block; end;
class TestBlockPlugin < Noosfero::Plugin
def self.extra_blocks
{
CustomBlock1 => {:type => Environment},
}
end
end
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new])
assert !@controller.available_blocks.include?(CustomBlock1)
end
should 'clone a block' do
block = create(ProfileImageBlock, :box => profile.boxes.first)
assert_difference 'ProfileImageBlock.count', 1 do
post :clone_block, :id => block.id, :profile => profile.identifier
assert_response :redirect
end
end
test 'should forbid POST to save for uneditable blocks' do
block = profile.blocks.last
block.edit_modes = "none"
block.save!
post :save, id: block.id, profile: profile.identifier
assert_response :forbidden
end
test 'should forbid POST to move_block for fixed blocks' do
block = profile.blocks.last
block.move_modes = "none"
block.save!
post :move_block, id: block.id, profile: profile.identifier, target: "end-of-box-#{@box3.id}"
assert_response :forbidden
end
should 'guarantee main block is always visible to everybody' do
get :edit, :profile => 'designtestuser', :id => @b4.id
%w[logged not_logged followers].each do |option|
assert_no_tag :select, :attributes => {:name => 'block[display_user]'},
:descendant => {:tag => 'option', :attributes => {:value => option}}
end
end
end