You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wiki_redirect_test.rb 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. require File.expand_path('../../test_helper', __FILE__)
  18. class WikiRedirectTest < ActiveSupport::TestCase
  19. fixtures :projects, :wikis, :wiki_pages
  20. def setup
  21. User.current = nil
  22. @wiki = Wiki.find(1)
  23. @original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
  24. end
  25. def test_create_redirect_on_rename
  26. @original.title = 'New title'
  27. @original.save!
  28. redirect = @wiki.redirects.find_by_title('Original_title')
  29. assert_not_nil redirect
  30. assert_equal 1, redirect.redirects_to_wiki_id
  31. assert_equal 'New_title', redirect.redirects_to
  32. assert_equal @original, redirect.target_page
  33. end
  34. def test_create_redirect_on_move
  35. @original.wiki_id = 2
  36. @original.save!
  37. redirect = @wiki.redirects.find_by_title('Original_title')
  38. assert_not_nil redirect
  39. assert_equal 2, redirect.redirects_to_wiki_id
  40. assert_equal 'Original_title', redirect.redirects_to
  41. assert_equal @original, redirect.target_page
  42. end
  43. def test_create_redirect_on_rename_and_move
  44. @original.title = 'New title'
  45. @original.wiki_id = 2
  46. @original.save!
  47. redirect = @wiki.redirects.find_by_title('Original_title')
  48. assert_not_nil redirect
  49. assert_equal 2, redirect.redirects_to_wiki_id
  50. assert_equal 'New_title', redirect.redirects_to
  51. assert_equal @original, redirect.target_page
  52. end
  53. def test_update_redirect
  54. # create a redirect that point to this page
  55. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  56. @original.title = 'New title'
  57. @original.save
  58. # make sure the old page now points to the new page
  59. assert_equal 'New_title', @wiki.find_page('An old page').title
  60. end
  61. def test_reverse_rename
  62. # create a redirect that point to this page
  63. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  64. @original.title = 'An old page'
  65. @original.save
  66. assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'An_old_page')
  67. assert @wiki.redirects.find_by_title_and_redirects_to('Original_title', 'An_old_page')
  68. end
  69. def test_rename_to_already_redirected
  70. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Other_page')
  71. @original.title = 'An old page'
  72. @original.save
  73. # this redirect have to be removed since 'An old page' page now exists
  74. assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'Other_page')
  75. end
  76. def test_redirects_removed_when_deleting_page
  77. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  78. @original.destroy
  79. assert_nil @wiki.redirects.first
  80. end
  81. end