To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / e0 / e03b3539b5eda7cb68bffc68e4f6d9f643e92475.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (25.6 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 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 |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
| 19 |
require 'wiki_controller' |
| 20 |
|
| 21 |
# Re-raise errors caught by the controller. |
| 22 |
class WikiController; def rescue_action(e) raise e end; end |
| 23 |
|
| 24 |
class WikiControllerTest < ActionController::TestCase |
| 25 |
fixtures :projects, :users, :roles, :members, :member_roles, |
| 26 |
:enabled_modules, :wikis, :wiki_pages, :wiki_contents, |
| 27 |
:wiki_content_versions, :attachments |
| 28 |
|
| 29 |
def setup |
| 30 |
@controller = WikiController.new |
| 31 |
@request = ActionController::TestRequest.new |
| 32 |
@response = ActionController::TestResponse.new |
| 33 |
User.current = nil |
| 34 |
end |
| 35 |
|
| 36 |
def test_show_start_page |
| 37 |
get :show, :project_id => 'ecookbook' |
| 38 |
assert_response :success |
| 39 |
assert_template 'show' |
| 40 |
assert_tag :tag => 'h1', :content => /CookBook documentation/ |
| 41 |
|
| 42 |
# child_pages macro |
| 43 |
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
| 44 |
:child => { :tag => 'li',
|
| 45 |
:child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
|
| 46 |
:content => 'Page with an inline image' } } |
| 47 |
end |
| 48 |
|
| 49 |
def test_export_link |
| 50 |
Role.anonymous.add_permission! :export_wiki_pages |
| 51 |
get :show, :project_id => 'ecookbook' |
| 52 |
assert_response :success |
| 53 |
assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'}
|
| 54 |
end |
| 55 |
|
| 56 |
def test_show_page_with_name |
| 57 |
get :show, :project_id => 1, :id => 'Another_page' |
| 58 |
assert_response :success |
| 59 |
assert_template 'show' |
| 60 |
assert_tag :tag => 'h1', :content => /Another page/ |
| 61 |
# Included page with an inline image |
| 62 |
assert_tag :tag => 'p', :content => /This is an inline image/ |
| 63 |
assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
|
| 64 |
:alt => 'This is a logo' } |
| 65 |
end |
| 66 |
|
| 67 |
def test_show_redirected_page |
| 68 |
WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') |
| 69 |
|
| 70 |
get :show, :project_id => 'ecookbook', :id => 'Old_title' |
| 71 |
assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
| 72 |
end |
| 73 |
|
| 74 |
def test_show_with_sidebar |
| 75 |
page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
| 76 |
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
| 77 |
page.save! |
| 78 |
|
| 79 |
get :show, :project_id => 1, :id => 'Another_page' |
| 80 |
assert_response :success |
| 81 |
assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
|
| 82 |
:content => /Side bar content for test_show_with_sidebar/ |
| 83 |
end |
| 84 |
|
| 85 |
def test_show_unexistent_page_without_edit_right |
| 86 |
get :show, :project_id => 1, :id => 'Unexistent page' |
| 87 |
assert_response 404 |
| 88 |
end |
| 89 |
|
| 90 |
def test_show_should_display_section_edit_links |
| 91 |
@request.session[:user_id] = 2 |
| 92 |
get :show, :project_id => 1, :id => 'Page with sections' |
| 93 |
assert_no_tag 'a', :attributes => {
|
| 94 |
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1' |
| 95 |
} |
| 96 |
assert_tag 'a', :attributes => {
|
| 97 |
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
| 98 |
} |
| 99 |
assert_tag 'a', :attributes => {
|
| 100 |
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' |
| 101 |
} |
| 102 |
end |
| 103 |
|
| 104 |
def test_show_current_version_should_display_section_edit_links |
| 105 |
@request.session[:user_id] = 2 |
| 106 |
get :show, :project_id => 1, :id => 'Page with sections', :version => 3 |
| 107 |
|
| 108 |
assert_tag 'a', :attributes => {
|
| 109 |
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
| 110 |
} |
| 111 |
end |
| 112 |
|
| 113 |
def test_show_old_version_should_not_display_section_edit_links |
| 114 |
@request.session[:user_id] = 2 |
| 115 |
get :show, :project_id => 1, :id => 'Page with sections', :version => 2 |
| 116 |
|
| 117 |
assert_no_tag 'a', :attributes => {
|
| 118 |
:href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' |
| 119 |
} |
| 120 |
end |
| 121 |
|
| 122 |
def test_show_unexistent_page_with_edit_right |
| 123 |
@request.session[:user_id] = 2 |
| 124 |
get :show, :project_id => 1, :id => 'Unexistent page' |
| 125 |
assert_response :success |
| 126 |
assert_template 'edit' |
| 127 |
end |
| 128 |
|
| 129 |
def test_create_page |
| 130 |
@request.session[:user_id] = 2 |
| 131 |
put :update, :project_id => 1, |
| 132 |
:id => 'New page', |
| 133 |
:content => {:comments => 'Created the page',
|
| 134 |
:text => "h1. New page\n\nThis is a new page", |
| 135 |
:version => 0} |
| 136 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page' |
| 137 |
page = Project.find(1).wiki.find_page('New page')
|
| 138 |
assert !page.new_record? |
| 139 |
assert_not_nil page.content |
| 140 |
assert_equal 'Created the page', page.content.comments |
| 141 |
end |
| 142 |
|
| 143 |
def test_create_page_with_attachments |
| 144 |
@request.session[:user_id] = 2 |
| 145 |
assert_difference 'WikiPage.count' do |
| 146 |
assert_difference 'Attachment.count' do |
| 147 |
put :update, :project_id => 1, |
| 148 |
:id => 'New page', |
| 149 |
:content => {:comments => 'Created the page',
|
| 150 |
:text => "h1. New page\n\nThis is a new page", |
| 151 |
:version => 0}, |
| 152 |
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
| 153 |
end |
| 154 |
end |
| 155 |
page = Project.find(1).wiki.find_page('New page')
|
| 156 |
assert_equal 1, page.attachments.count |
| 157 |
assert_equal 'testfile.txt', page.attachments.first.filename |
| 158 |
end |
| 159 |
|
| 160 |
def test_edit_page |
| 161 |
@request.session[:user_id] = 2 |
| 162 |
get :edit, :project_id => 'ecookbook', :id => 'Another_page' |
| 163 |
|
| 164 |
assert_response :success |
| 165 |
assert_template 'edit' |
| 166 |
|
| 167 |
assert_tag 'textarea', |
| 168 |
:attributes => { :name => 'content[text]' },
|
| 169 |
:content => WikiPage.find_by_title('Another_page').content.text
|
| 170 |
end |
| 171 |
|
| 172 |
def test_edit_section |
| 173 |
@request.session[:user_id] = 2 |
| 174 |
get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2 |
| 175 |
|
| 176 |
assert_response :success |
| 177 |
assert_template 'edit' |
| 178 |
|
| 179 |
page = WikiPage.find_by_title('Page_with_sections')
|
| 180 |
section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
| 181 |
|
| 182 |
assert_tag 'textarea', |
| 183 |
:attributes => { :name => 'content[text]' },
|
| 184 |
:content => section |
| 185 |
assert_tag 'input', |
| 186 |
:attributes => { :name => 'section', :type => 'hidden', :value => '2' }
|
| 187 |
assert_tag 'input', |
| 188 |
:attributes => { :name => 'section_hash', :type => 'hidden', :value => hash }
|
| 189 |
end |
| 190 |
|
| 191 |
def test_edit_invalid_section_should_respond_with_404 |
| 192 |
@request.session[:user_id] = 2 |
| 193 |
get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10 |
| 194 |
|
| 195 |
assert_response 404 |
| 196 |
end |
| 197 |
|
| 198 |
def test_update_page |
| 199 |
@request.session[:user_id] = 2 |
| 200 |
assert_no_difference 'WikiPage.count' do |
| 201 |
assert_no_difference 'WikiContent.count' do |
| 202 |
assert_difference 'WikiContent::Version.count' do |
| 203 |
put :update, :project_id => 1, |
| 204 |
:id => 'Another_page', |
| 205 |
:content => {
|
| 206 |
:comments => "my comments", |
| 207 |
:text => "edited", |
| 208 |
:version => 1 |
| 209 |
} |
| 210 |
end |
| 211 |
end |
| 212 |
end |
| 213 |
assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
| 214 |
|
| 215 |
page = Wiki.find(1).pages.find_by_title('Another_page')
|
| 216 |
assert_equal "edited", page.content.text |
| 217 |
assert_equal 2, page.content.version |
| 218 |
assert_equal "my comments", page.content.comments |
| 219 |
end |
| 220 |
|
| 221 |
def test_update_page_with_failure |
| 222 |
@request.session[:user_id] = 2 |
| 223 |
assert_no_difference 'WikiPage.count' do |
| 224 |
assert_no_difference 'WikiContent.count' do |
| 225 |
assert_no_difference 'WikiContent::Version.count' do |
| 226 |
put :update, :project_id => 1, |
| 227 |
:id => 'Another_page', |
| 228 |
:content => {
|
| 229 |
:comments => 'a' * 300, # failure here, comment is too long |
| 230 |
:text => 'edited', |
| 231 |
:version => 1 |
| 232 |
} |
| 233 |
end |
| 234 |
end |
| 235 |
end |
| 236 |
assert_response :success |
| 237 |
assert_template 'edit' |
| 238 |
|
| 239 |
assert_error_tag :descendant => {:content => /Comment is too long/}
|
| 240 |
assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited'
|
| 241 |
assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
|
| 242 |
end |
| 243 |
|
| 244 |
def test_update_stale_page_should_not_raise_an_error |
| 245 |
@request.session[:user_id] = 2 |
| 246 |
c = Wiki.find(1).find_page('Another_page').content
|
| 247 |
c.text = 'Previous text' |
| 248 |
c.save! |
| 249 |
assert_equal 2, c.version |
| 250 |
|
| 251 |
assert_no_difference 'WikiPage.count' do |
| 252 |
assert_no_difference 'WikiContent.count' do |
| 253 |
assert_no_difference 'WikiContent::Version.count' do |
| 254 |
put :update, :project_id => 1, |
| 255 |
:id => 'Another_page', |
| 256 |
:content => {
|
| 257 |
:comments => 'My comments', |
| 258 |
:text => 'Text should not be lost', |
| 259 |
:version => 1 |
| 260 |
} |
| 261 |
end |
| 262 |
end |
| 263 |
end |
| 264 |
assert_response :success |
| 265 |
assert_template 'edit' |
| 266 |
assert_tag :div, |
| 267 |
:attributes => { :class => /error/ },
|
| 268 |
:content => /Data has been updated by another user/ |
| 269 |
assert_tag 'textarea', |
| 270 |
:attributes => { :name => 'content[text]' },
|
| 271 |
:content => /Text should not be lost/ |
| 272 |
assert_tag 'input', |
| 273 |
:attributes => { :name => 'content[comments]', :value => 'My comments' }
|
| 274 |
|
| 275 |
c.reload |
| 276 |
assert_equal 'Previous text', c.text |
| 277 |
assert_equal 2, c.version |
| 278 |
end |
| 279 |
|
| 280 |
def test_update_section |
| 281 |
@request.session[:user_id] = 2 |
| 282 |
page = WikiPage.find_by_title('Page_with_sections')
|
| 283 |
section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
| 284 |
text = page.content.text |
| 285 |
|
| 286 |
assert_no_difference 'WikiPage.count' do |
| 287 |
assert_no_difference 'WikiContent.count' do |
| 288 |
assert_difference 'WikiContent::Version.count' do |
| 289 |
put :update, :project_id => 1, :id => 'Page_with_sections', |
| 290 |
:content => {
|
| 291 |
:text => "New section content", |
| 292 |
:version => 3 |
| 293 |
}, |
| 294 |
:section => 2, |
| 295 |
:section_hash => hash |
| 296 |
end |
| 297 |
end |
| 298 |
end |
| 299 |
assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
| 300 |
assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text |
| 301 |
end |
| 302 |
|
| 303 |
def test_update_section_should_allow_stale_page_update |
| 304 |
@request.session[:user_id] = 2 |
| 305 |
page = WikiPage.find_by_title('Page_with_sections')
|
| 306 |
section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) |
| 307 |
text = page.content.text |
| 308 |
|
| 309 |
assert_no_difference 'WikiPage.count' do |
| 310 |
assert_no_difference 'WikiContent.count' do |
| 311 |
assert_difference 'WikiContent::Version.count' do |
| 312 |
put :update, :project_id => 1, :id => 'Page_with_sections', |
| 313 |
:content => {
|
| 314 |
:text => "New section content", |
| 315 |
:version => 2 # Current version is 3 |
| 316 |
}, |
| 317 |
:section => 2, |
| 318 |
:section_hash => hash |
| 319 |
end |
| 320 |
end |
| 321 |
end |
| 322 |
assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections' |
| 323 |
page.reload |
| 324 |
assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text |
| 325 |
assert_equal 4, page.content.version |
| 326 |
end |
| 327 |
|
| 328 |
def test_update_section_should_not_allow_stale_section_update |
| 329 |
@request.session[:user_id] = 2 |
| 330 |
|
| 331 |
assert_no_difference 'WikiPage.count' do |
| 332 |
assert_no_difference 'WikiContent.count' do |
| 333 |
assert_no_difference 'WikiContent::Version.count' do |
| 334 |
put :update, :project_id => 1, :id => 'Page_with_sections', |
| 335 |
:content => {
|
| 336 |
:comments => 'My comments', |
| 337 |
:text => "Text should not be lost", |
| 338 |
:version => 3 |
| 339 |
}, |
| 340 |
:section => 2, |
| 341 |
:section_hash => Digest::MD5.hexdigest("wrong hash")
|
| 342 |
end |
| 343 |
end |
| 344 |
end |
| 345 |
assert_response :success |
| 346 |
assert_template 'edit' |
| 347 |
assert_tag :div, |
| 348 |
:attributes => { :class => /error/ },
|
| 349 |
:content => /Data has been updated by another user/ |
| 350 |
assert_tag 'textarea', |
| 351 |
:attributes => { :name => 'content[text]' },
|
| 352 |
:content => /Text should not be lost/ |
| 353 |
assert_tag 'input', |
| 354 |
:attributes => { :name => 'content[comments]', :value => 'My comments' }
|
| 355 |
end |
| 356 |
|
| 357 |
def test_preview |
| 358 |
@request.session[:user_id] = 2 |
| 359 |
xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
| 360 |
:content => { :comments => '',
|
| 361 |
:text => 'this is a *previewed text*', |
| 362 |
:version => 3 } |
| 363 |
assert_response :success |
| 364 |
assert_template 'common/_preview' |
| 365 |
assert_tag :tag => 'strong', :content => /previewed text/ |
| 366 |
end |
| 367 |
|
| 368 |
def test_preview_new_page |
| 369 |
@request.session[:user_id] = 2 |
| 370 |
xhr :post, :preview, :project_id => 1, :id => 'New page', |
| 371 |
:content => { :text => 'h1. New page',
|
| 372 |
:comments => '', |
| 373 |
:version => 0 } |
| 374 |
assert_response :success |
| 375 |
assert_template 'common/_preview' |
| 376 |
assert_tag :tag => 'h1', :content => /New page/ |
| 377 |
end |
| 378 |
|
| 379 |
def test_history |
| 380 |
get :history, :project_id => 1, :id => 'CookBook_documentation' |
| 381 |
assert_response :success |
| 382 |
assert_template 'history' |
| 383 |
assert_not_nil assigns(:versions) |
| 384 |
assert_equal 3, assigns(:versions).size |
| 385 |
assert_select "input[type=submit][name=commit]" |
| 386 |
end |
| 387 |
|
| 388 |
def test_history_with_one_version |
| 389 |
get :history, :project_id => 1, :id => 'Another_page' |
| 390 |
assert_response :success |
| 391 |
assert_template 'history' |
| 392 |
assert_not_nil assigns(:versions) |
| 393 |
assert_equal 1, assigns(:versions).size |
| 394 |
assert_select "input[type=submit][name=commit]", false |
| 395 |
end |
| 396 |
|
| 397 |
def test_diff |
| 398 |
get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 |
| 399 |
assert_response :success |
| 400 |
assert_template 'diff' |
| 401 |
assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
|
| 402 |
:content => /updated/ |
| 403 |
end |
| 404 |
|
| 405 |
def test_annotate |
| 406 |
get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
| 407 |
assert_response :success |
| 408 |
assert_template 'annotate' |
| 409 |
|
| 410 |
# Line 1 |
| 411 |
assert_tag :tag => 'tr', :child => {
|
| 412 |
:tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
|
| 413 |
:tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
|
| 414 |
:tag => 'td', :content => /h1\. CookBook documentation/ |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
# Line 5 |
| 420 |
assert_tag :tag => 'tr', :child => {
|
| 421 |
:tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
|
| 422 |
:tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/, :sibling => {
|
| 423 |
:tag => 'td', :content => /Some updated \[\[documentation\]\] here/ |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
end |
| 428 |
|
| 429 |
def test_get_rename |
| 430 |
@request.session[:user_id] = 2 |
| 431 |
get :rename, :project_id => 1, :id => 'Another_page' |
| 432 |
assert_response :success |
| 433 |
assert_template 'rename' |
| 434 |
assert_tag 'option', |
| 435 |
:attributes => {:value => ''},
|
| 436 |
:content => '', |
| 437 |
:parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
| 438 |
assert_no_tag 'option', |
| 439 |
:attributes => {:selected => 'selected'},
|
| 440 |
:parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
| 441 |
end |
| 442 |
|
| 443 |
def test_get_rename_child_page |
| 444 |
@request.session[:user_id] = 2 |
| 445 |
get :rename, :project_id => 1, :id => 'Child_1' |
| 446 |
assert_response :success |
| 447 |
assert_template 'rename' |
| 448 |
assert_tag 'option', |
| 449 |
:attributes => {:value => ''},
|
| 450 |
:content => '', |
| 451 |
:parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
|
| 452 |
assert_tag 'option', |
| 453 |
:attributes => {:value => '2', :selected => 'selected'},
|
| 454 |
:content => /Another page/, |
| 455 |
:parent => {
|
| 456 |
:tag => 'select', |
| 457 |
:attributes => {:name => 'wiki_page[parent_id]'}
|
| 458 |
} |
| 459 |
end |
| 460 |
|
| 461 |
def test_rename_with_redirect |
| 462 |
@request.session[:user_id] = 2 |
| 463 |
post :rename, :project_id => 1, :id => 'Another_page', |
| 464 |
:wiki_page => { :title => 'Another renamed page',
|
| 465 |
:redirect_existing_links => 1 } |
| 466 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
| 467 |
wiki = Project.find(1).wiki |
| 468 |
# Check redirects |
| 469 |
assert_not_nil wiki.find_page('Another page')
|
| 470 |
assert_nil wiki.find_page('Another page', :with_redirect => false)
|
| 471 |
end |
| 472 |
|
| 473 |
def test_rename_without_redirect |
| 474 |
@request.session[:user_id] = 2 |
| 475 |
post :rename, :project_id => 1, :id => 'Another_page', |
| 476 |
:wiki_page => { :title => 'Another renamed page',
|
| 477 |
:redirect_existing_links => "0" } |
| 478 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
| 479 |
wiki = Project.find(1).wiki |
| 480 |
# Check that there's no redirects |
| 481 |
assert_nil wiki.find_page('Another page')
|
| 482 |
end |
| 483 |
|
| 484 |
def test_rename_with_parent_assignment |
| 485 |
@request.session[:user_id] = 2 |
| 486 |
post :rename, :project_id => 1, :id => 'Another_page', |
| 487 |
:wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
|
| 488 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
| 489 |
assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
|
| 490 |
end |
| 491 |
|
| 492 |
def test_rename_with_parent_unassignment |
| 493 |
@request.session[:user_id] = 2 |
| 494 |
post :rename, :project_id => 1, :id => 'Child_1', |
| 495 |
:wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
|
| 496 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
| 497 |
assert_nil WikiPage.find_by_title('Child_1').parent
|
| 498 |
end |
| 499 |
|
| 500 |
def test_destroy_child |
| 501 |
@request.session[:user_id] = 2 |
| 502 |
delete :destroy, :project_id => 1, :id => 'Child_1' |
| 503 |
assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 504 |
end |
| 505 |
|
| 506 |
def test_destroy_parent |
| 507 |
@request.session[:user_id] = 2 |
| 508 |
assert_no_difference('WikiPage.count') do
|
| 509 |
delete :destroy, :project_id => 1, :id => 'Another_page' |
| 510 |
end |
| 511 |
assert_response :success |
| 512 |
assert_template 'destroy' |
| 513 |
end |
| 514 |
|
| 515 |
def test_destroy_parent_with_nullify |
| 516 |
@request.session[:user_id] = 2 |
| 517 |
assert_difference('WikiPage.count', -1) do
|
| 518 |
delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
| 519 |
end |
| 520 |
assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 521 |
assert_nil WikiPage.find_by_id(2) |
| 522 |
end |
| 523 |
|
| 524 |
def test_destroy_parent_with_cascade |
| 525 |
@request.session[:user_id] = 2 |
| 526 |
assert_difference('WikiPage.count', -3) do
|
| 527 |
delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
| 528 |
end |
| 529 |
assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 530 |
assert_nil WikiPage.find_by_id(2) |
| 531 |
assert_nil WikiPage.find_by_id(5) |
| 532 |
end |
| 533 |
|
| 534 |
def test_destroy_parent_with_reassign |
| 535 |
@request.session[:user_id] = 2 |
| 536 |
assert_difference('WikiPage.count', -1) do
|
| 537 |
delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
| 538 |
end |
| 539 |
assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
| 540 |
assert_nil WikiPage.find_by_id(2) |
| 541 |
assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
| 542 |
end |
| 543 |
|
| 544 |
def test_index |
| 545 |
get :index, :project_id => 'ecookbook' |
| 546 |
assert_response :success |
| 547 |
assert_template 'index' |
| 548 |
pages = assigns(:pages) |
| 549 |
assert_not_nil pages |
| 550 |
assert_equal Project.find(1).wiki.pages.size, pages.size |
| 551 |
assert_equal pages.first.content.updated_on, pages.first.updated_on |
| 552 |
|
| 553 |
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
| 554 |
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
|
| 555 |
:content => 'CookBook documentation' }, |
| 556 |
:child => { :tag => 'ul',
|
| 557 |
:child => { :tag => 'li',
|
| 558 |
:child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
|
| 559 |
:content => 'Page with an inline image' } } } }, |
| 560 |
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
|
| 561 |
:content => 'Another page' } } |
| 562 |
end |
| 563 |
|
| 564 |
def test_index_should_include_atom_link |
| 565 |
get :index, :project_id => 'ecookbook' |
| 566 |
assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
|
| 567 |
end |
| 568 |
|
| 569 |
context "GET :export" do |
| 570 |
context "with an authorized user to export the wiki" do |
| 571 |
setup do |
| 572 |
@request.session[:user_id] = 2 |
| 573 |
get :export, :project_id => 'ecookbook' |
| 574 |
end |
| 575 |
|
| 576 |
should_respond_with :success |
| 577 |
should_assign_to :pages |
| 578 |
should_respond_with_content_type "text/html" |
| 579 |
should "export all of the wiki pages to a single html file" do |
| 580 |
assert_select "a[name=?]", "CookBook_documentation" |
| 581 |
assert_select "a[name=?]", "Another_page" |
| 582 |
assert_select "a[name=?]", "Page_with_an_inline_image" |
| 583 |
end |
| 584 |
|
| 585 |
end |
| 586 |
|
| 587 |
context "with an unauthorized user" do |
| 588 |
setup do |
| 589 |
get :export, :project_id => 'ecookbook' |
| 590 |
|
| 591 |
should_respond_with :redirect |
| 592 |
should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :id => nil} }
|
| 593 |
end |
| 594 |
end |
| 595 |
end |
| 596 |
|
| 597 |
context "GET :date_index" do |
| 598 |
setup do |
| 599 |
get :date_index, :project_id => 'ecookbook' |
| 600 |
end |
| 601 |
|
| 602 |
should_respond_with :success |
| 603 |
should_assign_to :pages |
| 604 |
should_assign_to :pages_by_date |
| 605 |
should_render_template 'wiki/date_index' |
| 606 |
|
| 607 |
should "include atom link" do |
| 608 |
assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
|
| 609 |
end |
| 610 |
end |
| 611 |
|
| 612 |
def test_not_found |
| 613 |
get :show, :project_id => 999 |
| 614 |
assert_response 404 |
| 615 |
end |
| 616 |
|
| 617 |
def test_protect_page |
| 618 |
page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
| 619 |
assert !page.protected? |
| 620 |
@request.session[:user_id] = 2 |
| 621 |
post :protect, :project_id => 1, :id => page.title, :protected => '1' |
| 622 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
| 623 |
assert page.reload.protected? |
| 624 |
end |
| 625 |
|
| 626 |
def test_unprotect_page |
| 627 |
page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
| 628 |
assert page.protected? |
| 629 |
@request.session[:user_id] = 2 |
| 630 |
post :protect, :project_id => 1, :id => page.title, :protected => '0' |
| 631 |
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
| 632 |
assert !page.reload.protected? |
| 633 |
end |
| 634 |
|
| 635 |
def test_show_page_with_edit_link |
| 636 |
@request.session[:user_id] = 2 |
| 637 |
get :show, :project_id => 1 |
| 638 |
assert_response :success |
| 639 |
assert_template 'show' |
| 640 |
assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
|
| 641 |
end |
| 642 |
|
| 643 |
def test_show_page_without_edit_link |
| 644 |
@request.session[:user_id] = 4 |
| 645 |
get :show, :project_id => 1 |
| 646 |
assert_response :success |
| 647 |
assert_template 'show' |
| 648 |
assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
|
| 649 |
end |
| 650 |
|
| 651 |
def test_show_pdf |
| 652 |
@request.session[:user_id] = 2 |
| 653 |
get :show, :project_id => 1, :format => 'pdf' |
| 654 |
assert_response :success |
| 655 |
assert_not_nil assigns(:page) |
| 656 |
assert_equal 'application/pdf', @response.content_type |
| 657 |
assert_equal 'attachment; filename="CookBook_documentation.pdf"', |
| 658 |
@response.headers['Content-Disposition'] |
| 659 |
end |
| 660 |
|
| 661 |
def test_show_html |
| 662 |
@request.session[:user_id] = 2 |
| 663 |
get :show, :project_id => 1, :format => 'html' |
| 664 |
assert_response :success |
| 665 |
assert_not_nil assigns(:page) |
| 666 |
assert_equal 'text/html', @response.content_type |
| 667 |
assert_equal 'attachment; filename="CookBook_documentation.html"', |
| 668 |
@response.headers['Content-Disposition'] |
| 669 |
end |
| 670 |
|
| 671 |
def test_show_txt |
| 672 |
@request.session[:user_id] = 2 |
| 673 |
get :show, :project_id => 1, :format => 'txt' |
| 674 |
assert_response :success |
| 675 |
assert_not_nil assigns(:page) |
| 676 |
assert_equal 'text/plain', @response.content_type |
| 677 |
assert_equal 'attachment; filename="CookBook_documentation.txt"', |
| 678 |
@response.headers['Content-Disposition'] |
| 679 |
end |
| 680 |
|
| 681 |
def test_edit_unprotected_page |
| 682 |
# Non members can edit unprotected wiki pages |
| 683 |
@request.session[:user_id] = 4 |
| 684 |
get :edit, :project_id => 1, :id => 'Another_page' |
| 685 |
assert_response :success |
| 686 |
assert_template 'edit' |
| 687 |
end |
| 688 |
|
| 689 |
def test_edit_protected_page_by_nonmember |
| 690 |
# Non members can't edit protected wiki pages |
| 691 |
@request.session[:user_id] = 4 |
| 692 |
get :edit, :project_id => 1, :id => 'CookBook_documentation' |
| 693 |
assert_response 403 |
| 694 |
end |
| 695 |
|
| 696 |
def test_edit_protected_page_by_member |
| 697 |
@request.session[:user_id] = 2 |
| 698 |
get :edit, :project_id => 1, :id => 'CookBook_documentation' |
| 699 |
assert_response :success |
| 700 |
assert_template 'edit' |
| 701 |
end |
| 702 |
|
| 703 |
def test_history_of_non_existing_page_should_return_404 |
| 704 |
get :history, :project_id => 1, :id => 'Unknown_page' |
| 705 |
assert_response 404 |
| 706 |
end |
| 707 |
end |