Commit 08976954531281c358da512d788b4b53e86c88ab
1 parent
adc4f4fd
Exists in
master
and in
29 other branches
display_content: allow contents defined on plugins to be selectable
(ActionItem2993)
Showing
2 changed files
with
35 additions
and
1 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
@@ -61,9 +61,12 @@ class DisplayContentBlock < Block | @@ -61,9 +61,12 @@ class DisplayContentBlock < Block | ||
61 | 61 | ||
62 | VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] | 62 | VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] |
63 | 63 | ||
64 | + include Noosfero::Plugin::HotSpot | ||
65 | + | ||
64 | def articles_of_parent(parent = nil) | 66 | def articles_of_parent(parent = nil) |
65 | return [] if self.holder.nil? | 67 | return [] if self.holder.nil? |
66 | - holder.articles.find(:all, :conditions => {:type => VALID_CONTENT, :parent_id => (parent.nil? ? nil : parent)}) | 68 | + types = VALID_CONTENT + plugins.dispatch(:content_types).map(&:name) |
69 | + holder.articles.find(:all, :conditions => {:type => types, :parent_id => (parent.nil? ? nil : parent)}) | ||
67 | end | 70 | end |
68 | 71 | ||
69 | include ActionController::UrlWriter | 72 | include ActionController::UrlWriter |
plugins/display_content/test/unit/display_content_block_test.rb
@@ -238,6 +238,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -238,6 +238,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
238 | block.nodes= [a1.id, a2.id, a3.id] | 238 | block.nodes= [a1.id, a2.id, a3.id] |
239 | box = mock() | 239 | box = mock() |
240 | box.stubs(:owner).returns(profile) | 240 | box.stubs(:owner).returns(profile) |
241 | + box.stubs(:environment).returns(Environment.default) | ||
241 | block.stubs(:box).returns(box) | 242 | block.stubs(:box).returns(box) |
242 | assert_equal [], [a1, a2] - block.articles_of_parent | 243 | assert_equal [], [a1, a2] - block.articles_of_parent |
243 | assert_equal [], block.articles_of_parent - [a1, a2] | 244 | assert_equal [], block.articles_of_parent - [a1, a2] |
@@ -253,6 +254,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -253,6 +254,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
253 | block = DisplayContentBlock.new | 254 | block = DisplayContentBlock.new |
254 | box = mock() | 255 | box = mock() |
255 | box.stubs(:owner).returns(profile) | 256 | box.stubs(:owner).returns(profile) |
257 | + box.stubs(:environment).returns(Environment.default) | ||
256 | block.stubs(:box).returns(box) | 258 | block.stubs(:box).returns(box) |
257 | assert_equal [], [a3] - block.articles_of_parent(a2) | 259 | assert_equal [], [a3] - block.articles_of_parent(a2) |
258 | assert_equal [], block.articles_of_parent(a2) - [a3] | 260 | assert_equal [], block.articles_of_parent(a2) - [a3] |
@@ -270,6 +272,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -270,6 +272,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
270 | box = mock() | 272 | box = mock() |
271 | block.stubs(:box).returns(box) | 273 | block.stubs(:box).returns(box) |
272 | box.stubs(:owner).returns(environment) | 274 | box.stubs(:owner).returns(environment) |
275 | + box.stubs(:environment).returns(Environment.default) | ||
273 | environment.stubs(:portal_community).returns(profile) | 276 | environment.stubs(:portal_community).returns(profile) |
274 | 277 | ||
275 | assert_equal [], [a1, a2] - block.articles_of_parent | 278 | assert_equal [], [a1, a2] - block.articles_of_parent |
@@ -288,6 +291,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -288,6 +291,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
288 | box = mock() | 291 | box = mock() |
289 | block.stubs(:box).returns(box) | 292 | block.stubs(:box).returns(box) |
290 | box.stubs(:owner).returns(environment) | 293 | box.stubs(:owner).returns(environment) |
294 | + box.stubs(:environment).returns(Environment.default) | ||
291 | environment.stubs(:portal_community).returns(profile) | 295 | environment.stubs(:portal_community).returns(profile) |
292 | 296 | ||
293 | assert_equal [], [a3] - block.articles_of_parent(a2) | 297 | assert_equal [], [a3] - block.articles_of_parent(a2) |
@@ -301,6 +305,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -301,6 +305,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
301 | box = mock() | 305 | box = mock() |
302 | block.stubs(:box).returns(box) | 306 | block.stubs(:box).returns(box) |
303 | box.stubs(:owner).returns(environment) | 307 | box.stubs(:owner).returns(environment) |
308 | + box.stubs(:environment).returns(Environment.default) | ||
304 | 309 | ||
305 | assert_equal [], block.articles_of_parent() | 310 | assert_equal [], block.articles_of_parent() |
306 | end | 311 | end |
@@ -316,6 +321,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -316,6 +321,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
316 | block = DisplayContentBlock.new | 321 | block = DisplayContentBlock.new |
317 | box = mock() | 322 | box = mock() |
318 | box.stubs(:owner).returns(profile) | 323 | box.stubs(:owner).returns(profile) |
324 | + box.stubs(:environment).returns(Environment.default) | ||
319 | block.stubs(:box).returns(box) | 325 | block.stubs(:box).returns(box) |
320 | assert_equal [], [a2] - block.articles_of_parent | 326 | assert_equal [], [a2] - block.articles_of_parent |
321 | assert_equal [], block.articles_of_parent - [a2] | 327 | assert_equal [], block.articles_of_parent - [a2] |
@@ -334,6 +340,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -334,6 +340,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
334 | block = DisplayContentBlock.new | 340 | block = DisplayContentBlock.new |
335 | box = mock() | 341 | box = mock() |
336 | box.stubs(:owner).returns(profile) | 342 | box.stubs(:owner).returns(profile) |
343 | + box.stubs(:environment).returns(Environment.default) | ||
337 | block.stubs(:box).returns(box) | 344 | block.stubs(:box).returns(box) |
338 | assert_equal [a1], block.articles_of_parent | 345 | assert_equal [a1], block.articles_of_parent |
339 | end | 346 | end |
@@ -526,4 +533,28 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -526,4 +533,28 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
526 | assert_equivalent [f1.id, a1.id, a2.id, a3.id], block.nodes | 533 | assert_equivalent [f1.id, a1.id, a2.id, a3.id], block.nodes |
527 | end | 534 | end |
528 | 535 | ||
536 | + should "test should return plugins articles in articles of parent method" do | ||
537 | + class PluginArticle < Article; end | ||
538 | + | ||
539 | + class Plugin1 < Noosfero::Plugin | ||
540 | + def content_types | ||
541 | + [PluginArticle] | ||
542 | + end | ||
543 | + end | ||
544 | + | ||
545 | + profile = create_user('testuser').person | ||
546 | + Article.delete_all | ||
547 | + a1 = fast_create(PluginArticle, :name => 'test article 1', :profile_id => profile.id) | ||
548 | + | ||
549 | + env = fast_create(Environment) | ||
550 | + env.enable_plugin(Plugin1) | ||
551 | + | ||
552 | + block = DisplayContentBlock.new | ||
553 | + box = mock() | ||
554 | + box.stubs(:owner).returns(profile) | ||
555 | + box.stubs(:environment).returns(env) | ||
556 | + block.stubs(:box).returns(box) | ||
557 | + assert_equal [a1], block.articles_of_parent | ||
558 | + end | ||
559 | + | ||
529 | end | 560 | end |