diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-09-16 15:24:35 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-09-16 15:24:35 +0000 |
commit | 747e4ecd3a981e5d48d3028f5cd870b130eb65b4 (patch) | |
tree | 8f8bdf941521d4647db1ebcb0e9c450427ecbd63 /test/unit | |
parent | ca4f2c59b6479ad088aa87e6173bcdd5c7c66629 (diff) | |
download | redmine-747e4ecd3a981e5d48d3028f5cd870b130eb65b4.tar.gz redmine-747e4ecd3a981e5d48d3028f5cd870b130eb65b4.zip |
Adds a "depth" option to the child_pages macro (#10789).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10401 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/macros_test.rb | 18 | ||||
-rw-r--r-- | test/unit/wiki_page_test.rb | 18 |
2 files changed, 33 insertions, 3 deletions
diff --git a/test/unit/lib/redmine/wiki_formatting/macros_test.rb b/test/unit/lib/redmine/wiki_formatting/macros_test.rb index 75376652a..53665d017 100644 --- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -182,7 +182,8 @@ class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase def test_macro_child_pages expected = "<p><ul class=\"pages-hierarchy\">\n" + - "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a></li>\n" + + "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a>\n" + + "<ul class=\"pages-hierarchy\">\n<li><a href=\"/projects/ecookbook/wiki/Child_1_1\">Child 1 1</a></li>\n</ul>\n</li>\n" + "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" + "</ul>\n</p>" @@ -196,11 +197,12 @@ class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content) end - def test_macro_child_pages_with_option + def test_macro_child_pages_with_parent_option expected = "<p><ul class=\"pages-hierarchy\">\n" + "<li><a href=\"/projects/ecookbook/wiki/Another_page\">Another page</a>\n" + "<ul class=\"pages-hierarchy\">\n" + - "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a></li>\n" + + "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a>\n" + + "<ul class=\"pages-hierarchy\">\n<li><a href=\"/projects/ecookbook/wiki/Child_1_1\">Child 1 1</a></li>\n</ul>\n</li>\n" + "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" + "</ul>\n</li>\n</ul>\n</p>" @@ -214,6 +216,16 @@ class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content) end + def test_macro_child_pages_with_depth_option + expected = "<p><ul class=\"pages-hierarchy\">\n" + + "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a></li>\n" + + "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" + + "</ul>\n</p>" + + @project = Project.find(1) + assert_equal expected, textilizable("{{child_pages(depth=1)}}", :object => WikiPage.find(2).content) + end + def test_macro_child_pages_without_wiki_page_should_fail assert_match /can be called from wiki pages only/, textilizable("{{child_pages}}") end diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index 11341286b..2a606a782 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -131,4 +131,22 @@ class WikiPageTest < ActiveSupport::TestCase assert_equal Time.gm(2007, 3, 6, 23, 10, 51), page.content.updated_on assert_equal page.content.updated_on, page.updated_on end + + def test_descendants + page = WikiPage.create!(:wiki => @wiki, :title => 'Parent') + child1 = WikiPage.create!(:wiki => @wiki, :title => 'Child1', :parent => page) + child11 = WikiPage.create!(:wiki => @wiki, :title => 'Child11', :parent => child1) + child111 = WikiPage.create!(:wiki => @wiki, :title => 'Child111', :parent => child11) + child2 = WikiPage.create!(:wiki => @wiki, :title => 'Child2', :parent => page) + + assert_equal %w(Child1 Child11 Child111 Child2), page.descendants.map(&:title).sort + assert_equal %w(Child1 Child11 Child111 Child2), page.descendants(nil).map(&:title).sort + assert_equal %w(Child1 Child11 Child2), page.descendants(2).map(&:title).sort + assert_equal %w(Child1 Child2), page.descendants(1).map(&:title).sort + + assert_equal %w(Child1 Child11 Child111 Child2 Parent), page.self_and_descendants.map(&:title).sort + assert_equal %w(Child1 Child11 Child111 Child2 Parent), page.self_and_descendants(nil).map(&:title).sort + assert_equal %w(Child1 Child11 Child2 Parent), page.self_and_descendants(2).map(&:title).sort + assert_equal %w(Child1 Child2 Parent), page.self_and_descendants(1).map(&:title).sort + end end |