3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 require File.expand_path('../../test_helper', __FILE__)
22 class WikiTest < ActiveSupport::TestCase
23 fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
26 wiki = Wiki.new(:project => Project.find(2))
28 assert_equal 1, wiki.errors.count
30 wiki.start_page = "Start page"
36 @wiki.start_page = "Another start page"
39 assert_equal "Another start page", @wiki.start_page
42 def test_find_page_should_not_be_case_sensitive
44 page = WikiPage.find(2)
46 assert_equal page, wiki.find_page('Another_page')
47 assert_equal page, wiki.find_page('Another page')
48 assert_equal page, wiki.find_page('ANOTHER page')
51 def test_find_page_with_cyrillic_characters
53 page = WikiPage.find(10)
54 assert_equal page, wiki.find_page('Этика_менеджмента')
57 def test_find_page_with_backslashes
59 page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09')
60 assert_equal page, wiki.find_page('2009\\02\\09')
63 def test_find_page_without_redirect
65 page = wiki.find_page('Another_page')
67 assert_equal 'Another_page', page.title
68 assert_equal false, wiki.page_found_with_redirect?
71 def test_find_page_with_redirect
73 WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
74 page = wiki.find_page('Old_title')
76 assert_equal 'Another_page', page.title
77 assert_equal true, wiki.page_found_with_redirect?
81 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
82 assert_equal 'テスト', Wiki.titleize('テスト')
90 should "return nil if undefined" do
91 assert_nil @wiki.sidebar
94 should "return a WikiPage if defined" do
95 page = @wiki.pages.new(:title => 'Sidebar')
96 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
99 assert_kind_of WikiPage, @wiki.sidebar
100 assert_equal 'Sidebar', @wiki.sidebar.title