annotate test/integration/api_test/wiki_pages_test.rb @ 1621:3a510bf6a9bc

Merge from live branch
author Chris Cannam
date Fri, 13 Jul 2018 10:44:33 +0100
parents e248c7af89ec
children
rev   line source
Chris@1115 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1115 3 #
Chris@1115 4 # This program is free software; you can redistribute it and/or
Chris@1115 5 # modify it under the terms of the GNU General Public License
Chris@1115 6 # as published by the Free Software Foundation; either version 2
Chris@1115 7 # of the License, or (at your option) any later version.
Chris@1115 8 #
Chris@1115 9 # This program is distributed in the hope that it will be useful,
Chris@1115 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1115 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1115 12 # GNU General Public License for more details.
Chris@1115 13 #
Chris@1115 14 # You should have received a copy of the GNU General Public License
Chris@1115 15 # along with this program; if not, write to the Free Software
Chris@1115 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1115 17
Chris@1115 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@1115 19
Chris@1464 20 class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
Chris@1115 21 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@1115 22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
Chris@1115 23 :wiki_content_versions, :attachments
Chris@1115 24
Chris@1115 25 def setup
Chris@1115 26 Setting.rest_api_enabled = '1'
Chris@1115 27 end
Chris@1115 28
Chris@1115 29 test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
Chris@1115 30 get '/projects/ecookbook/wiki/index.xml'
Chris@1115 31 assert_response 200
Chris@1115 32 assert_equal 'application/xml', response.content_type
Chris@1115 33 assert_select 'wiki_pages[type=array]' do
Chris@1115 34 assert_select 'wiki_page', :count => Wiki.find(1).pages.count
Chris@1115 35 assert_select 'wiki_page' do
Chris@1115 36 assert_select 'title', :text => 'CookBook_documentation'
Chris@1115 37 assert_select 'version', :text => '3'
Chris@1115 38 assert_select 'created_on'
Chris@1115 39 assert_select 'updated_on'
Chris@1115 40 end
Chris@1115 41 assert_select 'wiki_page' do
Chris@1115 42 assert_select 'title', :text => 'Page_with_an_inline_image'
Chris@1115 43 assert_select 'parent[title=?]', 'CookBook_documentation'
Chris@1115 44 end
Chris@1115 45 end
Chris@1115 46 end
Chris@1115 47
Chris@1115 48 test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
Chris@1115 49 get '/projects/ecookbook/wiki/CookBook_documentation.xml'
Chris@1115 50 assert_response 200
Chris@1115 51 assert_equal 'application/xml', response.content_type
Chris@1115 52 assert_select 'wiki_page' do
Chris@1115 53 assert_select 'title', :text => 'CookBook_documentation'
Chris@1115 54 assert_select 'version', :text => '3'
Chris@1115 55 assert_select 'text'
Chris@1115 56 assert_select 'author'
Chris@1115 57 assert_select 'comments'
Chris@1115 58 assert_select 'created_on'
Chris@1115 59 assert_select 'updated_on'
Chris@1115 60 end
Chris@1115 61 end
Chris@1115 62
Chris@1115 63 test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
Chris@1115 64 get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
Chris@1115 65 assert_response 200
Chris@1115 66 assert_equal 'application/xml', response.content_type
Chris@1115 67 assert_select 'wiki_page' do
Chris@1115 68 assert_select 'title', :text => 'Page_with_an_inline_image'
Chris@1115 69 assert_select 'attachments[type=array]' do
Chris@1115 70 assert_select 'attachment' do
Chris@1115 71 assert_select 'id', :text => '3'
Chris@1115 72 assert_select 'filename', :text => 'logo.gif'
Chris@1115 73 end
Chris@1115 74 end
Chris@1115 75 end
Chris@1115 76 end
Chris@1115 77
Chris@1115 78 test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
Chris@1115 79 get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
Chris@1115 80 assert_response 404
Chris@1115 81 assert_equal 'application/xml', response.content_type
Chris@1115 82 end
Chris@1115 83
Chris@1115 84 test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
Chris@1115 85 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
Chris@1115 86 assert_response 200
Chris@1115 87 assert_equal 'application/xml', response.content_type
Chris@1115 88 assert_select 'wiki_page' do
Chris@1115 89 assert_select 'title', :text => 'CookBook_documentation'
Chris@1115 90 assert_select 'version', :text => '2'
Chris@1115 91 assert_select 'text'
Chris@1115 92 assert_select 'author'
Chris@1464 93 assert_select 'comments', :text => 'Small update'
Chris@1115 94 assert_select 'created_on'
Chris@1115 95 assert_select 'updated_on'
Chris@1115 96 end
Chris@1115 97 end
Chris@1115 98
Chris@1115 99 test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
Chris@1115 100 Role.anonymous.remove_permission! :view_wiki_edits
Chris@1115 101
Chris@1115 102 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
Chris@1115 103 assert_response 401
Chris@1115 104 assert_equal 'application/xml', response.content_type
Chris@1115 105 end
Chris@1115 106
Chris@1115 107 test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
Chris@1115 108 assert_no_difference 'WikiPage.count' do
Chris@1115 109 assert_difference 'WikiContent::Version.count' do
Chris@1115 110 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
Chris@1115 111 {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
Chris@1115 112 credentials('jsmith')
Chris@1115 113 assert_response 200
Chris@1115 114 end
Chris@1115 115 end
Chris@1115 116
Chris@1115 117 page = WikiPage.find(1)
Chris@1115 118 assert_equal 'New content from API', page.content.text
Chris@1115 119 assert_equal 4, page.content.version
Chris@1115 120 assert_equal 'API update', page.content.comments
Chris@1115 121 assert_equal 'jsmith', page.content.author.login
Chris@1115 122 end
Chris@1115 123
Chris@1115 124 test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
Chris@1115 125 assert_no_difference 'WikiPage.count' do
Chris@1115 126 assert_difference 'WikiContent::Version.count' do
Chris@1115 127 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
Chris@1115 128 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
Chris@1115 129 credentials('jsmith')
Chris@1115 130 assert_response 200
Chris@1115 131 end
Chris@1115 132 end
Chris@1115 133
Chris@1115 134 page = WikiPage.find(1)
Chris@1115 135 assert_equal 'New content from API', page.content.text
Chris@1115 136 assert_equal 4, page.content.version
Chris@1115 137 assert_equal 'API update', page.content.comments
Chris@1115 138 assert_equal 'jsmith', page.content.author.login
Chris@1115 139 end
Chris@1115 140
Chris@1115 141 test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
Chris@1115 142 assert_no_difference 'WikiPage.count' do
Chris@1115 143 assert_no_difference 'WikiContent::Version.count' do
Chris@1115 144 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
Chris@1115 145 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
Chris@1115 146 credentials('jsmith')
Chris@1115 147 assert_response 409
Chris@1115 148 end
Chris@1115 149 end
Chris@1115 150 end
Chris@1115 151
Chris@1115 152 test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
Chris@1115 153 assert_difference 'WikiPage.count' do
Chris@1115 154 assert_difference 'WikiContent::Version.count' do
Chris@1115 155 put '/projects/ecookbook/wiki/New_page_from_API.xml',
Chris@1115 156 {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
Chris@1115 157 credentials('jsmith')
Chris@1115 158 assert_response 201
Chris@1115 159 end
Chris@1115 160 end
Chris@1115 161
Chris@1115 162 page = WikiPage.order('id DESC').first
Chris@1115 163 assert_equal 'New_page_from_API', page.title
Chris@1115 164 assert_equal 'New content from API', page.content.text
Chris@1115 165 assert_equal 1, page.content.version
Chris@1115 166 assert_equal 'API create', page.content.comments
Chris@1115 167 assert_equal 'jsmith', page.content.author.login
Chris@1115 168 assert_nil page.parent
Chris@1115 169 end
Chris@1115 170
Chris@1115 171 test "PUT /projects/:project_id/wiki/:title.xml with parent" do
Chris@1115 172 assert_difference 'WikiPage.count' do
Chris@1115 173 assert_difference 'WikiContent::Version.count' do
Chris@1115 174 put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
Chris@1115 175 {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
Chris@1115 176 credentials('jsmith')
Chris@1115 177 assert_response 201
Chris@1115 178 end
Chris@1115 179 end
Chris@1115 180
Chris@1115 181 page = WikiPage.order('id DESC').first
Chris@1115 182 assert_equal 'New_subpage_from_API', page.title
Chris@1115 183 assert_equal WikiPage.find(1), page.parent
Chris@1115 184 end
Chris@1115 185
Chris@1115 186 test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
Chris@1115 187 assert_difference 'WikiPage.count', -1 do
Chris@1115 188 delete '/projects/ecookbook/wiki/CookBook_documentation.xml', {}, credentials('jsmith')
Chris@1115 189 assert_response 200
Chris@1115 190 end
Chris@1115 191
Chris@1115 192 assert_nil WikiPage.find_by_id(1)
Chris@1115 193 end
Chris@1115 194 end