You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wiki_controller_test.rb 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class WikiControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  21. :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
  22. :wiki_content_versions, :attachments,
  23. :issues, :issue_statuses, :trackers, :watchers
  24. def setup
  25. User.current = nil
  26. end
  27. def test_show_start_page
  28. with_settings :text_formatting => 'textile' do
  29. get :show, :params => {:project_id => 'ecookbook'}
  30. assert_response :success
  31. assert_select 'h1', :text => /CookBook documentation/
  32. # child_pages macro
  33. assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image',
  34. :text => 'Page with an inline image'
  35. end
  36. end
  37. def test_export_link
  38. Role.anonymous.add_permission! :export_wiki_pages
  39. get :show, :params => {:project_id => 'ecookbook'}
  40. assert_response :success
  41. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation.txt'
  42. end
  43. def test_edit_sidebar_link
  44. Role.anonymous.add_permission! :edit_wiki_pages
  45. Role.anonymous.add_permission! :protect_wiki_pages
  46. get :show, :params => {:project_id => 'ecookbook'}
  47. assert_response :success
  48. assert_select 'a[href=?]', '/projects/ecookbook/wiki/sidebar/edit'
  49. end
  50. def test_show_page_with_name
  51. with_settings :text_formatting => 'textile' do
  52. get :show, :params => {:project_id => 1, :id => 'Another_page'}
  53. assert_response :success
  54. assert_select 'h1', :text => /Another page/
  55. # Included page with an inline image
  56. assert_select 'p', :text => /This is an inline image/
  57. assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo'
  58. end
  59. end
  60. def test_show_old_version
  61. with_settings :default_language => 'en' do
  62. get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'}
  63. end
  64. assert_response :success
  65. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/
  66. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/
  67. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/
  68. end
  69. def test_show_old_version_with_attachments
  70. page = WikiPage.find(4)
  71. assert page.attachments.any?
  72. content = page.content
  73. content.text = "update"
  74. content.save!
  75. get :show, :params => {:project_id => 'ecookbook', :id => page.title, :version => '1'}
  76. assert_response :success
  77. end
  78. def test_show_old_version_without_permission_should_be_denied
  79. Role.anonymous.remove_permission! :view_wiki_edits
  80. get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'}
  81. assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2'
  82. end
  83. def test_show_first_version
  84. with_settings :default_language => 'en' do
  85. get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'}
  86. end
  87. assert_response :success
  88. assert_select 'a', :text => /Previous/, :count => 0
  89. assert_select 'a', :text => /diff/, :count => 0
  90. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/
  91. end
  92. def test_show_redirected_page
  93. WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
  94. get :show, :params => {:project_id => 'ecookbook', :id => 'Old_title'}
  95. assert_redirected_to '/projects/ecookbook/wiki/Another_page'
  96. end
  97. def test_show_with_sidebar
  98. page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
  99. page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
  100. page.save!
  101. get :show, :params => {:project_id => 1, :id => 'Another_page'}
  102. assert_response :success
  103. assert_select 'div#sidebar', :text => /Side bar content for test_show_with_sidebar/
  104. end
  105. def test_show_should_display_watchers
  106. @request.session[:user_id] = 2
  107. page = Project.find(1).wiki.find_page('Another_page')
  108. page.add_watcher User.find(2)
  109. page.add_watcher Group.find(10)
  110. [['1', true], ['0', false]].each do |(gravatar_enabled, is_display_gravatar)|
  111. with_settings :gravatar_enabled => gravatar_enabled do
  112. get :show, :params => {:project_id => 1, :id => 'Another_page'}
  113. end
  114. assert_select 'div#watchers ul' do
  115. assert_select 'li.user-2' do
  116. assert_select 'img.gravatar[title=?]', 'John Smith', is_display_gravatar
  117. assert_select 'a[href="/users/2"]'
  118. assert_select 'a[class*=delete]'
  119. end
  120. assert_select 'li.user-10' do
  121. assert_select 'img.gravatar[title=?]', 'A Team', is_display_gravatar
  122. assert_select 'a[href="/users/10"]', false
  123. assert_select 'a[class*=delete]'
  124. end
  125. end
  126. end
  127. end
  128. def test_show_should_display_section_edit_links
  129. with_settings :text_formatting => 'textile' do
  130. @request.session[:user_id] = 2
  131. get :show, :params => {:project_id => 1, :id => 'Page with sections'}
  132. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0
  133. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
  134. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
  135. end
  136. end
  137. def test_show_current_version_should_display_section_edit_links
  138. with_settings :text_formatting => 'textile' do
  139. @request.session[:user_id] = 2
  140. get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3}
  141. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
  142. end
  143. end
  144. def test_show_old_version_should_not_display_section_edit_links
  145. @request.session[:user_id] = 2
  146. get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 2}
  147. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2', 0
  148. end
  149. def test_show_unexistent_page_without_edit_right
  150. get :show, :params => {:project_id => 1, :id => 'Unexistent page'}
  151. assert_response 404
  152. end
  153. def test_show_unexistent_page_with_edit_right
  154. @request.session[:user_id] = 2
  155. get :show, :params => {:project_id => 1, :id => 'Unexistent page'}
  156. assert_response :success
  157. assert_select 'textarea[name=?]', 'content[text]'
  158. end
  159. def test_show_specific_version_of_an_unexistent_page_without_edit_right
  160. get :show, :params => {:project_id => 1, :id => 'Unexistent page', :version => 1}
  161. assert_response 404
  162. end
  163. def test_show_unexistent_page_with_parent_should_preselect_parent
  164. @request.session[:user_id] = 2
  165. get :show, :params => {:project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'}
  166. assert_response :success
  167. assert_select 'select[name=?] option[value="2"][selected=selected]', 'wiki_page[parent_id]'
  168. end
  169. def test_show_unexistent_version_page
  170. @request.session[:user_id] = 2
  171. get :show, :params => {:project_id => 1, :id => 'CookBook_documentation', :version => 100}
  172. assert_response 404
  173. end
  174. def test_show_should_not_show_history_without_permission
  175. Role.anonymous.remove_permission! :view_wiki_edits
  176. get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 2}
  177. assert_response 302
  178. end
  179. def test_show_page_without_content_should_display_the_edit_form
  180. @request.session[:user_id] = 2
  181. WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
  182. get :show, :params => {:project_id => 1, :id => 'NoContent'}
  183. assert_response :success
  184. assert_select 'textarea[name=?]', 'content[text]'
  185. end
  186. def test_show_protected_page_shoud_show_locked_badge
  187. @request.session[:user_id] = 2
  188. get :show, :params => {:project_id => 1, :id => 'CookBook_documentation'}
  189. assert_select 'p.wiki-update-info' do
  190. assert_select 'span.badge.badge-status-locked'
  191. end
  192. end
  193. def test_get_new
  194. @request.session[:user_id] = 2
  195. get :new, :params => {:project_id => 'ecookbook'}
  196. assert_response :success
  197. assert_select 'input[name=?]', 'title'
  198. end
  199. def test_get_new_xhr
  200. @request.session[:user_id] = 2
  201. get :new, :params => {:project_id => 'ecookbook'}, :xhr => true
  202. assert_response :success
  203. assert_include 'Unallowed characters', response.body
  204. end
  205. def test_post_new_with_valid_title_should_redirect_to_edit
  206. @request.session[:user_id] = 2
  207. post :new, :params => {:project_id => 'ecookbook', :title => 'New Page'}
  208. assert_redirected_to '/projects/ecookbook/wiki/New_Page'
  209. end
  210. def test_post_new_xhr_with_valid_title_should_redirect_to_edit
  211. @request.session[:user_id] = 2
  212. post :new, :params => {:project_id => 'ecookbook', :title => 'New Page'}, :xhr => true
  213. assert_response :success
  214. assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body
  215. end
  216. def test_post_new_should_redirect_to_edit_with_parent
  217. @request.session[:user_id] = 2
  218. post :new, :params => {:project_id => 'ecookbook', :title => 'New_Page', :parent => 'Child_1'}
  219. assert_redirected_to '/projects/ecookbook/wiki/New_Page?parent=Child_1'
  220. end
  221. def test_post_new_with_invalid_title_should_display_errors
  222. @request.session[:user_id] = 2
  223. post :new, :params => {:project_id => 'ecookbook', :title => 'Another page'}
  224. assert_response :success
  225. assert_select_error 'Title has already been taken'
  226. end
  227. def test_post_new_with_protected_title_should_display_errors
  228. Role.find(1).remove_permission!(:protect_wiki_pages)
  229. @request.session[:user_id] = 2
  230. post :new, :params => {:project_id => 'ecookbook', :title => 'Sidebar'}
  231. assert_response :success
  232. assert_select_error /Title/
  233. end
  234. def test_post_new_xhr_with_invalid_title_should_display_errors
  235. @request.session[:user_id] = 2
  236. post :new, :params => {:project_id => 'ecookbook', :title => 'Another page'}, :xhr => true
  237. assert_response :success
  238. assert_include 'Title has already been taken', response.body
  239. end
  240. def test_create_page
  241. @request.session[:user_id] = 2
  242. assert_difference 'WikiPage.count' do
  243. assert_difference 'WikiContent.count' do
  244. put :update, :params => {
  245. :project_id => 1,
  246. :id => 'New page',
  247. :content => {
  248. :comments => 'Created the page',
  249. :text => "h1. New page\n\nThis is a new page",
  250. :version => 0
  251. }
  252. }
  253. end
  254. end
  255. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
  256. page = Project.find(1).wiki.find_page('New page')
  257. assert !page.new_record?
  258. assert_not_nil page.content
  259. assert_nil page.parent
  260. assert_equal 'Created the page', page.content.comments
  261. end
  262. def test_create_page_with_attachments
  263. set_tmp_attachments_directory
  264. @request.session[:user_id] = 2
  265. assert_difference 'WikiPage.count' do
  266. assert_difference 'Attachment.count' do
  267. put :update, :params => {
  268. :project_id => 1,
  269. :id => 'New page',
  270. :content => {
  271. :comments => 'Created the page',
  272. :text => "h1. New page\n\nThis is a new page",
  273. :version => 0
  274. },
  275. :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
  276. }
  277. end
  278. end
  279. page = Project.find(1).wiki.find_page('New page')
  280. assert_equal 1, page.attachments.count
  281. assert_equal 'testfile.txt', page.attachments.first.filename
  282. end
  283. def test_create_page_with_parent
  284. @request.session[:user_id] = 2
  285. assert_difference 'WikiPage.count' do
  286. put :update, :params => {
  287. :project_id => 1,
  288. :id => 'New page',
  289. :content => {
  290. :text => "h1. New page\n\nThis is a new page",
  291. :version => 0
  292. },
  293. :wiki_page => {:parent_id => 2}
  294. }
  295. end
  296. page = Project.find(1).wiki.find_page('New page')
  297. assert_equal WikiPage.find(2), page.parent
  298. end
  299. def test_edit_page
  300. @request.session[:user_id] = 2
  301. get :edit, :params => {:project_id => 'ecookbook', :id => 'Another_page'}
  302. assert_response :success
  303. assert_select 'textarea[name=?]', 'content[text]',
  304. :text => WikiPage.find_by_title('Another_page').content.text
  305. end
  306. def test_edit_section
  307. with_settings :text_formatting => 'textile' do
  308. @request.session[:user_id] = 2
  309. get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2}
  310. assert_response :success
  311. page = WikiPage.find_by_title('Page_with_sections')
  312. section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
  313. assert_select 'textarea[name=?]', 'content[text]', :text => section
  314. assert_select 'input[name=section][type=hidden][value="2"]'
  315. assert_select 'input[name=section_hash][type=hidden][value=?]', hash
  316. end
  317. end
  318. def test_edit_invalid_section_should_respond_with_404
  319. @request.session[:user_id] = 2
  320. get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10}
  321. assert_response 404
  322. end
  323. def test_update_page
  324. @request.session[:user_id] = 2
  325. assert_no_difference 'WikiPage.count' do
  326. assert_no_difference 'WikiContent.count' do
  327. assert_difference 'WikiContentVersion.count' do
  328. put :update, :params => {
  329. :project_id => 1,
  330. :id => 'Another_page',
  331. :content => {
  332. :comments => "my comments",
  333. :text => "edited",
  334. :version => 1
  335. }
  336. }
  337. end
  338. end
  339. end
  340. assert_redirected_to '/projects/ecookbook/wiki/Another_page'
  341. page = Wiki.find(1).pages.find_by_title('Another_page')
  342. assert_equal "edited", page.content.text
  343. assert_equal 2, page.content.version
  344. assert_equal "my comments", page.content.comments
  345. end
  346. def test_update_page_with_parent
  347. @request.session[:user_id] = 2
  348. assert_no_difference 'WikiPage.count' do
  349. assert_no_difference 'WikiContent.count' do
  350. assert_difference 'WikiContentVersion.count' do
  351. put :update, :params => {
  352. :project_id => 1,
  353. :id => 'Another_page',
  354. :content => {
  355. :comments => "my comments",
  356. :text => "edited",
  357. :version => 1
  358. },
  359. :wiki_page => {:parent_id => '1'}
  360. }
  361. end
  362. end
  363. end
  364. assert_redirected_to '/projects/ecookbook/wiki/Another_page'
  365. page = Wiki.find(1).pages.find_by_title('Another_page')
  366. assert_equal "edited", page.content.text
  367. assert_equal 2, page.content.version
  368. assert_equal "my comments", page.content.comments
  369. assert_equal WikiPage.find(1), page.parent
  370. end
  371. def test_update_page_with_failure
  372. @request.session[:user_id] = 2
  373. assert_no_difference 'WikiPage.count' do
  374. assert_no_difference 'WikiContent.count' do
  375. assert_no_difference 'WikiContentVersion.count' do
  376. put :update, :params => {
  377. :project_id => 1,
  378. :id => 'Another_page',
  379. :content => {
  380. :comments => 'a' * 1300, # failure here, comment is too long
  381. :text => 'edited'
  382. },
  383. :wiki_page => {
  384. :parent_id => ""
  385. }
  386. }
  387. end
  388. end
  389. end
  390. assert_response :success
  391. assert_select_error /Comment is too long/
  392. assert_select 'textarea#content_text', :text => "edited"
  393. assert_select 'input#content_version[value="1"]'
  394. end
  395. def test_update_page_with_parent_change_only_should_not_create_content_version
  396. @request.session[:user_id] = 2
  397. assert_no_difference 'WikiPage.count' do
  398. assert_no_difference 'WikiContent.count' do
  399. assert_no_difference 'WikiContentVersion.count' do
  400. put :update, :params => {
  401. :project_id => 1,
  402. :id => 'Another_page',
  403. :content => {
  404. :comments => '',
  405. :text => Wiki.find(1).find_page('Another_page').content.text,
  406. :version => 1
  407. },
  408. :wiki_page => {:parent_id => '1'}
  409. }
  410. end
  411. end
  412. end
  413. page = Wiki.find(1).pages.find_by_title('Another_page')
  414. assert_equal 1, page.content.version
  415. assert_equal WikiPage.find(1), page.parent
  416. end
  417. def test_update_page_with_attachments_only_should_not_create_content_version
  418. set_tmp_attachments_directory
  419. @request.session[:user_id] = 2
  420. assert_no_difference 'WikiPage.count' do
  421. assert_no_difference 'WikiContent.count' do
  422. assert_no_difference 'WikiContentVersion.count' do
  423. assert_difference 'Attachment.count' do
  424. put :update, :params => {
  425. :project_id => 1,
  426. :id => 'Another_page',
  427. :content => {
  428. :comments => '',
  429. :text => Wiki.find(1).find_page('Another_page').content.text,
  430. :version => 1
  431. },
  432. :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
  433. }
  434. end
  435. end
  436. end
  437. end
  438. page = Wiki.find(1).pages.find_by_title('Another_page')
  439. assert_equal 1, page.content.version
  440. end
  441. def test_update_with_deleted_attachment_ids
  442. set_tmp_attachments_directory
  443. @request.session[:user_id] = 2
  444. page = WikiPage.find(4)
  445. attachment = page.attachments.first
  446. assert_difference 'Attachment.count', -1 do
  447. put :update, :params => {
  448. :project_id => page.wiki.project.id,
  449. :id => page.title,
  450. :content => {
  451. :comments => 'delete file',
  452. :text => 'edited'
  453. },
  454. :wiki_page => {:deleted_attachment_ids => [attachment.id]}
  455. }
  456. end
  457. page.reload
  458. refute_includes page.attachments, attachment
  459. end
  460. def test_update_with_deleted_attachment_ids_and_failure_should_preserve_selected_attachments
  461. set_tmp_attachments_directory
  462. @request.session[:user_id] = 2
  463. page = WikiPage.find(4)
  464. attachment = page.attachments.first
  465. assert_no_difference 'Attachment.count' do
  466. put :update, :params => {
  467. :project_id => page.wiki.project.id,
  468. :id => page.title,
  469. :content => {
  470. :comments => 'a' * 1300, # failure here, comment is too long
  471. :text => 'edited'
  472. },
  473. :wiki_page => {:deleted_attachment_ids => [attachment.id]}
  474. }
  475. end
  476. page.reload
  477. assert_includes page.attachments, attachment
  478. end
  479. def test_update_stale_page_should_not_raise_an_error
  480. @request.session[:user_id] = 2
  481. c = Wiki.find(1).find_page('Another_page').content
  482. c.text = 'Previous text'
  483. c.save!
  484. assert_equal 2, c.version
  485. assert_no_difference 'WikiPage.count' do
  486. assert_no_difference 'WikiContent.count' do
  487. assert_no_difference 'WikiContentVersion.count' do
  488. put :update, :params => {
  489. :project_id => 1,
  490. :id => 'Another_page',
  491. :content => {
  492. :comments => 'My comments',
  493. :text => 'Text should not be lost',
  494. :version => 1
  495. }
  496. }
  497. end
  498. end
  499. end
  500. assert_response :success
  501. assert_select 'div.error', :text => /Data has been updated by another user/
  502. assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
  503. assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
  504. c.reload
  505. assert_equal 'Previous text', c.text
  506. assert_equal 2, c.version
  507. end
  508. def test_update_page_without_content_should_create_content
  509. @request.session[:user_id] = 2
  510. page = WikiPage.create!(:title => 'NoContent', :wiki => Project.find(1).wiki)
  511. assert_no_difference 'WikiPage.count' do
  512. assert_difference 'WikiContent.count' do
  513. put :update, :params => {
  514. :project_id => 1,
  515. :id => 'NoContent',
  516. :content => {:text => 'Some content'}
  517. }
  518. assert_response 302
  519. end
  520. end
  521. assert_equal 'Some content', page.reload.content.text
  522. end
  523. def test_update_section
  524. with_settings :text_formatting => 'textile' do
  525. @request.session[:user_id] = 2
  526. page = WikiPage.find_by(title: 'Page_with_sections')
  527. section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
  528. text = page.content.text
  529. assert_no_difference 'WikiPage.count' do
  530. assert_no_difference 'WikiContent.count' do
  531. assert_difference 'WikiContentVersion.count' do
  532. put :update, :params => {
  533. :project_id => 1,
  534. :id => 'Page_with_sections',
  535. :content => {
  536. :text => 'New section content',
  537. :version => 3
  538. },
  539. :section => 2,
  540. :section_hash => hash
  541. }
  542. end
  543. end
  544. end
  545. assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
  546. assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.reload.content.text
  547. end
  548. end
  549. def test_update_section_should_allow_stale_page_update
  550. with_settings :text_formatting => 'textile' do
  551. @request.session[:user_id] = 2
  552. page = WikiPage.find_by(title: 'Page_with_sections')
  553. section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
  554. text = page.content.text
  555. assert_no_difference 'WikiPage.count' do
  556. assert_no_difference 'WikiContent.count' do
  557. assert_difference 'WikiContentVersion.count' do
  558. put :update, :params => {
  559. :project_id => 1,
  560. :id => 'Page_with_sections',
  561. :content => {
  562. :text => 'New section content',
  563. :version => 2 # Current version is 3
  564. },
  565. :section => 2,
  566. :section_hash => hash
  567. }
  568. end
  569. end
  570. end
  571. assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2'
  572. page.reload
  573. assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.content.text
  574. assert_equal 4, page.content.version
  575. end
  576. end
  577. def test_update_section_should_not_allow_stale_section_update
  578. @request.session[:user_id] = 2
  579. assert_no_difference 'WikiPage.count' do
  580. assert_no_difference 'WikiContent.count' do
  581. assert_no_difference 'WikiContentVersion.count' do
  582. put :update, :params => {
  583. :project_id => 1,
  584. :id => 'Page_with_sections',
  585. :content => {
  586. :comments => 'My comments',
  587. :text => "Text should not be lost",
  588. :version => 3
  589. },
  590. :section => 2,
  591. :section_hash => ActiveSupport::Digest.hexdigest("wrong hash")
  592. }
  593. end
  594. end
  595. end
  596. assert_response :success
  597. assert_select 'div.error', :text => /Data has been updated by another user/
  598. assert_select 'textarea[name=?]', 'content[text]', :text => /Text should not be lost/
  599. assert_select 'input[name=?][value=?]', 'content[comments]', 'My comments'
  600. end
  601. def test_preview
  602. with_settings :text_formatting => 'textile' do
  603. @request.session[:user_id] = 2
  604. post :preview, :params => {
  605. :project_id => 1,
  606. :id => 'CookBook_documentation',
  607. :content => {
  608. :comments => '',
  609. :text => 'this is a *previewed text*',
  610. :version => 3
  611. }
  612. }, :xhr => true
  613. assert_response :success
  614. assert_select 'strong', :text => /previewed text/
  615. end
  616. end
  617. def test_preview_new_page
  618. with_settings :text_formatting => 'textile' do
  619. @request.session[:user_id] = 2
  620. post :preview, :params => {
  621. :project_id => 1,
  622. :id => 'New page',
  623. :content => {
  624. :text => 'h1. New page',
  625. :comments => '',
  626. :version => 0
  627. }
  628. }, :xhr => true
  629. assert_response :success
  630. assert_select 'h1', :text => /New page/
  631. end
  632. end
  633. def test_history
  634. @request.session[:user_id] = 2
  635. get :history, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation'}
  636. assert_response :success
  637. assert_select 'table.wiki-page-versions tbody' do
  638. assert_select 'tr', 3
  639. end
  640. assert_select "input[type=submit][name=commit]"
  641. assert_select 'td' do
  642. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2'
  643. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate'
  644. assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete'
  645. end
  646. end
  647. def test_history_with_one_version
  648. @request.session[:user_id] = 2
  649. get :history, :params => {:project_id => 'ecookbook', :id => 'Another_page'}
  650. assert_response :success
  651. assert_select 'table.wiki-page-versions tbody' do
  652. assert_select 'tr', 1
  653. end
  654. assert_select "input[type=submit][name=commit]", false
  655. assert_select 'td' do
  656. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1'
  657. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate'
  658. assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0
  659. end
  660. end
  661. def test_diff
  662. content = WikiPage.find(1).content
  663. assert_difference 'WikiContentVersion.count', 2 do
  664. content.text = "Line removed\nThis is a sample text for testing diffs"
  665. content.save!
  666. content.text = "This is a sample text for testing diffs\nLine added"
  667. content.save!
  668. end
  669. get :diff, :params => {
  670. :project_id => 1, :id => 'CookBook_documentation',
  671. :version => content.version,
  672. :version_from => (content.version - 1)
  673. }
  674. assert_response :success
  675. assert_select 'span.diff_out', :text => 'Line removed'
  676. assert_select 'span.diff_in', :text => 'Line added'
  677. end
  678. def test_diff_with_invalid_version_should_respond_with_404
  679. get :diff, :params => {
  680. :project_id => 1, :id => 'CookBook_documentation',
  681. :version => '99'
  682. }
  683. assert_response 404
  684. end
  685. def test_diff_with_invalid_version_from_should_respond_with_404
  686. get :diff, :params => {
  687. :project_id => 1, :id => 'CookBook_documentation',
  688. :version => '99',
  689. :version_from => '98'
  690. }
  691. assert_response 404
  692. end
  693. def test_annotate
  694. get :annotate, :params => {
  695. :project_id => 1, :id => 'CookBook_documentation',
  696. :version => 2
  697. }
  698. assert_response :success
  699. # Line 1
  700. assert_select 'table.annotate tr:nth-child(1)' do
  701. assert_select 'th.line-num', :text => '1'
  702. assert_select 'td.author', :text => /Redmine Admin/
  703. assert_select 'td', :text => /h1\. CookBook documentation v2/
  704. end
  705. # Line 2
  706. assert_select 'table.annotate tr:nth-child(2)' do
  707. assert_select 'th.line-num', :text => '2'
  708. assert_select 'td.author', :text => /John Smith/
  709. end
  710. # Line 5
  711. assert_select 'table.annotate tr:nth-child(5)' do
  712. assert_select 'th.line-num', :text => '5'
  713. assert_select 'td.author', :text => /Redmine Admin/
  714. assert_select 'td', :text => /Some updated \[\[documentation\]\] here/
  715. end
  716. end
  717. def test_annotate_with_invalid_version_should_respond_with_404
  718. get :annotate, :params => {
  719. :project_id => 1, :id => 'CookBook_documentation',
  720. :version => '99'
  721. }
  722. assert_response 404
  723. end
  724. def test_get_rename
  725. @request.session[:user_id] = 2
  726. get :rename, :params => {:project_id => 1, :id => 'Another_page'}
  727. assert_response :success
  728. assert_select 'select[name=?]', 'wiki_page[parent_id]' do
  729. assert_select 'option[value=""]', :text => ''
  730. assert_select 'option[selected=selected]', 0
  731. end
  732. end
  733. def test_get_rename_child_page
  734. @request.session[:user_id] = 2
  735. get :rename, :params => {:project_id => 1, :id => 'Child_1'}
  736. assert_response :success
  737. assert_select 'select[name=?]', 'wiki_page[parent_id]' do
  738. assert_select 'option[value=""]', :text => ''
  739. assert_select 'option[value="2"][selected=selected]', :text => /Another page/
  740. end
  741. end
  742. def test_rename_with_redirect
  743. @request.session[:user_id] = 2
  744. post :rename, :params => {
  745. :project_id => 1,
  746. :id => 'Another_page',
  747. :wiki_page => {
  748. :title => 'Another renamed page',
  749. :redirect_existing_links => 1
  750. }
  751. }
  752. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
  753. wiki = Project.find(1).wiki
  754. # Check redirects
  755. assert_not_nil wiki.find_page('Another page')
  756. assert_nil wiki.find_page('Another page', :with_redirect => false)
  757. end
  758. def test_rename_without_redirect
  759. @request.session[:user_id] = 2
  760. post :rename, :params => {
  761. :project_id => 1,
  762. :id => 'Another_page',
  763. :wiki_page => {
  764. :title => 'Another renamed page',
  765. :redirect_existing_links => "0"
  766. }
  767. }
  768. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
  769. wiki = Project.find(1).wiki
  770. # Check that there's no redirects
  771. assert_nil wiki.find_page('Another page')
  772. end
  773. def test_rename_with_parent_assignment
  774. @request.session[:user_id] = 2
  775. post :rename, :params => {
  776. :project_id => 1,
  777. :id => 'Another_page',
  778. :wiki_page => {
  779. :title => 'Another page',
  780. :redirect_existing_links => "0",
  781. :parent_id => '4'
  782. }
  783. }
  784. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
  785. assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
  786. end
  787. def test_rename_with_parent_unassignment
  788. @request.session[:user_id] = 2
  789. post :rename, :params => {
  790. :project_id => 1,
  791. :id => 'Child_1',
  792. :wiki_page => {
  793. :title => 'Child 1',
  794. :redirect_existing_links => "0",
  795. :parent_id => ''
  796. }
  797. }
  798. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
  799. assert_nil WikiPage.find_by_title('Child_1').parent
  800. end
  801. def test_get_rename_should_show_target_projects_list
  802. @request.session[:user_id] = 2
  803. project = Project.find(5)
  804. project.enable_module! :wiki
  805. get :rename, :params => {:project_id => 1, :id => 'Another_page'}
  806. assert_response :success
  807. assert_select 'select[name=?]', 'wiki_page[wiki_id]' do
  808. assert_select 'option', 2
  809. assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/
  810. assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/
  811. end
  812. end
  813. def test_rename_with_move
  814. @request.session[:user_id] = 2
  815. project = Project.find(5)
  816. project.enable_module! :wiki
  817. post :rename, :params => {
  818. :project_id => 1,
  819. :id => 'Another_page',
  820. :wiki_page => {
  821. :wiki_id => project.wiki.id.to_s,
  822. :title => 'Another renamed page',
  823. :redirect_existing_links => 1
  824. }
  825. }
  826. assert_redirected_to '/projects/private-child/wiki/Another_renamed_page'
  827. page = WikiPage.find(2)
  828. assert_equal project.wiki.id, page.wiki_id
  829. end
  830. def test_rename_as_start_page
  831. @request.session[:user_id] = 2
  832. post :rename, :params => {
  833. :project_id => 'ecookbook',
  834. :id => 'Another_page',
  835. :wiki_page => {
  836. :wiki_id => '1',
  837. :title => 'Another_page',
  838. :redirect_existing_links => '1',
  839. :is_start_page => '1'
  840. }
  841. }
  842. assert_redirected_to '/projects/ecookbook/wiki/Another_page'
  843. wiki = Wiki.find(1)
  844. assert_equal 'Another_page', wiki.start_page
  845. end
  846. def test_destroy_a_page_without_children_should_not_ask_confirmation
  847. @request.session[:user_id] = 2
  848. delete :destroy, :params => {:project_id => 1, :id => 'Child_2'}
  849. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  850. assert_equal 'Successful deletion.', flash[:notice]
  851. end
  852. def test_destroy_parent_should_ask_confirmation
  853. @request.session[:user_id] = 2
  854. assert_no_difference('WikiPage.count') do
  855. delete :destroy, :params => {:project_id => 1, :id => 'Another_page'}
  856. end
  857. assert_response :success
  858. assert_select 'form' do
  859. assert_select 'input[name=todo][value=nullify]'
  860. assert_select 'input[name=todo][value=destroy]'
  861. assert_select 'input[name=todo][value=reassign]'
  862. end
  863. end
  864. def test_destroy_parent_with_nullify_should_delete_parent_only
  865. @request.session[:user_id] = 2
  866. assert_difference('WikiPage.count', -1) do
  867. delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'nullify'}
  868. end
  869. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  870. assert_equal 'Successful deletion.', flash[:notice]
  871. assert_nil WikiPage.find_by_id(2)
  872. end
  873. def test_destroy_parent_with_cascade_should_delete_descendants
  874. @request.session[:user_id] = 2
  875. assert_difference('WikiPage.count', -4) do
  876. delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'destroy'}
  877. end
  878. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  879. assert_equal 'Successful deletion.', flash[:notice]
  880. assert_nil WikiPage.find_by_id(2)
  881. assert_nil WikiPage.find_by_id(5)
  882. end
  883. def test_destroy_parent_with_reassign
  884. @request.session[:user_id] = 2
  885. assert_difference('WikiPage.count', -1) do
  886. delete :destroy, :params => {:project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1}
  887. end
  888. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  889. assert_equal 'Successful deletion.', flash[:notice]
  890. assert_nil WikiPage.find_by_id(2)
  891. assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
  892. end
  893. def test_destroy_version
  894. @request.session[:user_id] = 2
  895. assert_difference 'WikiContentVersion.count', -1 do
  896. assert_no_difference 'WikiContent.count' do
  897. assert_no_difference 'WikiPage.count' do
  898. delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2}
  899. assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history'
  900. end
  901. end
  902. end
  903. end
  904. def test_destroy_invalid_version_should_respond_with_404
  905. @request.session[:user_id] = 2
  906. assert_no_difference 'WikiContentVersion.count' do
  907. assert_no_difference 'WikiContent.count' do
  908. assert_no_difference 'WikiPage.count' do
  909. delete :destroy_version, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 99}
  910. end
  911. end
  912. end
  913. assert_response 404
  914. end
  915. def test_index
  916. get :index, :params => {:project_id => 'ecookbook'}
  917. assert_response :success
  918. assert_select 'ul.pages-hierarchy' do
  919. assert_select 'li', Project.find(1).wiki.pages.count
  920. end
  921. assert_select 'ul.pages-hierarchy' do
  922. assert_select 'li:nth-child(1) > a[href=?]', '/projects/ecookbook/wiki/Another_page', :text => 'Another page'
  923. assert_select 'li:nth-child(2)' do
  924. assert_select '> a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => 'CookBook documentation'
  925. assert_select 'ul li a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', :text => 'Page with an inline image'
  926. end
  927. end
  928. end
  929. def test_index_should_include_atom_link
  930. get :index, :params => {:project_id => 'ecookbook'}
  931. assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
  932. end
  933. def test_export_to_html
  934. @request.session[:user_id] = 2
  935. get :export, :params => {:project_id => 'ecookbook'}
  936. assert_response :success
  937. assert_equal "text/html", @response.media_type
  938. assert_select 'ul.pages-hierarchy' do
  939. assert_select 'li:nth-child(1) > a[href=?]', '#Another_page', :text => 'Another page'
  940. assert_select 'li:nth-child(2) > a[href=?]', '#CookBook_documentation', :text => 'CookBook documentation'
  941. assert_select 'li:nth-child(3) > a[href=?]', '#Page_with_sections', :text => 'Page with sections'
  942. end
  943. assert_select "a[name=?]", "CookBook_documentation"
  944. assert_select "a[name=?]", "Another_page"
  945. assert_select "a[name=?]", "Page_with_an_inline_image"
  946. end
  947. def test_export_to_pdf
  948. @request.session[:user_id] = 2
  949. get :export, :params => {:project_id => 'ecookbook', :format => 'pdf'}
  950. assert_response :success
  951. assert_equal 'application/pdf', @response.media_type
  952. assert_equal "attachment; filename=\"ecookbook.pdf\"; filename*=UTF-8''ecookbook.pdf", @response.headers['Content-Disposition']
  953. assert @response.body.starts_with?('%PDF')
  954. end
  955. def test_export_without_permission_should_be_denied
  956. @request.session[:user_id] = 2
  957. Role.find_by_name('Manager').remove_permission! :export_wiki_pages
  958. get :export, :params => {:project_id => 'ecookbook'}
  959. assert_response 403
  960. end
  961. def test_date_index
  962. get :date_index, :params => {:project_id => 'ecookbook'}
  963. assert_response :success
  964. assert_select 'a[href=?]', '/projects/ecookbook/activity.atom?show_wiki_edits=1'
  965. end
  966. def test_not_found
  967. get :show, :params => {:project_id => 999}
  968. assert_response 404
  969. end
  970. def test_protect_page
  971. page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
  972. assert !page.protected?
  973. @request.session[:user_id] = 2
  974. post :protect, :params => {:project_id => 1, :id => page.title, :protected => '1'}
  975. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
  976. assert page.reload.protected?
  977. end
  978. def test_unprotect_page
  979. page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
  980. assert page.protected?
  981. @request.session[:user_id] = 2
  982. post :protect, :params => {:project_id => 1, :id => page.title, :protected => '0'}
  983. assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
  984. assert !page.reload.protected?
  985. end
  986. def test_show_page_with_edit_link
  987. @request.session[:user_id] = 2
  988. get :show, :params => {:project_id => 1}
  989. assert_response :success
  990. assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit'
  991. end
  992. def test_show_page_without_edit_link
  993. @request.session[:user_id] = 4
  994. get :show, :params => {:project_id => 1}
  995. assert_response :success
  996. assert_select 'a[href=?]', '/projects/1/wiki/CookBook_documentation/edit', 0
  997. end
  998. def test_show_pdf
  999. @request.session[:user_id] = 2
  1000. get :show, :params => {:project_id => 1, :format => 'pdf'}
  1001. assert_response :success
  1002. assert_equal 'application/pdf', @response.media_type
  1003. assert_equal "attachment; filename=\"CookBook_documentation.pdf\"; filename*=UTF-8''CookBook_documentation.pdf",
  1004. @response.headers['Content-Disposition']
  1005. end
  1006. def test_show_html
  1007. with_settings :text_formatting => 'textile' do
  1008. @request.session[:user_id] = 2
  1009. get :show, :params => {:project_id => 1, :format => 'html'}
  1010. assert_response :success
  1011. assert_equal 'text/html', @response.media_type
  1012. assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html",
  1013. @response.headers['Content-Disposition']
  1014. assert_select 'h1', :text => /CookBook documentation/
  1015. end
  1016. end
  1017. def test_show_versioned_html
  1018. with_settings :text_formatting => 'textile' do
  1019. @request.session[:user_id] = 2
  1020. get :show, :params => {:project_id => 1, :format => 'html', :version => 2}
  1021. assert_response :success
  1022. assert_equal 'text/html', @response.media_type
  1023. assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html",
  1024. @response.headers['Content-Disposition']
  1025. assert_select 'h1', :text => /CookBook documentation v2/
  1026. end
  1027. end
  1028. def test_show_txt
  1029. @request.session[:user_id] = 2
  1030. get :show, :params => {:project_id => 1, :format => 'txt'}
  1031. assert_response :success
  1032. assert_equal 'text/plain', @response.media_type
  1033. assert_equal "attachment; filename=\"CookBook_documentation.txt\"; filename*=UTF-8''CookBook_documentation.txt",
  1034. @response.headers['Content-Disposition']
  1035. assert_include 'h1. CookBook documentation', @response.body
  1036. end
  1037. def test_show_versioned_txt
  1038. @request.session[:user_id] = 2
  1039. get :show, :params => {:project_id => 1, :format => 'txt', :version => 2}
  1040. assert_response :success
  1041. assert_equal 'text/plain', @response.media_type
  1042. assert_equal "attachment; filename=\"CookBook_documentation.txt\"; filename*=UTF-8''CookBook_documentation.txt",
  1043. @response.headers['Content-Disposition']
  1044. assert_include 'h1. CookBook documentation v2', @response.body
  1045. end
  1046. def test_show_filename_should_be_uri_encoded
  1047. @request.session[:user_id] = 2
  1048. title = 'Этика_менеджмента'
  1049. %w|pdf html txt|.each do |format|
  1050. # Non-MS browsers
  1051. @request.user_agent = ""
  1052. get :show, :params => {:project_id => 1, :id => title, :format => format}
  1053. assert_response :success
  1054. ascii_filename = "%3F%3F%3F%3F%3F_%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F%3F.#{format}"
  1055. utf8_filename = "%D0%AD%D1%82%D0%B8%D0%BA%D0%B0_%D0%BC%D0%B5%D0%BD%D0%B5%D0%B4%D0%B6%D0%BC%D0%B5%D0%BD%D1%82%D0%B0.#{format}"
  1056. assert_equal "attachment; filename=\"#{ascii_filename}\"; filename*=UTF-8''#{utf8_filename}",
  1057. @response.headers['Content-Disposition']
  1058. # Microsoft's browsers
  1059. @request.user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063'
  1060. get :show, :params => {:project_id => 1, :id => title, :format => format}
  1061. assert_response :success
  1062. assert_equal "attachment; filename=\"#{ascii_filename}\"; filename*=UTF-8''#{utf8_filename}",
  1063. @response.headers['Content-Disposition']
  1064. end
  1065. end
  1066. def test_edit_unprotected_page
  1067. # Non members can edit unprotected wiki pages
  1068. @request.session[:user_id] = 4
  1069. get :edit, :params => {:project_id => 1, :id => 'Another_page'}
  1070. assert_response :success
  1071. end
  1072. def test_edit_protected_page_by_nonmember
  1073. # Non members cannot edit protected wiki pages
  1074. @request.session[:user_id] = 4
  1075. get :edit, :params => {:project_id => 1, :id => 'CookBook_documentation'}
  1076. assert_response 403
  1077. end
  1078. def test_edit_protected_page_by_member
  1079. @request.session[:user_id] = 2
  1080. get :edit, :params => {:project_id => 1, :id => 'CookBook_documentation'}
  1081. assert_response :success
  1082. end
  1083. def test_history_of_non_existing_page_should_return_404
  1084. get :history, :params => {:project_id => 1, :id => 'Unknown_page'}
  1085. assert_response 404
  1086. end
  1087. def test_add_attachment
  1088. set_tmp_attachments_directory
  1089. @request.session[:user_id] = 2
  1090. assert_difference 'Attachment.count' do
  1091. post :add_attachment, :params => {
  1092. :project_id => 1,
  1093. :id => 'CookBook_documentation',
  1094. :attachments => {
  1095. '1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}
  1096. }
  1097. }
  1098. end
  1099. attachment = Attachment.order('id DESC').first
  1100. assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
  1101. end
  1102. def test_old_version_should_have_robot_exclusion_tag
  1103. @request.session[:user_id] = 2
  1104. # Discourage search engines from indexing old versions
  1105. get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'}
  1106. assert_response :success
  1107. assert_select 'head>meta[name="robots"][content=?]', 'noindex,follow,noarchive'
  1108. # No robots meta tag in the current version
  1109. get :show, :params => {:project_id => 'ecookbook', :id => 'CookBook_documentation'}
  1110. assert_response :success
  1111. assert_select 'head>meta[name="robots"]', false
  1112. end
  1113. end