annotate .svn/pristine/58/589406c4e8b5981509b450115306b35254aced34.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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