diff --git a/plugins/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb index 20fc876..024953f 100644 --- a/plugins/display_content/lib/display_content_block.rb +++ b/plugins/display_content/lib/display_content_block.rb @@ -20,14 +20,9 @@ class DisplayContentBlock < Block settings_items :nodes, :type => Array, :default => [] settings_items :sections, :type => Array, -#FIXME make test for values -#Refactoring section stuff :default => [{:value => 'publish_date', :checked => true}, {:value => 'title', :checked => true}, - {:value => 'abstract', :checked => true}, - {:value => 'body', :checked => false}, - {:value => 'image', :checked => false}, - {:value => 'tags', :checked => false}] + {:value => 'abstract', :checked => true}] settings_items :display_folder_children, :type => :boolean, :default => true settings_items :types, :type => Array @@ -50,7 +45,16 @@ class DisplayContentBlock < Block }[section] || section end - #FIXME make this test copy of Context Content + alias :orig_sections :sections + def sections + available_sections = AVAILABLE_SECTIONS + available_sections = available_sections - orig_sections.map{|e|e[:value]} + sections = available_sections.map do |section| + {:value => section, :checked => false} + end + sections + orig_sections + end + def available_content_types @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) checked_types = types.map {|t| t.constantize} @@ -62,17 +66,14 @@ class DisplayContentBlock < Block available_content_types.first(first_types_count) end - #FIXME make this test copy of Context Content def more_content_types available_content_types.drop(first_types_count) end - #FIXME make this test copy of Context Content def first_types_count [2, types.length].max end - #FIXME make this test copy of Context Content def types=(new_types) settings[:types] = new_types.reject(&:blank?) end diff --git a/plugins/display_content/test/unit/display_content_block_test.rb b/plugins/display_content/test/unit/display_content_block_test.rb index dfeb173..0291571 100644 --- a/plugins/display_content/test/unit/display_content_block_test.rb +++ b/plugins/display_content/test/unit/display_content_block_test.rb @@ -472,8 +472,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - block.sections = [{:value => 'body', :checked => true}] - section = block.sections.first + section = {:value => 'body', :checked => true} + block.sections = [section] assert block.display_section?(section) end @@ -557,4 +557,76 @@ class DisplayContentBlockTest < ActiveSupport::TestCase assert_equal [a1], block.articles_of_parent end + should "the section display all available sections" do + block = DisplayContentBlock.new + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]} + end + + should "the section display all available sections if the section value has only one key" do + block = DisplayContentBlock.new + block.sections = [{:value => 'abstract', :checked => true}] + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]} + end + + should 'return available content types with checked types first' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + + block.types = ['TinyMceArticle', 'Folder'] + assert_equal [TinyMceArticle, Folder, UploadedFile, Event, TextileArticle, RawHTMLArticle, Blog, Forum, Gallery, RssFeed], block.available_content_types + end + + should 'return available content types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + block.types = [] + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed], block.available_content_types + end + + should 'return first 2 content types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + assert_equal 2, block.first_content_types.length + end + + should 'return all but first 2 content types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + assert_equal block.available_content_types.length - 2, block.more_content_types.length + end + + should 'return 2 as default value for first_types_count' do + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + assert_equal 2, block.first_types_count + end + + should 'return types length if it has more than 2 selected types' do + block = DisplayContentBlock.create! + block.types = ['UploadedFile', 'Event', 'Folder'] + assert_equal 3, block.first_types_count + end + + should 'return selected types at first_content_types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['UploadedFile', 'Event', 'Folder'] + assert_equal [UploadedFile, Event, Folder], block.first_content_types + assert_equal block.available_content_types - [UploadedFile, Event, Folder], block.more_content_types + end + + should 'include plugin content at available content types' do + block = DisplayContentBlock.create! + class SomePluginContent;end + class SomePlugin; def content_types; SomePluginContent end end + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) + + block.types = [] + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], block.available_content_types + end + end -- libgit2 0.21.2