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_test.rb 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 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 File.expand_path('../../test_helper', __FILE__)
  19. class WikiTest < ActiveSupport::TestCase
  20. fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
  21. def setup
  22. User.current = nil
  23. end
  24. def test_create
  25. wiki = Wiki.new(:project => Project.find(3))
  26. assert !wiki.save
  27. assert_equal 1, wiki.errors.count
  28. wiki.start_page = "Start page"
  29. assert wiki.save
  30. end
  31. def test_update
  32. @wiki = Wiki.find(1)
  33. @wiki.start_page = "Another start page"
  34. assert @wiki.save
  35. @wiki.reload
  36. assert_equal "Another start page", @wiki.start_page
  37. end
  38. def test_find_page_should_not_be_case_sensitive
  39. wiki = Wiki.find(1)
  40. page = WikiPage.find(2)
  41. assert_equal page, wiki.find_page('Another_page')
  42. assert_equal page, wiki.find_page('Another page')
  43. assert_equal page, wiki.find_page('ANOTHER page')
  44. end
  45. def test_ordering_pages_should_not_be_case_sensitive
  46. wiki = Wiki.find(1)
  47. wiki.pages.destroy_all
  48. %w(ABc ACd Aac Acc).each do |title|
  49. wiki.pages.create(:title => title)
  50. end
  51. wiki.reload
  52. assert_equal %w(Aac ABc Acc ACd), wiki.pages.pluck(:title)
  53. end
  54. def test_find_page_with_cyrillic_characters
  55. wiki = Wiki.find(1)
  56. page = WikiPage.find(10)
  57. assert_equal page, wiki.find_page('Этика_менеджмента')
  58. end
  59. def test_find_page_with_backslashes
  60. wiki = Wiki.find(1)
  61. page = WikiPage.create!(:wiki => wiki, :title => '2009\\02\\09')
  62. assert_equal page, wiki.find_page('2009\\02\\09')
  63. end
  64. def test_find_page_without_redirect
  65. wiki = Wiki.find(1)
  66. page = wiki.find_page('Another_page')
  67. assert_not_nil page
  68. assert_equal 'Another_page', page.title
  69. assert_equal false, wiki.page_found_with_redirect?
  70. end
  71. def test_find_page_with_redirect
  72. wiki = Wiki.find(1)
  73. WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
  74. page = wiki.find_page('Old_title')
  75. assert_not_nil page
  76. assert_equal 'Another_page', page.title
  77. assert_equal true, wiki.page_found_with_redirect?
  78. end
  79. def test_titleize
  80. ja_test = 'テスト'
  81. assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
  82. assert_equal ja_test, Wiki.titleize(ja_test)
  83. end
  84. def test_sidebar_should_return_nil_if_undefined
  85. @wiki = Wiki.find(1)
  86. assert_nil @wiki.sidebar
  87. end
  88. def test_sidebar_should_return_a_wiki_page_if_defined
  89. @wiki = Wiki.find(1)
  90. page = @wiki.pages.new(:title => 'Sidebar')
  91. page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
  92. page.save!
  93. assert_kind_of WikiPage, @wiki.sidebar
  94. assert_equal 'Sidebar', @wiki.sidebar.title
  95. end
  96. def test_destroy_should_remove_redirects_from_the_wiki
  97. set_tmp_attachments_directory
  98. WikiRedirect.create!(:wiki_id => 1, :title => 'Foo', :redirects_to_wiki_id => 2, :redirects_to => 'Bar')
  99. Wiki.find(1).destroy
  100. assert_equal 0, WikiRedirect.where(:wiki_id => 1).count
  101. end
  102. def test_destroy_should_remove_redirects_to_the_wiki
  103. set_tmp_attachments_directory
  104. WikiRedirect.create!(:wiki_id => 2, :title => 'Foo', :redirects_to_wiki_id => 1, :redirects_to => 'Bar')
  105. Wiki.find(1).destroy
  106. assert_equal 0, WikiRedirect.where(:redirects_to_wiki_id => 1).count
  107. end
  108. end