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 | 61 | |
62 | 62 | VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] |
63 | 63 | |
64 | + include Noosfero::Plugin::HotSpot | |
65 | + | |
64 | 66 | def articles_of_parent(parent = nil) |
65 | 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 | 70 | end |
68 | 71 | |
69 | 72 | include ActionController::UrlWriter | ... | ... |
plugins/display_content/test/unit/display_content_block_test.rb
... | ... | @@ -238,6 +238,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
238 | 238 | block.nodes= [a1.id, a2.id, a3.id] |
239 | 239 | box = mock() |
240 | 240 | box.stubs(:owner).returns(profile) |
241 | + box.stubs(:environment).returns(Environment.default) | |
241 | 242 | block.stubs(:box).returns(box) |
242 | 243 | assert_equal [], [a1, a2] - block.articles_of_parent |
243 | 244 | assert_equal [], block.articles_of_parent - [a1, a2] |
... | ... | @@ -253,6 +254,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
253 | 254 | block = DisplayContentBlock.new |
254 | 255 | box = mock() |
255 | 256 | box.stubs(:owner).returns(profile) |
257 | + box.stubs(:environment).returns(Environment.default) | |
256 | 258 | block.stubs(:box).returns(box) |
257 | 259 | assert_equal [], [a3] - block.articles_of_parent(a2) |
258 | 260 | assert_equal [], block.articles_of_parent(a2) - [a3] |
... | ... | @@ -270,6 +272,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
270 | 272 | box = mock() |
271 | 273 | block.stubs(:box).returns(box) |
272 | 274 | box.stubs(:owner).returns(environment) |
275 | + box.stubs(:environment).returns(Environment.default) | |
273 | 276 | environment.stubs(:portal_community).returns(profile) |
274 | 277 | |
275 | 278 | assert_equal [], [a1, a2] - block.articles_of_parent |
... | ... | @@ -288,6 +291,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
288 | 291 | box = mock() |
289 | 292 | block.stubs(:box).returns(box) |
290 | 293 | box.stubs(:owner).returns(environment) |
294 | + box.stubs(:environment).returns(Environment.default) | |
291 | 295 | environment.stubs(:portal_community).returns(profile) |
292 | 296 | |
293 | 297 | assert_equal [], [a3] - block.articles_of_parent(a2) |
... | ... | @@ -301,6 +305,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
301 | 305 | box = mock() |
302 | 306 | block.stubs(:box).returns(box) |
303 | 307 | box.stubs(:owner).returns(environment) |
308 | + box.stubs(:environment).returns(Environment.default) | |
304 | 309 | |
305 | 310 | assert_equal [], block.articles_of_parent() |
306 | 311 | end |
... | ... | @@ -316,6 +321,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
316 | 321 | block = DisplayContentBlock.new |
317 | 322 | box = mock() |
318 | 323 | box.stubs(:owner).returns(profile) |
324 | + box.stubs(:environment).returns(Environment.default) | |
319 | 325 | block.stubs(:box).returns(box) |
320 | 326 | assert_equal [], [a2] - block.articles_of_parent |
321 | 327 | assert_equal [], block.articles_of_parent - [a2] |
... | ... | @@ -334,6 +340,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
334 | 340 | block = DisplayContentBlock.new |
335 | 341 | box = mock() |
336 | 342 | box.stubs(:owner).returns(profile) |
343 | + box.stubs(:environment).returns(Environment.default) | |
337 | 344 | block.stubs(:box).returns(box) |
338 | 345 | assert_equal [a1], block.articles_of_parent |
339 | 346 | end |
... | ... | @@ -526,4 +533,28 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
526 | 533 | assert_equivalent [f1.id, a1.id, a2.id, a3.id], block.nodes |
527 | 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 | 560 | end | ... | ... |