Commit 46095aa0e2b0e02d11d6e7899c527b79311071a7
1 parent
7e9327d0
Exists in
master
and in
23 other branches
Show only text article and folders on tree content
Showing
2 changed files
with
93 additions
and
1 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
| @@ -18,6 +18,7 @@ class DisplayContentBlock < Block | @@ -18,6 +18,7 @@ class DisplayContentBlock < Block | ||
| 18 | self.holder.articles.find(params.keys).map do |article| | 18 | self.holder.articles.find(params.keys).map do |article| |
| 19 | if article.folder? | 19 | if article.folder? |
| 20 | articles = articles + article.children | 20 | articles = articles + article.children |
| 21 | + parent_articles << article.id | ||
| 21 | else | 22 | else |
| 22 | articles<< article | 23 | articles<< article |
| 23 | end | 24 | end |
| @@ -27,9 +28,11 @@ class DisplayContentBlock < Block | @@ -27,9 +28,11 @@ class DisplayContentBlock < Block | ||
| 27 | self.nodes = articles.map{|a| a.id if a.is_a?(TextArticle) }.compact | 28 | self.nodes = articles.map{|a| a.id if a.is_a?(TextArticle) }.compact |
| 28 | end | 29 | end |
| 29 | 30 | ||
| 31 | + VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] | ||
| 32 | + | ||
| 30 | def articles_of_parent(parent = nil) | 33 | def articles_of_parent(parent = nil) |
| 31 | return [] if self.holder.nil? | 34 | return [] if self.holder.nil? |
| 32 | - holder.articles.find(:all, :conditions => {:parent_id => parent.nil? ? nil : parent}) | 35 | + holder.articles.find(:all, :conditions => {:type => VALID_CONTENT, :parent_id => (parent.nil? ? nil : parent)}) |
| 33 | end | 36 | end |
| 34 | 37 | ||
| 35 | include ActionController::UrlWriter | 38 | include ActionController::UrlWriter |
plugins/display_content/test/unit/display_content_block_test.rb
| 1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
| 2 | class DisplayContentBlockTest < ActiveSupport::TestCase | 2 | class DisplayContentBlockTest < ActiveSupport::TestCase |
| 3 | 3 | ||
| 4 | + INVALID_KIND_OF_ARTICLE = [EnterpriseHomepage, Event, RssFeed, UploadedFile, Gallery] | ||
| 5 | + VALID_KIND_OF_ARTICLE = [RawHTMLArticle, TextArticle, TextileArticle, TinyMceArticle, Folder, Blog, Forum] | ||
| 6 | + | ||
| 4 | should 'describe itself' do | 7 | should 'describe itself' do |
| 5 | assert_not_equal Block.description, DisplayContentBlock.description | 8 | assert_not_equal Block.description, DisplayContentBlock.description |
| 6 | end | 9 | end |
| @@ -376,6 +379,57 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -376,6 +379,57 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
| 376 | assert_equal [], block.parent_nodes - [f1.id, f2.id, f3.id, f4.id, f5.id] | 379 | assert_equal [], block.parent_nodes - [f1.id, f2.id, f3.id, f4.id, f5.id] |
| 377 | end | 380 | end |
| 378 | 381 | ||
| 382 | + should "save the folder in parent_nodes variable if it was checked" do | ||
| 383 | + profile = create_user('testuser').person | ||
| 384 | + Article.delete_all | ||
| 385 | + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) | ||
| 386 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | ||
| 387 | + a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f1.id) | ||
| 388 | + | ||
| 389 | + checked_articles= {f1.id => 1} | ||
| 390 | + | ||
| 391 | + block = DisplayContentBlock.new | ||
| 392 | + block.stubs(:holder).returns(profile) | ||
| 393 | + block.checked_nodes= checked_articles | ||
| 394 | + | ||
| 395 | + assert_equal [], [f1.id] - block.parent_nodes | ||
| 396 | + assert_equal [], block.parent_nodes - [f1.id] | ||
| 397 | + end | ||
| 398 | + | ||
| 399 | + should "save the blog in parent_nodes variable if it was checked" do | ||
| 400 | + profile = create_user('testuser').person | ||
| 401 | + Article.delete_all | ||
| 402 | + b1 = fast_create(Blog, :name => 'test folder 1', :profile_id => profile.id) | ||
| 403 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => b1.id) | ||
| 404 | + a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => b1.id) | ||
| 405 | + | ||
| 406 | + checked_articles= {b1.id => 1} | ||
| 407 | + | ||
| 408 | + block = DisplayContentBlock.new | ||
| 409 | + block.stubs(:holder).returns(profile) | ||
| 410 | + block.checked_nodes= checked_articles | ||
| 411 | + | ||
| 412 | + assert_equal [], [b1.id] - block.parent_nodes | ||
| 413 | + assert_equal [], block.parent_nodes - [b1.id] | ||
| 414 | + end | ||
| 415 | + | ||
| 416 | + should "save the forum in parent_nodes variable if it was checked" do | ||
| 417 | + profile = create_user('testuser').person | ||
| 418 | + Article.delete_all | ||
| 419 | + f1 = fast_create(Forum, :name => 'test folder 1', :profile_id => profile.id) | ||
| 420 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) | ||
| 421 | + a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f1.id) | ||
| 422 | + | ||
| 423 | + checked_articles= {f1.id => 1} | ||
| 424 | + | ||
| 425 | + block = DisplayContentBlock.new | ||
| 426 | + block.stubs(:holder).returns(profile) | ||
| 427 | + block.checked_nodes= checked_articles | ||
| 428 | + | ||
| 429 | + assert_equal [], [f1.id] - block.parent_nodes | ||
| 430 | + assert_equal [], block.parent_nodes - [f1.id] | ||
| 431 | + end | ||
| 432 | + | ||
| 379 | should "return all root articles from profile" do | 433 | should "return all root articles from profile" do |
| 380 | profile = create_user('testuser').person | 434 | profile = create_user('testuser').person |
| 381 | Article.delete_all | 435 | Article.delete_all |
| @@ -454,6 +508,41 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -454,6 +508,41 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
| 454 | assert_equal [], block.articles_of_parent() | 508 | assert_equal [], block.articles_of_parent() |
| 455 | end | 509 | end |
| 456 | 510 | ||
| 511 | + INVALID_KIND_OF_ARTICLE.map do |invalid_article| | ||
| 512 | + | ||
| 513 | + define_method "test_should_not_return_#{invalid_article.name}_articles_in_articles_of_parent_method" do | ||
| 514 | + profile = create_user('testuser').person | ||
| 515 | + Article.delete_all | ||
| 516 | + a1 = fast_create(invalid_article, :name => 'test article 1', :profile_id => profile.id) | ||
| 517 | + a2 = fast_create(VALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id) | ||
| 518 | + | ||
| 519 | + block = DisplayContentBlock.new | ||
| 520 | + box = mock() | ||
| 521 | + box.stubs(:owner).returns(profile) | ||
| 522 | + block.stubs(:box).returns(box) | ||
| 523 | + assert_equal [], [a2] - block.articles_of_parent | ||
| 524 | + assert_equal [], block.articles_of_parent - [a2] | ||
| 525 | + end | ||
| 526 | + | ||
| 527 | + end | ||
| 528 | + | ||
| 529 | + VALID_KIND_OF_ARTICLE.map do |valid_article| | ||
| 530 | + | ||
| 531 | + define_method "test_should_return_#{valid_article.name}_articles_in_articles_of_parent_method" do | ||
| 532 | + profile = create_user('testuser').person | ||
| 533 | + Article.delete_all | ||
| 534 | + a1 = fast_create(valid_article, :name => 'test article 1', :profile_id => profile.id) | ||
| 535 | + a2 = fast_create(INVALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id) | ||
| 536 | + | ||
| 537 | + block = DisplayContentBlock.new | ||
| 538 | + box = mock() | ||
| 539 | + box.stubs(:owner).returns(profile) | ||
| 540 | + block.stubs(:box).returns(box) | ||
| 541 | + assert_equal [a1], block.articles_of_parent | ||
| 542 | + end | ||
| 543 | + | ||
| 544 | + end | ||
| 545 | + | ||
| 457 | should 'list links for all articles title defined in nodes' do | 546 | should 'list links for all articles title defined in nodes' do |
| 458 | profile = create_user('testuser').person | 547 | profile = create_user('testuser').person |
| 459 | Article.delete_all | 548 | Article.delete_all |