1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class WikiPageTest < ActiveSupport::TestCase
21 fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
25 @page = @wiki.pages.first
29 page = WikiPage.new(:wiki => @wiki)
31 assert_equal 1, page.errors.count
36 assert !page.protected?
39 assert @wiki.pages.include?(page)
42 def test_sidebar_should_be_protected_by_default
43 page = @wiki.find_or_new_page('sidebar')
44 assert page.new_record?
45 assert page.protected?
48 def test_find_or_new_page
49 page = @wiki.find_or_new_page("CookBook documentation")
50 assert_kind_of WikiPage, page
51 assert !page.new_record?
53 page = @wiki.find_or_new_page("Non existing page")
54 assert_kind_of WikiPage, page
55 assert page.new_record?
59 page = WikiPage.find_by_title('Another_page')
60 assert_nil page.parent_title
62 page = WikiPage.find_by_title('Page_with_an_inline_image')
63 assert_equal 'CookBook documentation', page.parent_title
66 def test_assign_parent
67 page = WikiPage.find_by_title('Another_page')
68 page.parent_title = 'CookBook documentation'
71 assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
74 def test_unassign_parent
75 page = WikiPage.find_by_title('Page_with_an_inline_image')
76 page.parent_title = ''
79 assert_nil page.parent
82 def test_parent_validation
83 page = WikiPage.find_by_title('CookBook_documentation')
85 # A page that doesn't exist
86 page.parent_title = 'Unknown title'
88 assert_equal I18n.translate('activerecord.errors.messages.invalid'), page.errors.on(:parent_title)
90 page.parent_title = 'Page_with_an_inline_image'
92 assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title)
94 page.parent_title = 'CookBook_documentation'
96 assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title)
98 page.parent_title = 'Another_page'
103 page = WikiPage.find(1)
105 assert_nil WikiPage.find_by_id(1)
106 # make sure that page content and its history are deleted
107 assert WikiContent.find_all_by_page_id(1).empty?
108 assert WikiContent.versioned_class.find_all_by_page_id(1).empty?
111 def test_destroy_should_not_nullify_children
112 page = WikiPage.find(2)
113 child_ids = page.child_ids
114 assert child_ids.any?
116 assert_nil WikiPage.find_by_id(2)
118 children = WikiPage.find_all_by_id(child_ids)
119 assert_equal child_ids.size, children.size
120 children.each do |child|
121 assert_nil child.parent_id