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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 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_create_default
  32. wiki = Wiki.create_default(Project.find(1))
  33. assert wiki.save
  34. assert_equal "Wiki", wiki.start_page
  35. end
  36. def test_update
  37. @wiki = Wiki.find(1)
  38. @wiki.start_page = "Another start page"
  39. assert @wiki.save
  40. @wiki.reload
  41. assert_equal "Another start page", @wiki.start_page
  42. end
  43. def test_find_page_should_not_be_case_sensitive
  44. wiki = Wiki.find(1)
  45. page = WikiPage.find(2)
  46. assert_equal page, wiki.find_page('Another_page')
  47. assert_equal page, wiki.find_page('Another page')
  48. assert_equal page, wiki.find_page('ANOTHER page')
  49. end
  50. def test_ordering_pages_should_not_be_case_sensitive
  51. wiki = Wiki.find(1)
  52. wiki.pages.destroy_all
  53. %w(ABc ACd Aac Acc).each do |title|
  54. wiki.pages.create(:title => title)
  55. end
  56. wiki.reload
  57. assert_equal %w(Aac ABc Acc ACd), wiki.pages.pluck(:title)
  58. end
  59. def test_find_page_with_cyrillic_characters
  60. wiki = Wiki.find(1)
  61. page = WikiPage.find(10)
  62. assert_equal page, wiki.find_page('Этика_менеджмента')
  63. end
  64. def test_find_page_with_backslashes
  65. wiki = Wiki.find(1)
  66. page = WikiPage.create!(:wiki => wiki, :title => '2009\\02\\09')
  67. assert_equal page, wiki.find_page('2009\\02\\09')
  68. end
  69. def test_find_page_without_redirect
  70. wiki = Wiki.find(1)
  71. page = wiki.find_page('Another_page')
  72. assert_not_nil page
  73. assert_equal 'Another_page', page.title
  74. assert_equal false, wiki.page_found_with_redirect?
  75. end
  76. def test_find_page_with_redirect
  77. wiki = Wiki.find(1)
  78. WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
  79. page = wiki.find_page('Old_title')
  80. assert_not_nil page
  81. assert_equal 'Another_page', page.title
  82. assert_equal true, wiki.page_found_with_redirect?
  83. end
  84. def test_titleize
  85. ja_test = 'テスト'
  86. assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
  87. assert_equal ja_test, Wiki.titleize(ja_test)
  88. end
  89. def test_sidebar_should_return_nil_if_undefined
  90. @wiki = Wiki.find(1)
  91. assert_nil @wiki.sidebar
  92. end
  93. def test_sidebar_should_return_a_wiki_page_if_defined
  94. @wiki = Wiki.find(1)
  95. page = @wiki.pages.new(:title => 'Sidebar')
  96. page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
  97. page.save!
  98. assert_kind_of WikiPage, @wiki.sidebar
  99. assert_equal 'Sidebar', @wiki.sidebar.title
  100. end
  101. def test_destroy_should_remove_redirects_from_the_wiki
  102. set_tmp_attachments_directory
  103. WikiRedirect.create!(:wiki_id => 1, :title => 'Foo', :redirects_to_wiki_id => 2, :redirects_to => 'Bar')
  104. Wiki.find(1).destroy
  105. assert_equal 0, WikiRedirect.where(:wiki_id => 1).count
  106. end
  107. def test_destroy_should_remove_redirects_to_the_wiki
  108. set_tmp_attachments_directory
  109. WikiRedirect.create!(:wiki_id => 2, :title => 'Foo', :redirects_to_wiki_id => 1, :redirects_to => 'Bar')
  110. Wiki.find(1).destroy
  111. assert_equal 0, WikiRedirect.where(:redirects_to_wiki_id => 1).count
  112. end
  113. end