annotate .svn/pristine/ae/aefa10621da29d1174e5f170d627124a0e405f4e.svn-base @ 1464:261b3d9a4903 redmine-2.4

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