Chris@0
|
1 # Redmine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require File.dirname(__FILE__) + '/../../../../test_helper'
|
Chris@0
|
19
|
Chris@0
|
20 class Redmine::WikiFormatting::MacrosTest < HelperTestCase
|
Chris@0
|
21 include ApplicationHelper
|
Chris@0
|
22 include ActionView::Helpers::TextHelper
|
chris@37
|
23 include ActionView::Helpers::SanitizeHelper
|
chris@37
|
24 extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
chris@37
|
25
|
Chris@0
|
26 fixtures :projects, :roles, :enabled_modules, :users,
|
Chris@0
|
27 :repositories, :changesets,
|
Chris@0
|
28 :trackers, :issue_statuses, :issues,
|
Chris@0
|
29 :versions, :documents,
|
Chris@0
|
30 :wikis, :wiki_pages, :wiki_contents,
|
Chris@0
|
31 :boards, :messages,
|
Chris@0
|
32 :attachments
|
Chris@0
|
33
|
Chris@0
|
34 def setup
|
Chris@0
|
35 super
|
Chris@0
|
36 @project = nil
|
Chris@0
|
37 end
|
Chris@0
|
38
|
Chris@0
|
39 def teardown
|
Chris@0
|
40 end
|
Chris@0
|
41
|
Chris@0
|
42 def test_macro_hello_world
|
Chris@0
|
43 text = "{{hello_world}}"
|
Chris@0
|
44 assert textilizable(text).match(/Hello world!/)
|
Chris@0
|
45 # escaping
|
Chris@0
|
46 text = "!{{hello_world}}"
|
Chris@0
|
47 assert_equal '<p>{{hello_world}}</p>', textilizable(text)
|
Chris@0
|
48 end
|
Chris@0
|
49
|
Chris@0
|
50 def test_macro_include
|
Chris@0
|
51 @project = Project.find(1)
|
Chris@0
|
52 # include a page of the current project wiki
|
Chris@0
|
53 text = "{{include(Another page)}}"
|
Chris@0
|
54 assert textilizable(text).match(/This is a link to a ticket/)
|
Chris@0
|
55
|
Chris@0
|
56 @project = nil
|
Chris@0
|
57 # include a page of a specific project wiki
|
Chris@0
|
58 text = "{{include(ecookbook:Another page)}}"
|
Chris@0
|
59 assert textilizable(text).match(/This is a link to a ticket/)
|
Chris@0
|
60
|
Chris@0
|
61 text = "{{include(ecookbook:)}}"
|
Chris@0
|
62 assert textilizable(text).match(/CookBook documentation/)
|
Chris@0
|
63
|
Chris@0
|
64 text = "{{include(unknowidentifier:somepage)}}"
|
Chris@0
|
65 assert textilizable(text).match(/Page not found/)
|
Chris@0
|
66 end
|
Chris@0
|
67
|
Chris@0
|
68 def test_macro_child_pages
|
Chris@0
|
69 expected = "<p><ul class=\"pages-hierarchy\">\n" +
|
Chris@0
|
70 "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a></li>\n" +
|
Chris@0
|
71 "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" +
|
Chris@0
|
72 "</ul>\n</p>"
|
Chris@0
|
73
|
Chris@0
|
74 @project = Project.find(1)
|
Chris@0
|
75 # child pages of the current wiki page
|
Chris@0
|
76 assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content)
|
Chris@0
|
77 # child pages of another page
|
Chris@0
|
78 assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content)
|
Chris@0
|
79
|
Chris@0
|
80 @project = Project.find(2)
|
Chris@0
|
81 assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content)
|
Chris@0
|
82 end
|
Chris@0
|
83
|
Chris@0
|
84 def test_macro_child_pages_with_option
|
Chris@0
|
85 expected = "<p><ul class=\"pages-hierarchy\">\n" +
|
Chris@0
|
86 "<li><a href=\"/projects/ecookbook/wiki/Another_page\">Another page</a>\n" +
|
Chris@0
|
87 "<ul class=\"pages-hierarchy\">\n" +
|
Chris@0
|
88 "<li><a href=\"/projects/ecookbook/wiki/Child_1\">Child 1</a></li>\n" +
|
Chris@0
|
89 "<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" +
|
Chris@0
|
90 "</ul>\n</li>\n</ul>\n</p>"
|
Chris@0
|
91
|
Chris@0
|
92 @project = Project.find(1)
|
Chris@0
|
93 # child pages of the current wiki page
|
Chris@0
|
94 assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content)
|
Chris@0
|
95 # child pages of another page
|
Chris@0
|
96 assert_equal expected, textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content)
|
Chris@0
|
97
|
Chris@0
|
98 @project = Project.find(2)
|
Chris@0
|
99 assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content)
|
Chris@0
|
100 end
|
Chris@0
|
101 end
|