To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / .svn / text-base / wiki_redirect_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (2.72 KB)

1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
3
#
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.
8
# 
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.
13
# 
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.
17

    
18
require File.expand_path('../../test_helper', __FILE__)
19

    
20
class WikiRedirectTest < ActiveSupport::TestCase
21
  fixtures :projects, :wikis, :wiki_pages
22

    
23
  def setup
24
    @wiki = Wiki.find(1)
25
    @original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
26
  end
27
  
28
  def test_create_redirect
29
    @original.title = 'New title'
30
    assert @original.save
31
    @original.reload
32
    
33
    assert_equal 'New_title', @original.title
34
    assert @wiki.redirects.find_by_title('Original_title')
35
    assert @wiki.find_page('Original title')
36
    assert @wiki.find_page('ORIGINAL title')
37
  end
38
  
39
  def test_update_redirect
40
    # create a redirect that point to this page
41
    assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
42
    
43
    @original.title = 'New title'
44
    @original.save
45
    # make sure the old page now points to the new page
46
    assert_equal 'New_title', @wiki.find_page('An old page').title
47
  end
48
  
49
  def test_reverse_rename
50
    # create a redirect that point to this page
51
    assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
52

    
53
    @original.title = 'An old page'
54
    @original.save
55
    assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'An_old_page')
56
    assert @wiki.redirects.find_by_title_and_redirects_to('Original_title', 'An_old_page')
57
  end
58
  
59
  def test_rename_to_already_redirected
60
    assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Other_page')
61

    
62
    @original.title = 'An old page'
63
    @original.save
64
    # this redirect have to be removed since 'An old page' page now exists
65
    assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'Other_page')
66
  end
67
  
68
  def test_redirects_removed_when_deleting_page
69
    assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
70
    
71
    @original.destroy
72
    assert !@wiki.redirects.find(:first)
73
  end
74
end