2012-10-25 23:44:04 +04:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2012-10-25 23:44:04 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
require File.expand_path('../../../test_helper', __FILE__)
|
|
|
|
|
2013-01-22 22:26:04 +04:00
|
|
|
class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base
|
2012-10-25 23:44:04 +04:00
|
|
|
fixtures :projects, :users, :roles, :members, :member_roles,
|
|
|
|
:enabled_modules, :wikis, :wiki_pages, :wiki_contents,
|
|
|
|
:wiki_content_versions, :attachments
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Setting.rest_api_enabled = '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
|
|
|
|
get '/projects/ecookbook/wiki/index.xml'
|
2012-10-26 00:38:29 +04:00
|
|
|
assert_response 200
|
2012-10-25 23:44:04 +04:00
|
|
|
assert_equal 'application/xml', response.content_type
|
|
|
|
assert_select 'wiki_pages[type=array]' do
|
|
|
|
assert_select 'wiki_page', :count => Wiki.find(1).pages.count
|
|
|
|
assert_select 'wiki_page' do
|
|
|
|
assert_select 'title', :text => 'CookBook_documentation'
|
|
|
|
assert_select 'version', :text => '3'
|
|
|
|
assert_select 'created_on'
|
|
|
|
assert_select 'updated_on'
|
|
|
|
end
|
2012-10-26 00:38:29 +04:00
|
|
|
assert_select 'wiki_page' do
|
|
|
|
assert_select 'title', :text => 'Page_with_an_inline_image'
|
|
|
|
assert_select 'parent[title=?]', 'CookBook_documentation'
|
|
|
|
end
|
2012-10-25 23:44:04 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
|
|
|
|
get '/projects/ecookbook/wiki/CookBook_documentation.xml'
|
2012-10-26 00:38:29 +04:00
|
|
|
assert_response 200
|
2012-10-25 23:44:04 +04:00
|
|
|
assert_equal 'application/xml', response.content_type
|
|
|
|
assert_select 'wiki_page' do
|
|
|
|
assert_select 'title', :text => 'CookBook_documentation'
|
|
|
|
assert_select 'version', :text => '3'
|
|
|
|
assert_select 'text'
|
|
|
|
assert_select 'author'
|
2012-10-26 01:17:46 +04:00
|
|
|
assert_select 'comments'
|
2012-10-25 23:44:04 +04:00
|
|
|
assert_select 'created_on'
|
|
|
|
assert_select 'updated_on'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-26 00:44:37 +04:00
|
|
|
test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
|
|
|
|
get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
|
|
|
|
assert_response 200
|
|
|
|
assert_equal 'application/xml', response.content_type
|
|
|
|
assert_select 'wiki_page' do
|
|
|
|
assert_select 'title', :text => 'Page_with_an_inline_image'
|
|
|
|
assert_select 'attachments[type=array]' do
|
|
|
|
assert_select 'attachment' do
|
|
|
|
assert_select 'id', :text => '3'
|
|
|
|
assert_select 'filename', :text => 'logo.gif'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-25 23:44:04 +04:00
|
|
|
test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
|
|
|
|
get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
|
|
|
|
assert_response 404
|
|
|
|
assert_equal 'application/xml', response.content_type
|
|
|
|
end
|
|
|
|
|
|
|
|
test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
|
|
|
|
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
|
2012-10-26 00:38:29 +04:00
|
|
|
assert_response 200
|
2012-10-25 23:44:04 +04:00
|
|
|
assert_equal 'application/xml', response.content_type
|
|
|
|
assert_select 'wiki_page' do
|
|
|
|
assert_select 'title', :text => 'CookBook_documentation'
|
|
|
|
assert_select 'version', :text => '2'
|
|
|
|
assert_select 'text'
|
|
|
|
assert_select 'author'
|
|
|
|
assert_select 'created_on'
|
|
|
|
assert_select 'updated_on'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
|
|
|
|
Role.anonymous.remove_permission! :view_wiki_edits
|
|
|
|
|
|
|
|
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
|
|
|
|
assert_response 401
|
|
|
|
assert_equal 'application/xml', response.content_type
|
|
|
|
end
|
2012-10-26 00:38:29 +04:00
|
|
|
|
|
|
|
test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
|
|
|
|
assert_no_difference 'WikiPage.count' do
|
|
|
|
assert_difference 'WikiContent::Version.count' do
|
|
|
|
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
|
|
|
|
{:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
|
|
|
|
credentials('jsmith')
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
page = WikiPage.find(1)
|
|
|
|
assert_equal 'New content from API', page.content.text
|
|
|
|
assert_equal 4, page.content.version
|
|
|
|
assert_equal 'API update', page.content.comments
|
|
|
|
assert_equal 'jsmith', page.content.author.login
|
|
|
|
end
|
|
|
|
|
|
|
|
test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
|
|
|
|
assert_no_difference 'WikiPage.count' do
|
|
|
|
assert_difference 'WikiContent::Version.count' do
|
|
|
|
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
|
|
|
|
{:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
|
|
|
|
credentials('jsmith')
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
page = WikiPage.find(1)
|
|
|
|
assert_equal 'New content from API', page.content.text
|
|
|
|
assert_equal 4, page.content.version
|
|
|
|
assert_equal 'API update', page.content.comments
|
|
|
|
assert_equal 'jsmith', page.content.author.login
|
|
|
|
end
|
|
|
|
|
|
|
|
test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
|
|
|
|
assert_no_difference 'WikiPage.count' do
|
|
|
|
assert_no_difference 'WikiContent::Version.count' do
|
|
|
|
put '/projects/ecookbook/wiki/CookBook_documentation.xml',
|
|
|
|
{:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
|
|
|
|
credentials('jsmith')
|
|
|
|
assert_response 409
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
|
|
|
|
assert_difference 'WikiPage.count' do
|
|
|
|
assert_difference 'WikiContent::Version.count' do
|
|
|
|
put '/projects/ecookbook/wiki/New_page_from_API.xml',
|
|
|
|
{:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
|
|
|
|
credentials('jsmith')
|
|
|
|
assert_response 201
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
page = WikiPage.order('id DESC').first
|
|
|
|
assert_equal 'New_page_from_API', page.title
|
|
|
|
assert_equal 'New content from API', page.content.text
|
|
|
|
assert_equal 1, page.content.version
|
|
|
|
assert_equal 'API create', page.content.comments
|
|
|
|
assert_equal 'jsmith', page.content.author.login
|
|
|
|
assert_nil page.parent
|
|
|
|
end
|
|
|
|
|
|
|
|
test "PUT /projects/:project_id/wiki/:title.xml with parent" do
|
|
|
|
assert_difference 'WikiPage.count' do
|
|
|
|
assert_difference 'WikiContent::Version.count' do
|
|
|
|
put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
|
|
|
|
{:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
|
|
|
|
credentials('jsmith')
|
|
|
|
assert_response 201
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
page = WikiPage.order('id DESC').first
|
|
|
|
assert_equal 'New_subpage_from_API', page.title
|
|
|
|
assert_equal WikiPage.find(1), page.parent
|
|
|
|
end
|
2012-10-29 00:17:38 +04:00
|
|
|
|
|
|
|
test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
|
|
|
|
assert_difference 'WikiPage.count', -1 do
|
|
|
|
delete '/projects/ecookbook/wiki/CookBook_documentation.xml', {}, credentials('jsmith')
|
|
|
|
assert_response 200
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nil WikiPage.find_by_id(1)
|
|
|
|
end
|
2012-10-25 23:44:04 +04:00
|
|
|
end
|