Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

wiki_test.rb 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2017 Jean-Philippe Lang
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. require File.expand_path('../../test_helper', __FILE__)
  20. class WikiTest < ActiveSupport::TestCase
  21. fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
  22. def test_create
  23. wiki = Wiki.new(:project => Project.find(3))
  24. assert !wiki.save
  25. assert_equal 1, wiki.errors.count
  26. wiki.start_page = "Start page"
  27. assert wiki.save
  28. end
  29. def test_update
  30. @wiki = Wiki.find(1)
  31. @wiki.start_page = "Another start page"
  32. assert @wiki.save
  33. @wiki.reload
  34. assert_equal "Another start page", @wiki.start_page
  35. end
  36. def test_find_page_should_not_be_case_sensitive
  37. wiki = Wiki.find(1)
  38. page = WikiPage.find(2)
  39. assert_equal page, wiki.find_page('Another_page')
  40. assert_equal page, wiki.find_page('Another page')
  41. assert_equal page, wiki.find_page('ANOTHER page')
  42. end
  43. def test_find_page_with_cyrillic_characters
  44. wiki = Wiki.find(1)
  45. page = WikiPage.find(10)
  46. assert_equal page, wiki.find_page('Этика_менеджмента')
  47. end
  48. def test_find_page_with_backslashes
  49. wiki = Wiki.find(1)
  50. page = WikiPage.create!(:wiki => wiki, :title => '2009\\02\\09')
  51. assert_equal page, wiki.find_page('2009\\02\\09')
  52. end
  53. def test_find_page_without_redirect
  54. wiki = Wiki.find(1)
  55. page = wiki.find_page('Another_page')
  56. assert_not_nil page
  57. assert_equal 'Another_page', page.title
  58. assert_equal false, wiki.page_found_with_redirect?
  59. end
  60. def test_find_page_with_redirect
  61. wiki = Wiki.find(1)
  62. WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
  63. page = wiki.find_page('Old_title')
  64. assert_not_nil page
  65. assert_equal 'Another_page', page.title
  66. assert_equal true, wiki.page_found_with_redirect?
  67. end
  68. def test_titleize
  69. ja_test = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88".force_encoding('UTF-8')
  70. assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
  71. assert_equal ja_test, Wiki.titleize(ja_test)
  72. end
  73. def test_sidebar_should_return_nil_if_undefined
  74. @wiki = Wiki.find(1)
  75. assert_nil @wiki.sidebar
  76. end
  77. def test_sidebar_should_return_a_wiki_page_if_defined
  78. @wiki = Wiki.find(1)
  79. page = @wiki.pages.new(:title => 'Sidebar')
  80. page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
  81. page.save!
  82. assert_kind_of WikiPage, @wiki.sidebar
  83. assert_equal 'Sidebar', @wiki.sidebar.title
  84. end
  85. def test_destroy_should_remove_redirects_from_the_wiki
  86. WikiRedirect.create!(:wiki_id => 1, :title => 'Foo', :redirects_to_wiki_id => 2, :redirects_to => 'Bar')
  87. Wiki.find(1).destroy
  88. assert_equal 0, WikiRedirect.where(:wiki_id => 1).count
  89. end
  90. def test_destroy_should_remove_redirects_to_the_wiki
  91. WikiRedirect.create!(:wiki_id => 2, :title => 'Foo', :redirects_to_wiki_id => 1, :redirects_to => 'Bar')
  92. Wiki.find(1).destroy
  93. assert_equal 0, WikiRedirect.where(:redirects_to_wiki_id => 1).count
  94. end
  95. end