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 42KB

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