Commit 2004e8196ec71e0526ea4b81b3721549632345d2
1 parent
09069e2e
Exists in
master
and in
27 other branches
adding unit tests for choose content types for display
Showing
2 changed files
with
85 additions
and
12 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
| ... | ... | @@ -20,14 +20,9 @@ class DisplayContentBlock < Block |
| 20 | 20 | settings_items :nodes, :type => Array, :default => [] |
| 21 | 21 | settings_items :sections, |
| 22 | 22 | :type => Array, |
| 23 | -#FIXME make test for values | |
| 24 | -#Refactoring section stuff | |
| 25 | 23 | :default => [{:value => 'publish_date', :checked => true}, |
| 26 | 24 | {:value => 'title', :checked => true}, |
| 27 | - {:value => 'abstract', :checked => true}, | |
| 28 | - {:value => 'body', :checked => false}, | |
| 29 | - {:value => 'image', :checked => false}, | |
| 30 | - {:value => 'tags', :checked => false}] | |
| 25 | + {:value => 'abstract', :checked => true}] | |
| 31 | 26 | settings_items :display_folder_children, :type => :boolean, :default => true |
| 32 | 27 | settings_items :types, :type => Array |
| 33 | 28 | |
| ... | ... | @@ -50,7 +45,16 @@ class DisplayContentBlock < Block |
| 50 | 45 | }[section] || section |
| 51 | 46 | end |
| 52 | 47 | |
| 53 | - #FIXME make this test copy of Context Content | |
| 48 | + alias :orig_sections :sections | |
| 49 | + def sections | |
| 50 | + available_sections = AVAILABLE_SECTIONS | |
| 51 | + available_sections = available_sections - orig_sections.map{|e|e[:value]} | |
| 52 | + sections = available_sections.map do |section| | |
| 53 | + {:value => section, :checked => false} | |
| 54 | + end | |
| 55 | + sections + orig_sections | |
| 56 | + end | |
| 57 | + | |
| 54 | 58 | def available_content_types |
| 55 | 59 | @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) |
| 56 | 60 | checked_types = types.map {|t| t.constantize} |
| ... | ... | @@ -62,17 +66,14 @@ class DisplayContentBlock < Block |
| 62 | 66 | available_content_types.first(first_types_count) |
| 63 | 67 | end |
| 64 | 68 | |
| 65 | - #FIXME make this test copy of Context Content | |
| 66 | 69 | def more_content_types |
| 67 | 70 | available_content_types.drop(first_types_count) |
| 68 | 71 | end |
| 69 | 72 | |
| 70 | - #FIXME make this test copy of Context Content | |
| 71 | 73 | def first_types_count |
| 72 | 74 | [2, types.length].max |
| 73 | 75 | end |
| 74 | 76 | |
| 75 | - #FIXME make this test copy of Context Content | |
| 76 | 77 | def types=(new_types) |
| 77 | 78 | settings[:types] = new_types.reject(&:blank?) |
| 78 | 79 | end | ... | ... |
plugins/display_content/test/unit/display_content_block_test.rb
| ... | ... | @@ -472,8 +472,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 472 | 472 | |
| 473 | 473 | block = DisplayContentBlock.new |
| 474 | 474 | |
| 475 | - block.sections = [{:value => 'body', :checked => true}] | |
| 476 | - section = block.sections.first | |
| 475 | + section = {:value => 'body', :checked => true} | |
| 476 | + block.sections = [section] | |
| 477 | 477 | |
| 478 | 478 | assert block.display_section?(section) |
| 479 | 479 | end |
| ... | ... | @@ -557,4 +557,76 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
| 557 | 557 | assert_equal [a1], block.articles_of_parent |
| 558 | 558 | end |
| 559 | 559 | |
| 560 | + should "the section display all available sections" do | |
| 561 | + block = DisplayContentBlock.new | |
| 562 | + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]} | |
| 563 | + end | |
| 564 | + | |
| 565 | + should "the section display all available sections if the section value has only one key" do | |
| 566 | + block = DisplayContentBlock.new | |
| 567 | + block.sections = [{:value => 'abstract', :checked => true}] | |
| 568 | + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]} | |
| 569 | + end | |
| 570 | + | |
| 571 | + should 'return available content types with checked types first' do | |
| 572 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
| 573 | + block = DisplayContentBlock.create! | |
| 574 | + block.types = ['TinyMceArticle'] | |
| 575 | + | |
| 576 | + block.types = ['TinyMceArticle', 'Folder'] | |
| 577 | + assert_equal [TinyMceArticle, Folder, UploadedFile, Event, TextileArticle, RawHTMLArticle, Blog, Forum, Gallery, RssFeed], block.available_content_types | |
| 578 | + end | |
| 579 | + | |
| 580 | + should 'return available content types' do | |
| 581 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
| 582 | + block = DisplayContentBlock.create! | |
| 583 | + block.types = ['TinyMceArticle'] | |
| 584 | + block.types = [] | |
| 585 | + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed], block.available_content_types | |
| 586 | + end | |
| 587 | + | |
| 588 | + should 'return first 2 content types' do | |
| 589 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
| 590 | + block = DisplayContentBlock.create! | |
| 591 | + block.types = ['TinyMceArticle'] | |
| 592 | + assert_equal 2, block.first_content_types.length | |
| 593 | + end | |
| 594 | + | |
| 595 | + should 'return all but first 2 content types' do | |
| 596 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
| 597 | + block = DisplayContentBlock.create! | |
| 598 | + block.types = ['TinyMceArticle'] | |
| 599 | + assert_equal block.available_content_types.length - 2, block.more_content_types.length | |
| 600 | + end | |
| 601 | + | |
| 602 | + should 'return 2 as default value for first_types_count' do | |
| 603 | + block = DisplayContentBlock.create! | |
| 604 | + block.types = ['TinyMceArticle'] | |
| 605 | + assert_equal 2, block.first_types_count | |
| 606 | + end | |
| 607 | + | |
| 608 | + should 'return types length if it has more than 2 selected types' do | |
| 609 | + block = DisplayContentBlock.create! | |
| 610 | + block.types = ['UploadedFile', 'Event', 'Folder'] | |
| 611 | + assert_equal 3, block.first_types_count | |
| 612 | + end | |
| 613 | + | |
| 614 | + should 'return selected types at first_content_types' do | |
| 615 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
| 616 | + block = DisplayContentBlock.create! | |
| 617 | + block.types = ['UploadedFile', 'Event', 'Folder'] | |
| 618 | + assert_equal [UploadedFile, Event, Folder], block.first_content_types | |
| 619 | + assert_equal block.available_content_types - [UploadedFile, Event, Folder], block.more_content_types | |
| 620 | + end | |
| 621 | + | |
| 622 | + should 'include plugin content at available content types' do | |
| 623 | + block = DisplayContentBlock.create! | |
| 624 | + class SomePluginContent;end | |
| 625 | + class SomePlugin; def content_types; SomePluginContent end end | |
| 626 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) | |
| 627 | + | |
| 628 | + block.types = [] | |
| 629 | + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], block.available_content_types | |
| 630 | + end | |
| 631 | + | |
| 560 | 632 | end | ... | ... |