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