Chris@0
|
1 # encoding: utf-8
|
Chris@0
|
2 #
|
Chris@441
|
3 # Redmine - project management software
|
Chris@1494
|
4 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@0
|
5 #
|
Chris@0
|
6 # This program is free software; you can redistribute it and/or
|
Chris@0
|
7 # modify it under the terms of the GNU General Public License
|
Chris@0
|
8 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
9 # of the License, or (at your option) any later version.
|
Chris@441
|
10 #
|
Chris@0
|
11 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
14 # GNU General Public License for more details.
|
Chris@441
|
15 #
|
Chris@0
|
16 # You should have received a copy of the GNU General Public License
|
Chris@0
|
17 # along with this program; if not, write to the Free Software
|
Chris@0
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
19
|
Chris@119
|
20 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
21
|
Chris@0
|
22 class WikiTest < ActiveSupport::TestCase
|
Chris@441
|
23 fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
|
Chris@441
|
24
|
Chris@0
|
25 def test_create
|
Chris@0
|
26 wiki = Wiki.new(:project => Project.find(2))
|
Chris@0
|
27 assert !wiki.save
|
Chris@0
|
28 assert_equal 1, wiki.errors.count
|
Chris@441
|
29
|
Chris@0
|
30 wiki.start_page = "Start page"
|
Chris@0
|
31 assert wiki.save
|
Chris@0
|
32 end
|
Chris@0
|
33
|
Chris@0
|
34 def test_update
|
Chris@0
|
35 @wiki = Wiki.find(1)
|
Chris@0
|
36 @wiki.start_page = "Another start page"
|
Chris@0
|
37 assert @wiki.save
|
Chris@0
|
38 @wiki.reload
|
Chris@0
|
39 assert_equal "Another start page", @wiki.start_page
|
Chris@0
|
40 end
|
Chris@441
|
41
|
Chris@441
|
42 def test_find_page_should_not_be_case_sensitive
|
Chris@119
|
43 wiki = Wiki.find(1)
|
Chris@119
|
44 page = WikiPage.find(2)
|
Chris@441
|
45
|
Chris@119
|
46 assert_equal page, wiki.find_page('Another_page')
|
Chris@119
|
47 assert_equal page, wiki.find_page('Another page')
|
Chris@119
|
48 assert_equal page, wiki.find_page('ANOTHER page')
|
Chris@441
|
49 end
|
Chris@441
|
50
|
Chris@441
|
51 def test_find_page_with_cyrillic_characters
|
Chris@441
|
52 wiki = Wiki.find(1)
|
Chris@119
|
53 page = WikiPage.find(10)
|
Chris@119
|
54 assert_equal page, wiki.find_page('Этика_менеджмента')
|
Chris@119
|
55 end
|
Chris@441
|
56
|
Chris@441
|
57 def test_find_page_with_backslashes
|
Chris@441
|
58 wiki = Wiki.find(1)
|
Chris@1115
|
59 page = WikiPage.create!(:wiki => wiki, :title => '2009\\02\\09')
|
Chris@441
|
60 assert_equal page, wiki.find_page('2009\\02\\09')
|
Chris@441
|
61 end
|
Chris@441
|
62
|
Chris@441
|
63 def test_find_page_without_redirect
|
Chris@441
|
64 wiki = Wiki.find(1)
|
Chris@441
|
65 page = wiki.find_page('Another_page')
|
Chris@441
|
66 assert_not_nil page
|
Chris@441
|
67 assert_equal 'Another_page', page.title
|
Chris@441
|
68 assert_equal false, wiki.page_found_with_redirect?
|
Chris@441
|
69 end
|
Chris@441
|
70
|
Chris@441
|
71 def test_find_page_with_redirect
|
Chris@441
|
72 wiki = Wiki.find(1)
|
Chris@441
|
73 WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
|
Chris@441
|
74 page = wiki.find_page('Old_title')
|
Chris@441
|
75 assert_not_nil page
|
Chris@441
|
76 assert_equal 'Another_page', page.title
|
Chris@441
|
77 assert_equal true, wiki.page_found_with_redirect?
|
Chris@441
|
78 end
|
Chris@441
|
79
|
Chris@0
|
80 def test_titleize
|
Chris@1115
|
81 ja_test = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
|
Chris@1115
|
82 ja_test.force_encoding('UTF-8') if ja_test.respond_to?(:force_encoding)
|
Chris@0
|
83 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
|
Chris@1115
|
84 assert_equal ja_test, Wiki.titleize(ja_test)
|
Chris@0
|
85 end
|
Chris@441
|
86
|
Chris@1464
|
87 def test_sidebar_should_return_nil_if_undefined
|
Chris@1464
|
88 @wiki = Wiki.find(1)
|
Chris@1464
|
89 assert_nil @wiki.sidebar
|
Chris@1464
|
90 end
|
Chris@441
|
91
|
Chris@1464
|
92 def test_sidebar_should_return_a_wiki_page_if_defined
|
Chris@1464
|
93 @wiki = Wiki.find(1)
|
Chris@1464
|
94 page = @wiki.pages.new(:title => 'Sidebar')
|
Chris@1464
|
95 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
|
Chris@1464
|
96 page.save!
|
Chris@441
|
97
|
Chris@1464
|
98 assert_kind_of WikiPage, @wiki.sidebar
|
Chris@1464
|
99 assert_equal 'Sidebar', @wiki.sidebar.title
|
Chris@0
|
100 end
|
Chris@0
|
101 end
|