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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class WikiRedirectTest < ActiveSupport::TestCase
  20. fixtures :projects, :wikis, :wiki_pages
  21. def setup
  22. User.current = nil
  23. @wiki = Wiki.find(1)
  24. @original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
  25. end
  26. def test_create_redirect_on_rename
  27. @original.title = 'New title'
  28. @original.save!
  29. redirect = @wiki.redirects.find_by_title('Original_title')
  30. assert_not_nil redirect
  31. assert_equal 1, redirect.redirects_to_wiki_id
  32. assert_equal 'New_title', redirect.redirects_to
  33. assert_equal @original, redirect.target_page
  34. end
  35. def test_create_redirect_on_move
  36. @original.wiki_id = 2
  37. @original.save!
  38. redirect = @wiki.redirects.find_by_title('Original_title')
  39. assert_not_nil redirect
  40. assert_equal 2, redirect.redirects_to_wiki_id
  41. assert_equal 'Original_title', redirect.redirects_to
  42. assert_equal @original, redirect.target_page
  43. end
  44. def test_create_redirect_on_rename_and_move
  45. @original.title = 'New title'
  46. @original.wiki_id = 2
  47. @original.save!
  48. redirect = @wiki.redirects.find_by_title('Original_title')
  49. assert_not_nil redirect
  50. assert_equal 2, redirect.redirects_to_wiki_id
  51. assert_equal 'New_title', redirect.redirects_to
  52. assert_equal @original, redirect.target_page
  53. end
  54. def test_update_redirect
  55. # create a redirect that point to this page
  56. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  57. @original.title = 'New title'
  58. @original.save
  59. # make sure the old page now points to the new page
  60. assert_equal 'New_title', @wiki.find_page('An old page').title
  61. end
  62. def test_reverse_rename
  63. # create a redirect that point to this page
  64. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  65. @original.title = 'An old page'
  66. @original.save
  67. assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'An_old_page')
  68. assert @wiki.redirects.find_by_title_and_redirects_to('Original_title', 'An_old_page')
  69. end
  70. def test_rename_to_already_redirected
  71. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Other_page')
  72. @original.title = 'An old page'
  73. @original.save
  74. # this redirect have to be removed since 'An old page' page now exists
  75. assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'Other_page')
  76. end
  77. def test_redirects_removed_when_deleting_page
  78. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  79. @original.destroy
  80. assert_not @wiki.redirects.exists?
  81. end
  82. end