annotate .svn/pristine/ec/ec08ed5799ed2d9d7e3eaed4465f5f691c2309ee.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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