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