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_pages_test.rb 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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 Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
  19. fixtures :projects, :users, :roles, :members, :member_roles,
  20. :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
  21. :wiki_content_versions, :attachments
  22. test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
  23. get '/projects/ecookbook/wiki/index.xml'
  24. assert_response 200
  25. assert_equal 'application/xml', response.content_type
  26. assert_select 'wiki_pages[type=array]' do
  27. assert_select 'wiki_page', :count => Wiki.find(1).pages.count
  28. assert_select 'wiki_page' do
  29. assert_select 'title', :text => 'CookBook_documentation'
  30. assert_select 'version', :text => '3'
  31. assert_select 'created_on'
  32. assert_select 'updated_on'
  33. end
  34. assert_select 'wiki_page' do
  35. assert_select 'title', :text => 'Page_with_an_inline_image'
  36. assert_select 'parent[title=?]', 'CookBook_documentation'
  37. end
  38. end
  39. end
  40. test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
  41. get '/projects/ecookbook/wiki/CookBook_documentation.xml'
  42. assert_response 200
  43. assert_equal 'application/xml', response.content_type
  44. assert_select 'wiki_page' do
  45. assert_select 'title', :text => 'CookBook_documentation'
  46. assert_select 'version', :text => '3'
  47. assert_select 'text'
  48. assert_select 'author'
  49. assert_select 'comments'
  50. assert_select 'created_on'
  51. assert_select 'updated_on'
  52. end
  53. end
  54. test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
  55. get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
  56. assert_response 200
  57. assert_equal 'application/xml', response.content_type
  58. assert_select 'wiki_page' do
  59. assert_select 'title', :text => 'Page_with_an_inline_image'
  60. assert_select 'attachments[type=array]' do
  61. assert_select 'attachment' do
  62. assert_select 'id', :text => '3'
  63. assert_select 'filename', :text => 'logo.gif'
  64. end
  65. end
  66. end
  67. end
  68. test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
  69. get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
  70. assert_response 404
  71. assert_equal 'application/xml', response.content_type
  72. end
  73. test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
  74. get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
  75. assert_response 200
  76. assert_equal 'application/xml', response.content_type
  77. assert_select 'wiki_page' do
  78. assert_select 'title', :text => 'CookBook_documentation'
  79. assert_select 'version', :text => '2'
  80. assert_select 'text'
  81. assert_select 'author'
  82. assert_select 'comments', :text => 'Small update'
  83. assert_select 'created_on'
  84. assert_select 'updated_on'
  85. end
  86. end
  87. test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
  88. Role.anonymous.remove_permission! :view_wiki_edits
  89. get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
  90. assert_response 401
  91. assert_equal 'application/xml', response.content_type
  92. end
  93. test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
  94. assert_no_difference 'WikiPage.count' do
  95. assert_difference 'WikiContent::Version.count' do
  96. put '/projects/ecookbook/wiki/CookBook_documentation.xml',
  97. {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
  98. credentials('jsmith')
  99. assert_response 200
  100. end
  101. end
  102. page = WikiPage.find(1)
  103. assert_equal 'New content from API', page.content.text
  104. assert_equal 4, page.content.version
  105. assert_equal 'API update', page.content.comments
  106. assert_equal 'jsmith', page.content.author.login
  107. end
  108. test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
  109. assert_no_difference 'WikiPage.count' do
  110. assert_difference 'WikiContent::Version.count' do
  111. put '/projects/ecookbook/wiki/CookBook_documentation.xml',
  112. {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
  113. credentials('jsmith')
  114. assert_response 200
  115. end
  116. end
  117. page = WikiPage.find(1)
  118. assert_equal 'New content from API', page.content.text
  119. assert_equal 4, page.content.version
  120. assert_equal 'API update', page.content.comments
  121. assert_equal 'jsmith', page.content.author.login
  122. end
  123. test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
  124. assert_no_difference 'WikiPage.count' do
  125. assert_no_difference 'WikiContent::Version.count' do
  126. put '/projects/ecookbook/wiki/CookBook_documentation.xml',
  127. {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
  128. credentials('jsmith')
  129. assert_response 409
  130. end
  131. end
  132. end
  133. test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
  134. assert_difference 'WikiPage.count' do
  135. assert_difference 'WikiContent::Version.count' do
  136. put '/projects/ecookbook/wiki/New_page_from_API.xml',
  137. {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
  138. credentials('jsmith')
  139. assert_response 201
  140. end
  141. end
  142. page = WikiPage.order('id DESC').first
  143. assert_equal 'New_page_from_API', page.title
  144. assert_equal 'New content from API', page.content.text
  145. assert_equal 1, page.content.version
  146. assert_equal 'API create', page.content.comments
  147. assert_equal 'jsmith', page.content.author.login
  148. assert_nil page.parent
  149. end
  150. test "PUT /projects/:project_id/wiki/:title.xml with parent" do
  151. assert_difference 'WikiPage.count' do
  152. assert_difference 'WikiContent::Version.count' do
  153. put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
  154. {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
  155. credentials('jsmith')
  156. assert_response 201
  157. end
  158. end
  159. page = WikiPage.order('id DESC').first
  160. assert_equal 'New_subpage_from_API', page.title
  161. assert_equal WikiPage.find(1), page.parent
  162. end
  163. test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
  164. assert_difference 'WikiPage.count', -1 do
  165. delete '/projects/ecookbook/wiki/CookBook_documentation.xml', {}, credentials('jsmith')
  166. assert_response 200
  167. end
  168. assert_nil WikiPage.find_by_id(1)
  169. end
  170. end