Chris@0: # Redmine - project management software Chris@0: # Copyright (C) 2006-2008 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@117: require File.expand_path('../../../../../test_helper', __FILE__) Chris@0: Chris@0: class Redmine::WikiFormatting::MacrosTest < HelperTestCase Chris@0: include ApplicationHelper Chris@0: include ActionView::Helpers::TextHelper chris@37: include ActionView::Helpers::SanitizeHelper chris@37: extend ActionView::Helpers::SanitizeHelper::ClassMethods chris@37: Chris@0: fixtures :projects, :roles, :enabled_modules, :users, Chris@0: :repositories, :changesets, Chris@0: :trackers, :issue_statuses, :issues, Chris@0: :versions, :documents, Chris@0: :wikis, :wiki_pages, :wiki_contents, Chris@0: :boards, :messages, Chris@0: :attachments Chris@0: Chris@0: def setup Chris@0: super Chris@0: @project = nil Chris@0: end Chris@0: Chris@0: def teardown Chris@0: end Chris@0: Chris@0: def test_macro_hello_world Chris@0: text = "{{hello_world}}" Chris@0: assert textilizable(text).match(/Hello world!/) Chris@0: # escaping Chris@0: text = "!{{hello_world}}" Chris@0: assert_equal '

{{hello_world}}

', textilizable(text) Chris@0: end Chris@0: Chris@0: def test_macro_include Chris@0: @project = Project.find(1) Chris@0: # include a page of the current project wiki Chris@0: text = "{{include(Another page)}}" Chris@0: assert textilizable(text).match(/This is a link to a ticket/) Chris@0: Chris@0: @project = nil Chris@0: # include a page of a specific project wiki Chris@0: text = "{{include(ecookbook:Another page)}}" Chris@0: assert textilizable(text).match(/This is a link to a ticket/) Chris@0: Chris@0: text = "{{include(ecookbook:)}}" Chris@0: assert textilizable(text).match(/CookBook documentation/) Chris@0: Chris@0: text = "{{include(unknowidentifier:somepage)}}" Chris@0: assert textilizable(text).match(/Page not found/) Chris@0: end Chris@0: Chris@0: def test_macro_child_pages Chris@0: expected = "

\n

" Chris@0: Chris@0: @project = Project.find(1) Chris@0: # child pages of the current wiki page Chris@0: assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content) Chris@0: # child pages of another page Chris@0: assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content) Chris@0: Chris@0: @project = Project.find(2) Chris@0: assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content) Chris@0: end Chris@0: Chris@0: def test_macro_child_pages_with_option Chris@0: expected = "

\n

" Chris@0: Chris@0: @project = Project.find(1) Chris@0: # child pages of the current wiki page Chris@0: assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content) Chris@0: # child pages of another page Chris@0: assert_equal expected, textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content) Chris@0: Chris@0: @project = Project.find(2) Chris@0: assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content) Chris@0: end Chris@0: end