2008-11-22 14:44:07 +03:00
|
|
|
# Redmine - project management software
|
2011-08-30 11:54:23 +04:00
|
|
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
2008-11-22 14:44:07 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-30 11:54:23 +04:00
|
|
|
#
|
2008-11-22 14:44:07 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-08-30 11:54:23 +04:00
|
|
|
#
|
2008-11-22 14:44:07 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../../../../test_helper', __FILE__)
|
2008-11-22 14:44:07 +03:00
|
|
|
|
2011-06-22 08:01:45 +04:00
|
|
|
class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase
|
2008-11-22 14:44:07 +03:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2010-11-06 20:47:27 +03:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
fixtures :projects, :roles, :enabled_modules, :users,
|
2011-08-30 11:54:23 +04:00
|
|
|
:repositories, :changesets,
|
2008-11-22 14:44:07 +03:00
|
|
|
:trackers, :issue_statuses, :issues,
|
|
|
|
:versions, :documents,
|
|
|
|
:wikis, :wiki_pages, :wiki_contents,
|
|
|
|
:boards, :messages,
|
|
|
|
:attachments
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@project = nil
|
|
|
|
end
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
def teardown
|
|
|
|
end
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2011-12-03 19:29:51 +04:00
|
|
|
def test_macro_registration
|
|
|
|
Redmine::WikiFormatting::Macros.register do
|
2011-12-10 17:55:47 +04:00
|
|
|
macro :foo do |obj, args|
|
2011-12-03 19:29:51 +04:00
|
|
|
"Foo macro output"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
text = "{{foo}}"
|
|
|
|
assert_equal '<p>Foo macro output</p>', textilizable(text)
|
|
|
|
end
|
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
def test_macro_hello_world
|
|
|
|
text = "{{hello_world}}"
|
|
|
|
assert textilizable(text).match(/Hello world!/)
|
|
|
|
# escaping
|
|
|
|
text = "!{{hello_world}}"
|
|
|
|
assert_equal '<p>{{hello_world}}</p>', textilizable(text)
|
|
|
|
end
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2011-12-03 19:25:02 +04:00
|
|
|
def test_macro_macro_list
|
|
|
|
text = "{{macro_list}}"
|
|
|
|
assert_match %r{<code>hello_world</code>}, textilizable(text)
|
|
|
|
end
|
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
def test_macro_include
|
|
|
|
@project = Project.find(1)
|
|
|
|
# include a page of the current project wiki
|
|
|
|
text = "{{include(Another page)}}"
|
|
|
|
assert textilizable(text).match(/This is a link to a ticket/)
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
@project = nil
|
|
|
|
# include a page of a specific project wiki
|
|
|
|
text = "{{include(ecookbook:Another page)}}"
|
|
|
|
assert textilizable(text).match(/This is a link to a ticket/)
|
|
|
|
|
|
|
|
text = "{{include(ecookbook:)}}"
|
|
|
|
assert textilizable(text).match(/CookBook documentation/)
|
|
|
|
|
|
|
|
text = "{{include(unknowidentifier:somepage)}}"
|
|
|
|
assert textilizable(text).match(/Page not found/)
|
|
|
|
end
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
def test_macro_child_pages
|
|
|
|
expected = "<p><ul class=\"pages-hierarchy\">\n" +
|
2009-01-26 04:47:51 +03:00
|
|
|
"<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" +
|
2008-11-22 14:44:07 +03:00
|
|
|
"</ul>\n</p>"
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
@project = Project.find(1)
|
|
|
|
# child pages of the current wiki page
|
|
|
|
assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content)
|
|
|
|
# child pages of another page
|
|
|
|
assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content)
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
@project = Project.find(2)
|
|
|
|
assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content)
|
|
|
|
end
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
def test_macro_child_pages_with_option
|
|
|
|
expected = "<p><ul class=\"pages-hierarchy\">\n" +
|
2009-01-26 04:47:51 +03:00
|
|
|
"<li><a href=\"/projects/ecookbook/wiki/Another_page\">Another page</a>\n" +
|
2008-11-22 14:44:07 +03:00
|
|
|
"<ul class=\"pages-hierarchy\">\n" +
|
2009-01-26 04:47:51 +03:00
|
|
|
"<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" +
|
2008-11-22 14:44:07 +03:00
|
|
|
"</ul>\n</li>\n</ul>\n</p>"
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
@project = Project.find(1)
|
|
|
|
# child pages of the current wiki page
|
|
|
|
assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content)
|
|
|
|
# child pages of another page
|
|
|
|
assert_equal expected, textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content)
|
2011-08-30 11:54:23 +04:00
|
|
|
|
2008-11-22 14:44:07 +03:00
|
|
|
@project = Project.find(2)
|
|
|
|
assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content)
|
|
|
|
end
|
2011-12-03 19:32:46 +04:00
|
|
|
|
|
|
|
def test_macro_child_pages_without_wiki_page_should_fail
|
|
|
|
assert_match /can be called from wiki pages only/, textilizable("{{child_pages}}")
|
|
|
|
end
|
2008-11-22 14:44:07 +03:00
|
|
|
end
|