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.

application_helper_test.rb 83KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 ApplicationHelperTest < Redmine::HelperTest
  20. include ERB::Util
  21. include Rails.application.routes.url_helpers
  22. fixtures :projects, :enabled_modules,
  23. :users, :email_addresses,
  24. :members, :member_roles, :roles,
  25. :repositories, :changesets,
  26. :projects_trackers,
  27. :trackers, :issue_statuses, :issues, :versions, :documents, :journals,
  28. :wikis, :wiki_pages, :wiki_contents,
  29. :boards, :messages, :news,
  30. :attachments, :enumerations,
  31. :custom_values, :custom_fields, :custom_fields_projects
  32. def setup
  33. super
  34. set_tmp_attachments_directory
  35. @russian_test = 'тест'
  36. end
  37. test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
  38. User.current = User.find_by_login('admin')
  39. @project = Issue.first.project # Used by helper
  40. response = link_to_if_authorized('By controller/actionr',
  41. {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
  42. assert_match /href/, response
  43. end
  44. test "#link_to_if_authorized for unauthorized user should display nothing if user isn't authorized" do
  45. User.current = User.find_by_login('dlopper')
  46. @project = Project.find('private-child')
  47. issue = @project.issues.first
  48. assert !issue.visible?
  49. response = link_to_if_authorized('Never displayed',
  50. {:controller => 'issues', :action => 'show', :id => issue})
  51. assert_nil response
  52. end
  53. def test_auto_links
  54. to_test = {
  55. 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
  56. 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
  57. 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
  58. 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
  59. 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
  60. 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
  61. 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
  62. 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
  63. '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)',
  64. '(see inline link : http://www.foo.bar/Test)' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>)',
  65. '(see inline link : http://www.foo.bar/Test).' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>).',
  66. '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
  67. '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
  68. '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
  69. 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
  70. 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
  71. 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
  72. 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
  73. 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
  74. 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
  75. 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
  76. 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
  77. # two exclamation marks
  78. 'http://example.net/path!602815048C7B5C20!302.html' => '<a class="external" href="http://example.net/path!602815048C7B5C20!302.html">http://example.net/path!602815048C7B5C20!302.html</a>',
  79. # escaping
  80. 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo&quot;bar</a>',
  81. # wrap in angle brackets
  82. '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;',
  83. # invalid urls
  84. 'http://' => 'http://',
  85. 'www.' => 'www.',
  86. 'test-www.bar.com' => 'test-www.bar.com',
  87. # ends with a hyphen
  88. 'http://www.redmine.org/example-' => '<a class="external" href="http://www.redmine.org/example-">http://www.redmine.org/example-</a>',
  89. }
  90. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  91. end
  92. def test_auto_links_with_non_ascii_characters
  93. to_test = {
  94. "http://foo.bar/#{@russian_test}" =>
  95. %|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
  96. }
  97. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  98. end
  99. def test_auto_mailto
  100. to_test = {
  101. 'test@foo.bar' => '<a class="email" href="mailto:test@foo.bar">test@foo.bar</a>',
  102. 'test@www.foo.bar' => '<a class="email" href="mailto:test@www.foo.bar">test@www.foo.bar</a>',
  103. }
  104. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  105. end
  106. def test_inline_images
  107. to_test = {
  108. '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
  109. 'floating !>http://foo.bar/image.jpg!' => 'floating <span style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></span>',
  110. 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="wiki-class-some-class" alt="" />',
  111. 'with class !(wiki-class-foo)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="wiki-class-foo" alt="" />',
  112. 'with style !{width:100px;height:100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height:100px;" alt="" />',
  113. 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />',
  114. 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" alt="This is a double-quoted &quot;title&quot;" />',
  115. }
  116. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  117. end
  118. def test_inline_images_inside_tags
  119. raw = <<-RAW
  120. h1. !foo.png! Heading
  121. Centered image:
  122. p=. !bar.gif!
  123. RAW
  124. assert textilizable(raw).include?('<img src="foo.png" alt="" />')
  125. assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
  126. end
  127. def test_attached_images
  128. to_test = {
  129. 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
  130. 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" />',
  131. 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
  132. 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
  133. # link image
  134. '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" /></a>',
  135. }
  136. attachments = Attachment.all
  137. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
  138. end
  139. def test_attached_images_with_textile_and_non_ascii_filename
  140. to_test = {
  141. 'CAFÉ.JPG' => 'CAF%C3%89.JPG',
  142. 'crème.jpg' => 'cr%C3%A8me.jpg',
  143. }
  144. with_settings :text_formatting => 'textile' do
  145. to_test.each do |filename, result|
  146. attachment = Attachment.generate!(:filename => filename)
  147. assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" />), textilizable("!#{filename}!", :attachments => [attachment])
  148. end
  149. end
  150. end
  151. def test_attached_images_with_markdown_and_non_ascii_filename
  152. skip unless Object.const_defined?(:Redcarpet)
  153. to_test = {
  154. 'CAFÉ.JPG' => 'CAF%C3%89.JPG',
  155. 'crème.jpg' => 'cr%C3%A8me.jpg',
  156. }
  157. with_settings :text_formatting => 'markdown' do
  158. to_test.each do |filename, result|
  159. attachment = Attachment.generate!(:filename => filename)
  160. assert_include %(<img src="/attachments/download/#{attachment.id}/#{result}" alt="" />), textilizable("![](#{filename})", :attachments => [attachment])
  161. end
  162. end
  163. end
  164. def test_attached_images_with_hires_naming
  165. attachment = Attachment.generate!(:filename => 'image@2x.png')
  166. assert_equal %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" /></p>),
  167. textilizable("!image@2x.png!", :attachments => [attachment])
  168. end
  169. def test_attached_images_filename_extension
  170. set_tmp_attachments_directory
  171. a1 = Attachment.new(
  172. :container => Issue.find(1),
  173. :file => mock_file_with_options({:original_filename => "testtest.JPG"}),
  174. :author => User.find(1))
  175. assert a1.save
  176. assert_equal "testtest.JPG", a1.filename
  177. assert_equal "image/jpeg", a1.content_type
  178. assert a1.image?
  179. a2 = Attachment.new(
  180. :container => Issue.find(1),
  181. :file => mock_file_with_options({:original_filename => "testtest.jpeg"}),
  182. :author => User.find(1))
  183. assert a2.save
  184. assert_equal "testtest.jpeg", a2.filename
  185. assert_equal "image/jpeg", a2.content_type
  186. assert a2.image?
  187. a3 = Attachment.new(
  188. :container => Issue.find(1),
  189. :file => mock_file_with_options({:original_filename => "testtest.JPE"}),
  190. :author => User.find(1))
  191. assert a3.save
  192. assert_equal "testtest.JPE", a3.filename
  193. assert_equal "image/jpeg", a3.content_type
  194. assert a3.image?
  195. a4 = Attachment.new(
  196. :container => Issue.find(1),
  197. :file => mock_file_with_options({:original_filename => "Testtest.BMP"}),
  198. :author => User.find(1))
  199. assert a4.save
  200. assert_equal "Testtest.BMP", a4.filename
  201. assert_equal "image/x-ms-bmp", a4.content_type
  202. assert a4.image?
  203. to_test = {
  204. 'Inline image: !testtest.jpg!' =>
  205. 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '/testtest.JPG" alt="" />',
  206. 'Inline image: !testtest.jpeg!' =>
  207. 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testtest.jpeg" alt="" />',
  208. 'Inline image: !testtest.jpe!' =>
  209. 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '/testtest.JPE" alt="" />',
  210. 'Inline image: !testtest.bmp!' =>
  211. 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '/Testtest.BMP" alt="" />',
  212. }
  213. attachments = [a1, a2, a3, a4]
  214. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
  215. end
  216. def test_attached_images_should_read_later
  217. set_fixtures_attachments_directory
  218. a1 = Attachment.find(16)
  219. assert_equal "testfile.png", a1.filename
  220. assert a1.readable?
  221. assert (! a1.visible?(User.anonymous))
  222. assert a1.visible?(User.find(2))
  223. a2 = Attachment.find(17)
  224. assert_equal "testfile.PNG", a2.filename
  225. assert a2.readable?
  226. assert (! a2.visible?(User.anonymous))
  227. assert a2.visible?(User.find(2))
  228. assert a1.created_on < a2.created_on
  229. to_test = {
  230. 'Inline image: !testfile.png!' =>
  231. 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
  232. 'Inline image: !Testfile.PNG!' =>
  233. 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" />',
  234. }
  235. attachments = [a1, a2]
  236. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
  237. set_tmp_attachments_directory
  238. end
  239. def test_textile_external_links
  240. to_test = {
  241. 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
  242. 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
  243. '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
  244. '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with &quot;double-quotes&quot;" class="external">link</a>',
  245. "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
  246. # no multiline link text
  247. "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />and another on a second line\":test",
  248. # mailto link
  249. "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
  250. # two exclamation marks
  251. '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
  252. # escaping
  253. '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
  254. # ends with a hyphen
  255. '(see "inline link":http://www.foo.bar/Test-)' => '(see <a href="http://www.foo.bar/Test-" class="external">inline link</a>)',
  256. 'http://foo.bar/page?p=1&t=z&s=-' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=-">http://foo.bar/page?p=1&#38;t=z&#38;s=-</a>',
  257. 'This is an intern "link":/foo/bar-' => 'This is an intern <a href="/foo/bar-">link</a>', }
  258. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  259. end
  260. def test_textile_external_links_with_non_ascii_characters
  261. to_test = {
  262. %|This is a "link":http://foo.bar/#{@russian_test}| =>
  263. %|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
  264. }
  265. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  266. end
  267. def test_redmine_links
  268. user_with_email_login = User.generate!(:login => 'abcd@example.com')
  269. user_with_email_login_2 = User.generate!(:login => 'foo.bar@example.com')
  270. u_email_id = user_with_email_login.id
  271. u_email_id_2 = user_with_email_login_2.id
  272. issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
  273. :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)')
  274. ext_issue_link = link_to('Bug #3', {:controller => 'issues', :action => 'show', :id => 3},
  275. :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ": Error 281 when updating a recipe"
  276. note_link = link_to('#3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
  277. :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)')
  278. ext_note_link = link_to('Bug #3-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
  279. :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ": Error 281 when updating a recipe"
  280. note_link2 = link_to('#3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
  281. :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)')
  282. ext_note_link2 = link_to('Bug #3#note-14', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
  283. :class => Issue.find(3).css_classes, :title => 'Bug: Error 281 when updating a recipe (New)') + ": Error 281 when updating a recipe"
  284. revision_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 10, :rev => 1},
  285. :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
  286. revision_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 10, :rev => 2},
  287. :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
  288. changeset_link2 = link_to('691322a8eb01e11fd7',
  289. {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 10, :rev => 1},
  290. :class => 'changeset', :title => 'My very first commit do not escaping #<>&')
  291. document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
  292. :class => 'document')
  293. version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
  294. :class => 'version')
  295. board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
  296. message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
  297. news_url = {:controller => 'news', :action => 'show', :id => 1}
  298. project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
  299. source_url = '/projects/ecookbook/repository/10/entry/some/file'
  300. source_url_with_rev = '/projects/ecookbook/repository/10/revisions/52/entry/some/file'
  301. source_url_with_ext = '/projects/ecookbook/repository/10/entry/some/file.ext'
  302. source_url_with_rev_and_ext = '/projects/ecookbook/repository/10/revisions/52/entry/some/file.ext'
  303. source_url_with_branch = '/projects/ecookbook/repository/10/revisions/branch/entry/some/file'
  304. export_url = '/projects/ecookbook/repository/10/raw/some/file'
  305. export_url_with_rev = '/projects/ecookbook/repository/10/revisions/52/raw/some/file'
  306. export_url_with_ext = '/projects/ecookbook/repository/10/raw/some/file.ext'
  307. export_url_with_rev_and_ext = '/projects/ecookbook/repository/10/revisions/52/raw/some/file.ext'
  308. export_url_with_branch = '/projects/ecookbook/repository/10/revisions/branch/raw/some/file'
  309. to_test = {
  310. # tickets
  311. '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
  312. # ticket notes
  313. '#3-14' => note_link,
  314. '#3#note-14' => note_link2,
  315. # should not ignore leading zero
  316. '#03' => '#03',
  317. # tickets with more info
  318. '##3, [##3], (##3) and ##3.' => "#{ext_issue_link}, [#{ext_issue_link}], (#{ext_issue_link}) and #{ext_issue_link}.",
  319. '##3-14' => ext_note_link,
  320. '##3#note-14' => ext_note_link2,
  321. '##03' => '##03',
  322. # changesets
  323. 'r1' => revision_link,
  324. 'r1.' => "#{revision_link}.",
  325. 'r1, r2' => "#{revision_link}, #{revision_link2}",
  326. 'r1,r2' => "#{revision_link},#{revision_link2}",
  327. 'commit:691322a8eb01e11fd7' => changeset_link2,
  328. # documents
  329. 'document#1' => document_link,
  330. 'document:"Test document"' => document_link,
  331. # versions
  332. 'version#2' => version_link,
  333. 'version:1.0' => version_link,
  334. 'version:"1.0"' => version_link,
  335. # source
  336. 'source:some/file' => link_to('source:some/file', source_url, :class => 'source'),
  337. 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
  338. 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
  339. 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
  340. 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
  341. 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
  342. 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
  343. 'source:/some/file@52' => link_to('source:/some/file@52', source_url_with_rev, :class => 'source'),
  344. 'source:/some/file@branch' => link_to('source:/some/file@branch', source_url_with_branch, :class => 'source'),
  345. 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_rev_and_ext, :class => 'source'),
  346. 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url + "#L110", :class => 'source'),
  347. 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext + "#L110", :class => 'source'),
  348. 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url_with_rev + "#L110", :class => 'source'),
  349. # export
  350. 'export:/some/file' => link_to('export:/some/file', export_url, :class => 'source download'),
  351. 'export:/some/file.ext' => link_to('export:/some/file.ext', export_url_with_ext, :class => 'source download'),
  352. 'export:/some/file@52' => link_to('export:/some/file@52', export_url_with_rev, :class => 'source download'),
  353. 'export:/some/file.ext@52' => link_to('export:/some/file.ext@52', export_url_with_rev_and_ext, :class => 'source download'),
  354. 'export:/some/file@branch' => link_to('export:/some/file@branch', export_url_with_branch, :class => 'source download'),
  355. # forum
  356. 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
  357. 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
  358. # message
  359. 'message#4' => link_to('Post 2', message_url, :class => 'message'),
  360. 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
  361. # news
  362. 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
  363. 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
  364. # project
  365. 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
  366. 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
  367. 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
  368. # not found
  369. '#0123456789' => '#0123456789',
  370. # invalid expressions
  371. 'source:' => 'source:',
  372. # url hash
  373. "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
  374. # user
  375. 'user:jsmith' => link_to_user(User.find_by_id(2)),
  376. 'user:JSMITH' => link_to_user(User.find_by_id(2)),
  377. 'user#2' => link_to_user(User.find_by_id(2)),
  378. '@jsmith' => link_to_user(User.find_by_id(2)),
  379. '@JSMITH' => link_to_user(User.find_by_id(2)),
  380. '@abcd@example.com' => link_to_user(User.find_by_id(u_email_id)),
  381. 'user:abcd@example.com' => link_to_user(User.find_by_id(u_email_id)),
  382. '@foo.bar@example.com' => link_to_user(User.find_by_id(u_email_id_2)),
  383. 'user:foo.bar@example.com' => link_to_user(User.find_by_id(u_email_id_2)),
  384. # invalid user
  385. 'user:foobar' => 'user:foobar',
  386. }
  387. @project = Project.find(1)
  388. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
  389. end
  390. def test_link_to_note_within_the_same_page
  391. issue = Issue.find(1)
  392. assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
  393. journal = Journal.find(2)
  394. assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
  395. end
  396. def test_user_links_with_email_as_login_name_should_not_be_parsed_textile
  397. with_settings :text_formatting => 'textile' do
  398. u = User.generate!(:login => 'jsmith@somenet.foo')
  399. # user link format: @jsmith@somenet.foo
  400. raw = "@jsmith@somenet.foo should not be parsed in jsmith@somenet.foo"
  401. assert_match %r{<p><a class="user active".*>#{u.name}</a> should not be parsed in <a class="email" href="mailto:jsmith@somenet.foo">jsmith@somenet.foo</a></p>},
  402. textilizable(raw, :project => Project.find(1))
  403. # user link format: user:jsmith@somenet.foo
  404. raw = "user:jsmith@somenet.foo should not be parsed in jsmith@somenet.foo"
  405. assert_match %r{<p><a class="user active".*>#{u.name}</a> should not be parsed in <a class="email" href="mailto:jsmith@somenet.foo">jsmith@somenet.foo</a></p>},
  406. textilizable(raw, :project => Project.find(1))
  407. end
  408. end
  409. def test_user_links_with_email_as_login_name_should_not_be_parsed_markdown
  410. with_settings :text_formatting => 'markdown' do
  411. u = User.generate!(:login => 'jsmith@somenet.foo')
  412. # user link format: @jsmith@somenet.foo
  413. raw = "@jsmith@somenet.foo should not be parsed in jsmith@somenet.foo"
  414. assert_match %r{<p><a class=\"user active\".*>#{u.name}</a> should not be parsed in <a href=\"mailto:jsmith@somenet.foo\">jsmith@somenet.foo</a></p>},
  415. textilizable(raw, :project => Project.find(1))
  416. # user link format: user:jsmith@somenet.foo
  417. raw = "user:jsmith@somenet.foo should not be parsed in jsmith@somenet.foo"
  418. assert_match %r{<p><a class=\"user active\".*>#{u.name}</a> should not be parsed in <a href=\"mailto:jsmith@somenet.foo\">jsmith@somenet.foo</a></p>},
  419. textilizable(raw, :project => Project.find(1))
  420. end
  421. end
  422. def test_should_not_parse_redmine_links_inside_link
  423. raw = "r1 should not be parsed in http://example.com/url-r1/"
  424. assert_match %r{<p><a class="changeset".*>r1</a> should not be parsed in <a class="external" href="http://example.com/url-r1/">http://example.com/url-r1/</a></p>},
  425. textilizable(raw, :project => Project.find(1))
  426. end
  427. def test_redmine_links_with_a_different_project_before_current_project
  428. vp1 = Version.generate!(:project_id => 1, :name => '1.4.4')
  429. vp3 = Version.generate!(:project_id => 3, :name => '1.4.4')
  430. @project = Project.find(3)
  431. result1 = link_to("1.4.4", "/versions/#{vp1.id}", :class => "version")
  432. result2 = link_to("1.4.4", "/versions/#{vp3.id}", :class => "version")
  433. assert_equal "<p>#{result1} #{result2}</p>",
  434. textilizable("ecookbook:version:1.4.4 version:1.4.4")
  435. end
  436. def test_escaped_redmine_links_should_not_be_parsed
  437. to_test = [
  438. '#3.',
  439. '#3-14.',
  440. '#3#-note14.',
  441. 'r1',
  442. 'document#1',
  443. 'document:"Test document"',
  444. 'version#2',
  445. 'version:1.0',
  446. 'version:"1.0"',
  447. 'source:/some/file'
  448. ]
  449. @project = Project.find(1)
  450. to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" }
  451. end
  452. def test_cross_project_redmine_links
  453. source_link = link_to('ecookbook:source:/some/file',
  454. {:controller => 'repositories', :action => 'entry',
  455. :id => 'ecookbook', :repository_id => 10, :path => ['some', 'file']},
  456. :class => 'source')
  457. changeset_link = link_to('ecookbook:r2',
  458. {:controller => 'repositories', :action => 'revision',
  459. :id => 'ecookbook', :repository_id => 10, :rev => 2},
  460. :class => 'changeset',
  461. :title => 'This commit fixes #1, #2 and references #1 & #3')
  462. to_test = {
  463. # documents
  464. 'document:"Test document"' => 'document:"Test document"',
  465. 'ecookbook:document:"Test document"' =>
  466. link_to("Test document", "/documents/1", :class => "document"),
  467. 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
  468. # versions
  469. 'version:"1.0"' => 'version:"1.0"',
  470. 'ecookbook:version:"1.0"' =>
  471. link_to("1.0", "/versions/2", :class => "version"),
  472. 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
  473. # changeset
  474. 'r2' => 'r2',
  475. 'ecookbook:r2' => changeset_link,
  476. 'invalid:r2' => 'invalid:r2',
  477. # source
  478. 'source:/some/file' => 'source:/some/file',
  479. 'ecookbook:source:/some/file' => source_link,
  480. 'invalid:source:/some/file' => 'invalid:source:/some/file',
  481. }
  482. @project = Project.find(3)
  483. to_test.each do |text, result|
  484. assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
  485. end
  486. end
  487. def test_redmine_links_by_name_should_work_with_html_escaped_characters
  488. v = Version.generate!(:name => "Test & Show.txt", :project_id => 1)
  489. link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version")
  490. @project = v.project
  491. assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
  492. end
  493. def test_link_to_issue_subject
  494. issue = Issue.generate!(:subject => "01234567890123456789")
  495. str = link_to_issue(issue, :truncate => 10)
  496. result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes)
  497. assert_equal "#{result}: 0123456...", str
  498. issue = Issue.generate!(:subject => "<&>")
  499. str = link_to_issue(issue)
  500. result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes)
  501. assert_equal "#{result}: &lt;&amp;&gt;", str
  502. issue = Issue.generate!(:subject => "<&>0123456789012345")
  503. str = link_to_issue(issue, :truncate => 10)
  504. result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes)
  505. assert_equal "#{result}: &lt;&amp;&gt;0123...", str
  506. end
  507. def test_link_to_issue_title
  508. long_str = "0123456789" * 5
  509. issue = Issue.generate!(:subject => "#{long_str}01234567890123456789")
  510. str = link_to_issue(issue, :subject => false)
  511. result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}",
  512. :class => issue.css_classes,
  513. :title => "#{long_str}0123456...")
  514. assert_equal result, str
  515. issue = Issue.generate!(:subject => "<&>#{long_str}01234567890123456789")
  516. str = link_to_issue(issue, :subject => false)
  517. result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}",
  518. :class => issue.css_classes,
  519. :title => "<&>#{long_str}0123...")
  520. assert_equal result, str
  521. end
  522. def test_multiple_repositories_redmine_links
  523. svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg')
  524. Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
  525. hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
  526. Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
  527. changeset_link = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 10, :rev => 2},
  528. :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
  529. svn_changeset_link = link_to('svn_repo-1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn_repo-1', :rev => 123},
  530. :class => 'changeset', :title => '')
  531. hg_changeset_link = link_to('hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
  532. :class => 'changeset', :title => '')
  533. source_link = link_to('source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 10, :path => ['some', 'file']}, :class => 'source')
  534. hg_source_link = link_to('source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
  535. to_test = {
  536. 'r2' => changeset_link,
  537. 'svn_repo-1|r123' => svn_changeset_link,
  538. 'invalid|r123' => 'invalid|r123',
  539. 'commit:hg1|abcd' => hg_changeset_link,
  540. 'commit:invalid|abcd' => 'commit:invalid|abcd',
  541. # source
  542. 'source:some/file' => source_link,
  543. 'source:hg1|some/file' => hg_source_link,
  544. 'source:invalid|some/file' => 'source:invalid|some/file',
  545. }
  546. @project = Project.find(1)
  547. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
  548. end
  549. def test_cross_project_multiple_repositories_redmine_links
  550. svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///foo/hg')
  551. Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123')
  552. hg = Repository::Mercurial.create!(:project_id => 1, :identifier => 'hg1', :url => '/foo/hg')
  553. Changeset.create!(:repository => hg, :committed_on => Time.now, :revision => '123', :scmid => 'abcd')
  554. changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 10, :rev => 2},
  555. :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
  556. svn_changeset_link = link_to('ecookbook:svn1|r123', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'svn1', :rev => 123},
  557. :class => 'changeset', :title => '')
  558. hg_changeset_link = link_to('ecookbook:hg1|abcd', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :repository_id => 'hg1', :rev => 'abcd'},
  559. :class => 'changeset', :title => '')
  560. source_link = link_to('ecookbook:source:some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 10, :path => ['some', 'file']}, :class => 'source')
  561. hg_source_link = link_to('ecookbook:source:hg1|some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :repository_id => 'hg1', :path => ['some', 'file']}, :class => 'source')
  562. to_test = {
  563. 'ecookbook:r2' => changeset_link,
  564. 'ecookbook:svn1|r123' => svn_changeset_link,
  565. 'ecookbook:invalid|r123' => 'ecookbook:invalid|r123',
  566. 'ecookbook:commit:hg1|abcd' => hg_changeset_link,
  567. 'ecookbook:commit:invalid|abcd' => 'ecookbook:commit:invalid|abcd',
  568. 'invalid:commit:invalid|abcd' => 'invalid:commit:invalid|abcd',
  569. # source
  570. 'ecookbook:source:some/file' => source_link,
  571. 'ecookbook:source:hg1|some/file' => hg_source_link,
  572. 'ecookbook:source:invalid|some/file' => 'ecookbook:source:invalid|some/file',
  573. 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file',
  574. }
  575. @project = Project.find(3)
  576. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
  577. end
  578. def test_redmine_links_git_commit
  579. @project = Project.find(3)
  580. r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
  581. c = Changeset.create!(:repository => r,
  582. :committed_on => Time.now,
  583. :revision => 'abcd',
  584. :scmid => 'abcd',
  585. :comments => 'test commit')
  586. changeset_link = link_to('abcd',
  587. {
  588. :controller => 'repositories',
  589. :action => 'revision',
  590. :id => 'subproject1',
  591. :repository_id => r.id,
  592. :rev => 'abcd',
  593. },
  594. :class => 'changeset', :title => 'test commit')
  595. to_test = {
  596. 'commit:abcd' => changeset_link,
  597. }
  598. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  599. end
  600. # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
  601. def test_redmine_links_mercurial_commit
  602. @project = Project.find(3)
  603. r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
  604. c = Changeset.create!(:repository => r,
  605. :committed_on => Time.now,
  606. :revision => '123',
  607. :scmid => 'abcd',
  608. :comments => 'test commit')
  609. changeset_link_rev = link_to('r123',
  610. {
  611. :controller => 'repositories',
  612. :action => 'revision',
  613. :id => 'subproject1',
  614. :repository_id => r.id,
  615. :rev => '123' ,
  616. },
  617. :class => 'changeset', :title => 'test commit')
  618. changeset_link_commit = link_to('abcd',
  619. {
  620. :controller => 'repositories',
  621. :action => 'revision',
  622. :id => 'subproject1',
  623. :repository_id => r.id,
  624. :rev => 'abcd' ,
  625. },
  626. :class => 'changeset', :title => 'test commit')
  627. to_test = {
  628. 'r123' => changeset_link_rev,
  629. 'commit:abcd' => changeset_link_commit,
  630. }
  631. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  632. end
  633. def test_attachment_links
  634. text = 'attachment:error281.txt'
  635. result = link_to("error281.txt", "/attachments/1",
  636. :class => "attachment")
  637. assert_equal "<p>#{result}</p>",
  638. textilizable(text,
  639. :attachments => Issue.find(3).attachments),
  640. "#{text} failed"
  641. end
  642. def test_attachment_link_should_link_to_latest_attachment
  643. set_tmp_attachments_directory
  644. a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
  645. a2 = Attachment.generate!(:filename => "test.txt")
  646. result = link_to("test.txt", "/attachments/#{a2.id}",
  647. :class => "attachment")
  648. assert_equal "<p>#{result}</p>",
  649. textilizable('attachment:test.txt', :attachments => [a1, a2])
  650. end
  651. def test_attachment_links_to_images_with_email_format_should_not_be_parsed
  652. attachment = Attachment.generate!(:filename => 'image@2x.png')
  653. with_settings :text_formatting => 'textile' do
  654. raw = "attachment:image@2x.png should not be parsed in image@2x.png"
  655. assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}">image@2x.png</a> should not be parsed in image@2x.png</p>},
  656. textilizable(raw, :attachments => [attachment])
  657. end
  658. with_settings :text_formatting => 'markdown' do
  659. raw = "attachment:image@2x.png should not be parsed in image@2x.png"
  660. assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}">image@2x.png</a> should not be parsed in image@2x.png</p>} ,
  661. textilizable(raw, :attachments => [attachment])
  662. end
  663. end
  664. def test_wiki_links
  665. User.current = User.find_by_login('jsmith')
  666. russian_eacape = CGI.escape(@russian_test)
  667. to_test = {
  668. '[[CookBook documentation]]' =>
  669. link_to("CookBook documentation",
  670. "/projects/ecookbook/wiki/CookBook_documentation",
  671. :class => "wiki-page"),
  672. '[[Another page|Page]]' =>
  673. link_to("Page",
  674. "/projects/ecookbook/wiki/Another_page",
  675. :class => "wiki-page"),
  676. # title content should be formatted
  677. '[[Another page|With _styled_ *title*]]' =>
  678. link_to("With <em>styled</em> <strong>title</strong>".html_safe,
  679. "/projects/ecookbook/wiki/Another_page",
  680. :class => "wiki-page"),
  681. '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' =>
  682. link_to("With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;".html_safe,
  683. "/projects/ecookbook/wiki/Another_page",
  684. :class => "wiki-page"),
  685. # link with anchor
  686. '[[CookBook documentation#One-section]]' =>
  687. link_to("CookBook documentation",
  688. "/projects/ecookbook/wiki/CookBook_documentation#One-section",
  689. :class => "wiki-page"),
  690. '[[Another page#anchor|Page]]' =>
  691. link_to("Page",
  692. "/projects/ecookbook/wiki/Another_page#anchor",
  693. :class => "wiki-page"),
  694. # UTF8 anchor
  695. "[[Another_page##{@russian_test}|#{@russian_test}]]" =>
  696. link_to(@russian_test,
  697. "/projects/ecookbook/wiki/Another_page##{russian_eacape}",
  698. :class => "wiki-page"),
  699. # link to anchor
  700. '[[#anchor]]' =>
  701. link_to("#anchor",
  702. "#anchor",
  703. :class => "wiki-page"),
  704. '[[#anchor|One-section]]' =>
  705. link_to("One-section",
  706. "#anchor",
  707. :class => "wiki-page"),
  708. # page that doesn't exist
  709. '[[Unknown page]]' =>
  710. link_to("Unknown page",
  711. "/projects/ecookbook/wiki/Unknown_page",
  712. :class => "wiki-page new"),
  713. '[[Unknown page|404]]' =>
  714. link_to("404",
  715. "/projects/ecookbook/wiki/Unknown_page",
  716. :class => "wiki-page new"),
  717. # link to another project wiki
  718. '[[onlinestore:]]' =>
  719. link_to("onlinestore",
  720. "/projects/onlinestore/wiki",
  721. :class => "wiki-page"),
  722. '[[onlinestore:|Wiki]]' =>
  723. link_to("Wiki",
  724. "/projects/onlinestore/wiki",
  725. :class => "wiki-page"),
  726. '[[onlinestore:Start page]]' =>
  727. link_to("Start page",
  728. "/projects/onlinestore/wiki/Start_page",
  729. :class => "wiki-page"),
  730. '[[onlinestore:Start page|Text]]' =>
  731. link_to("Text",
  732. "/projects/onlinestore/wiki/Start_page",
  733. :class => "wiki-page"),
  734. '[[onlinestore:Unknown page]]' =>
  735. link_to("Unknown page",
  736. "/projects/onlinestore/wiki/Unknown_page",
  737. :class => "wiki-page new"),
  738. # struck through link
  739. '-[[Another page|Page]]-' =>
  740. "<del>".html_safe +
  741. link_to("Page",
  742. "/projects/ecookbook/wiki/Another_page",
  743. :class => "wiki-page").html_safe +
  744. "</del>".html_safe,
  745. '-[[Another page|Page]] link-' =>
  746. "<del>".html_safe +
  747. link_to("Page",
  748. "/projects/ecookbook/wiki/Another_page",
  749. :class => "wiki-page").html_safe +
  750. " link</del>".html_safe,
  751. # escaping
  752. '![[Another page|Page]]' => '[[Another page|Page]]',
  753. # project does not exist
  754. '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
  755. '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
  756. # missing permission to view wiki in project
  757. '[[private-child:]]' => '[[private-child:]]',
  758. '[[private-child:Wiki]]' => '[[private-child:Wiki]]',
  759. }
  760. @project = Project.find(1)
  761. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  762. end
  763. def test_wiki_links_with_special_characters_should_work_in_textile
  764. to_test = wiki_links_with_special_characters
  765. @project = Project.find(1)
  766. with_settings :text_formatting => 'textile' do
  767. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  768. end
  769. end
  770. def test_wiki_links_with_special_characters_should_work_in_markdown
  771. to_test = wiki_links_with_special_characters
  772. @project = Project.find(1)
  773. with_settings :text_formatting => 'markdown' do
  774. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text).strip }
  775. end
  776. end
  777. def test_wiki_links_with_square_brackets_in_project_name
  778. User.current = User.find_by_login('jsmith')
  779. another_project = Project.find(1) # eCookbook
  780. another_project.name = "[foo]#{another_project.name}"
  781. another_project.save
  782. page = another_project.wiki.find_page('Another page')
  783. page.title = "[bar]#{page.title}"
  784. page.save
  785. to_test = {
  786. '[[[foo]eCookbook:]]' =>
  787. link_to("[foo]eCookbook",
  788. "/projects/ecookbook/wiki",
  789. :class => "wiki-page"),
  790. '[[[foo]eCookbook:CookBook documentation]]' =>
  791. link_to("CookBook documentation",
  792. "/projects/ecookbook/wiki/CookBook_documentation",
  793. :class => "wiki-page"),
  794. '[[[foo]eCookbook:[bar]Another page]]' =>
  795. link_to("[bar]Another page",
  796. "/projects/ecookbook/wiki/%5Bbar%5DAnother_page",
  797. :class => "wiki-page"),
  798. '[[[foo]eCookbook:Unknown page]]' =>
  799. link_to("Unknown page",
  800. "/projects/ecookbook/wiki/Unknown_page",
  801. :class => "wiki-page new"),
  802. '[[[foo]eCookbook:[baz]Unknown page]]' =>
  803. link_to("[baz]Unknown page",
  804. "/projects/ecookbook/wiki/%5Bbaz%5DUnknown_page",
  805. :class => "wiki-page new"),
  806. }
  807. @project = Project.find(2) # OnlineStore
  808. with_settings :text_formatting => 'textile' do
  809. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  810. end
  811. with_settings :text_formatting => 'markdown' do
  812. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text).strip }
  813. end
  814. end
  815. def test_wiki_links_within_local_file_generation_context
  816. to_test = {
  817. # link to a page
  818. '[[CookBook documentation]]' =>
  819. link_to("CookBook documentation", "CookBook_documentation.html",
  820. :class => "wiki-page"),
  821. '[[CookBook documentation|documentation]]' =>
  822. link_to("documentation", "CookBook_documentation.html",
  823. :class => "wiki-page"),
  824. '[[CookBook documentation#One-section]]' =>
  825. link_to("CookBook documentation", "CookBook_documentation.html#One-section",
  826. :class => "wiki-page"),
  827. '[[CookBook documentation#One-section|documentation]]' =>
  828. link_to("documentation", "CookBook_documentation.html#One-section",
  829. :class => "wiki-page"),
  830. # page that doesn't exist
  831. '[[Unknown page]]' =>
  832. link_to("Unknown page", "Unknown_page.html",
  833. :class => "wiki-page new"),
  834. '[[Unknown page|404]]' =>
  835. link_to("404", "Unknown_page.html",
  836. :class => "wiki-page new"),
  837. '[[Unknown page#anchor]]' =>
  838. link_to("Unknown page", "Unknown_page.html#anchor",
  839. :class => "wiki-page new"),
  840. '[[Unknown page#anchor|404]]' =>
  841. link_to("404", "Unknown_page.html#anchor",
  842. :class => "wiki-page new"),
  843. }
  844. @project = Project.find(1)
  845. to_test.each do |text, result|
  846. assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
  847. end
  848. end
  849. def test_wiki_links_within_wiki_page_context
  850. page = WikiPage.find_by_title('Another_page' )
  851. to_test = {
  852. '[[CookBook documentation]]' =>
  853. link_to("CookBook documentation",
  854. "/projects/ecookbook/wiki/CookBook_documentation",
  855. :class => "wiki-page"),
  856. '[[CookBook documentation|documentation]]' =>
  857. link_to("documentation",
  858. "/projects/ecookbook/wiki/CookBook_documentation",
  859. :class => "wiki-page"),
  860. '[[CookBook documentation#One-section]]' =>
  861. link_to("CookBook documentation",
  862. "/projects/ecookbook/wiki/CookBook_documentation#One-section",
  863. :class => "wiki-page"),
  864. '[[CookBook documentation#One-section|documentation]]' =>
  865. link_to("documentation",
  866. "/projects/ecookbook/wiki/CookBook_documentation#One-section",
  867. :class => "wiki-page"),
  868. # link to the current page
  869. '[[Another page]]' =>
  870. link_to("Another page",
  871. "/projects/ecookbook/wiki/Another_page",
  872. :class => "wiki-page"),
  873. '[[Another page|Page]]' =>
  874. link_to("Page",
  875. "/projects/ecookbook/wiki/Another_page",
  876. :class => "wiki-page"),
  877. '[[Another page#anchor]]' =>
  878. link_to("Another page",
  879. "#anchor",
  880. :class => "wiki-page"),
  881. '[[Another page#anchor|Page]]' =>
  882. link_to("Page",
  883. "#anchor",
  884. :class => "wiki-page"),
  885. # page that doesn't exist
  886. '[[Unknown page]]' =>
  887. link_to("Unknown page",
  888. "/projects/ecookbook/wiki/Unknown_page?parent=Another_page",
  889. :class => "wiki-page new"),
  890. '[[Unknown page|404]]' =>
  891. link_to("404",
  892. "/projects/ecookbook/wiki/Unknown_page?parent=Another_page",
  893. :class => "wiki-page new"),
  894. '[[Unknown page#anchor]]' =>
  895. link_to("Unknown page",
  896. "/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor",
  897. :class => "wiki-page new"),
  898. '[[Unknown page#anchor|404]]' =>
  899. link_to("404",
  900. "/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor",
  901. :class => "wiki-page new"),
  902. }
  903. @project = Project.find(1)
  904. to_test.each do |text, result|
  905. assert_equal "<p>#{result}</p>",
  906. textilizable(WikiContent.new( :text => text, :page => page ), :text)
  907. end
  908. end
  909. def test_wiki_links_anchor_option_should_prepend_page_title_to_href
  910. to_test = {
  911. # link to a page
  912. '[[CookBook documentation]]' =>
  913. link_to("CookBook documentation",
  914. "#CookBook_documentation",
  915. :class => "wiki-page"),
  916. '[[CookBook documentation|documentation]]' =>
  917. link_to("documentation",
  918. "#CookBook_documentation",
  919. :class => "wiki-page"),
  920. '[[CookBook documentation#One-section]]' =>
  921. link_to("CookBook documentation",
  922. "#CookBook_documentation_One-section",
  923. :class => "wiki-page"),
  924. '[[CookBook documentation#One-section|documentation]]' =>
  925. link_to("documentation",
  926. "#CookBook_documentation_One-section",
  927. :class => "wiki-page"),
  928. # page that doesn't exist
  929. '[[Unknown page]]' =>
  930. link_to("Unknown page",
  931. "#Unknown_page",
  932. :class => "wiki-page new"),
  933. '[[Unknown page|404]]' =>
  934. link_to("404",
  935. "#Unknown_page",
  936. :class => "wiki-page new"),
  937. '[[Unknown page#anchor]]' =>
  938. link_to("Unknown page",
  939. "#Unknown_page_anchor",
  940. :class => "wiki-page new"),
  941. '[[Unknown page#anchor|404]]' =>
  942. link_to("404",
  943. "#Unknown_page_anchor",
  944. :class => "wiki-page new"),
  945. }
  946. @project = Project.find(1)
  947. to_test.each do |text, result|
  948. assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
  949. end
  950. end
  951. def test_html_tags
  952. to_test = {
  953. "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
  954. "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
  955. "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
  956. # do not escape pre/code tags
  957. "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
  958. "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
  959. "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
  960. "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
  961. "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
  962. # remove attributes including class
  963. "<pre class='foo'>some text</pre>" => "<pre>some text</pre>",
  964. '<pre class="foo">some text</pre>' => '<pre>some text</pre>',
  965. "<pre class='foo bar'>some text</pre>" => "<pre>some text</pre>",
  966. '<pre class="foo bar">some text</pre>' => '<pre>some text</pre>',
  967. "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
  968. # xss
  969. '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
  970. '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
  971. }
  972. to_test.each { |text, result| assert_equal result, textilizable(text) }
  973. end
  974. def test_allowed_html_tags
  975. to_test = {
  976. "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
  977. "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
  978. "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
  979. }
  980. to_test.each { |text, result| assert_equal result, textilizable(text) }
  981. end
  982. def test_pre_tags
  983. raw = <<-RAW
  984. Before
  985. <pre>
  986. <prepared-statement-cache-size>32</prepared-statement-cache-size>
  987. </pre>
  988. After
  989. RAW
  990. expected = <<-EXPECTED
  991. <p>Before</p>
  992. <pre>
  993. &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
  994. </pre>
  995. <p>After</p>
  996. EXPECTED
  997. assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
  998. end
  999. def test_pre_content_should_not_parse_wiki_and_redmine_links
  1000. raw = <<-RAW
  1001. [[CookBook documentation]]
  1002. #1
  1003. <pre>
  1004. [[CookBook documentation]]
  1005. #1
  1006. </pre>
  1007. RAW
  1008. result1 = link_to("CookBook documentation",
  1009. "/projects/ecookbook/wiki/CookBook_documentation",
  1010. :class => "wiki-page")
  1011. result2 = link_to('#1',
  1012. "/issues/1",
  1013. :class => Issue.find(1).css_classes,
  1014. :title => "Bug: Cannot print recipes (New)")
  1015. expected = <<-EXPECTED
  1016. <p>#{result1}</p>
  1017. <p>#{result2}</p>
  1018. <pre>
  1019. [[CookBook documentation]]
  1020. #1
  1021. </pre>
  1022. EXPECTED
  1023. @project = Project.find(1)
  1024. assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
  1025. end
  1026. def test_non_closing_pre_blocks_should_be_closed
  1027. raw = <<-RAW
  1028. <pre><code>
  1029. RAW
  1030. expected = <<-EXPECTED
  1031. <pre><code>
  1032. </code></pre>
  1033. EXPECTED
  1034. @project = Project.find(1)
  1035. assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
  1036. end
  1037. def test_unbalanced_closing_pre_tag_should_not_error
  1038. assert_nothing_raised do
  1039. textilizable("unbalanced</pre>")
  1040. end
  1041. end
  1042. def test_syntax_highlight
  1043. raw = <<-RAW
  1044. <pre><code class="ECMA_script">
  1045. /* Hello */
  1046. document.write("Hello World!");
  1047. </code></pre>
  1048. RAW
  1049. expected = <<-EXPECTED
  1050. <pre><code class="ECMA_script syntaxhl"><span class="cm">/* Hello */</span><span class="nb">document</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="dl">"</span><span class="s2">Hello World!</span><span class="dl">"</span><span class="p">);</span></code></pre>
  1051. EXPECTED
  1052. assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
  1053. end
  1054. def test_syntax_highlight_ampersand_in_textile
  1055. raw = <<-RAW
  1056. <pre><code class="ruby">
  1057. x = a & b
  1058. </code></pre>
  1059. RAW
  1060. expected = <<-EXPECTED
  1061. <pre><code class=\"ruby syntaxhl\"><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"n\">a</span> <span class=\"o\">&amp;</span> <span class=\"n\">b</span></code></pre>
  1062. EXPECTED
  1063. with_settings :text_formatting => 'textile' do
  1064. assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
  1065. end
  1066. end
  1067. def test_syntax_highlight_should_normalize_line_endings
  1068. assert_equal "line 1\nline 2\n", syntax_highlight("test.txt", "line 1\rline 2\r\n")
  1069. end
  1070. def test_to_path_param
  1071. assert_equal 'test1/test2', to_path_param('test1/test2')
  1072. assert_equal 'test1/test2', to_path_param('/test1/test2/')
  1073. assert_equal 'test1/test2', to_path_param('//test1/test2/')
  1074. assert_nil to_path_param('/')
  1075. end
  1076. def test_wiki_links_in_tables
  1077. text = "|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|"
  1078. link1 = link_to("Link title", "/projects/ecookbook/wiki/Page", :class => "wiki-page new")
  1079. link2 = link_to("Other title", "/projects/ecookbook/wiki/Other_Page", :class => "wiki-page new")
  1080. link3 = link_to("Last page", "/projects/ecookbook/wiki/Last_page", :class => "wiki-page new")
  1081. result = "<tr><td>#{link1}</td>" +
  1082. "<td>#{link2}</td>" +
  1083. "</tr><tr><td>Cell 21</td><td>#{link3}</td></tr>"
  1084. @project = Project.find(1)
  1085. assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
  1086. end
  1087. def test_text_formatting
  1088. to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
  1089. '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
  1090. 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
  1091. 'a H *umane* W *eb* T *ext* G *enerator*' => 'a H <strong>umane</strong> W <strong>eb</strong> T <strong>ext</strong> G <strong>enerator</strong>',
  1092. 'a *H* umane *W* eb *T* ext *G* enerator' => 'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator',
  1093. }
  1094. to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
  1095. end
  1096. def test_wiki_horizontal_rule
  1097. assert_equal '<hr />', textilizable('---')
  1098. assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
  1099. end
  1100. def test_headings
  1101. raw = 'h1. Some heading'
  1102. expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
  1103. assert_equal expected, textilizable(raw)
  1104. end
  1105. def test_headings_with_special_chars
  1106. # This test makes sure that the generated anchor names match the expected
  1107. # ones even if the heading text contains unconventional characters
  1108. raw = 'h1. Some heading related to version 0.5'
  1109. anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
  1110. expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
  1111. assert_equal expected, textilizable(raw)
  1112. end
  1113. def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
  1114. page = WikiPage.new( :title => 'Page Title', :wiki_id => 1 )
  1115. content = WikiContent.new( :text => 'h1. Some heading', :page => page )
  1116. expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
  1117. assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
  1118. end
  1119. def test_table_of_content
  1120. set_language_if_valid 'en'
  1121. raw = <<-RAW
  1122. {{toc}}
  1123. h1. Title
  1124. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
  1125. h2. Subtitle with a [[Wiki]] link
  1126. Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
  1127. h2. Subtitle with [[Wiki|another Wiki]] link
  1128. h2. Subtitle with %{color:red}red text%
  1129. <pre>
  1130. some code
  1131. </pre>
  1132. h3. Subtitle with *some* _modifiers_
  1133. h3. Subtitle with @inline code@
  1134. h1. Another title
  1135. h3. An "Internet link":http://www.redmine.org/ inside subtitle
  1136. h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
  1137. RAW
  1138. expected = '<ul class="toc">' +
  1139. '<li><strong>Table of contents</strong></li>' +
  1140. '<li><a href="#Title">Title</a>' +
  1141. '<ul>' +
  1142. '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
  1143. '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
  1144. '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
  1145. '<ul>' +
  1146. '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
  1147. '<li><a href="#Subtitle-with-inline-code">Subtitle with inline code</a></li>' +
  1148. '</ul>' +
  1149. '</li>' +
  1150. '</ul>' +
  1151. '</li>' +
  1152. '<li><a href="#Another-title">Another title</a>' +
  1153. '<ul>' +
  1154. '<li>' +
  1155. '<ul>' +
  1156. '<li><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
  1157. '</ul>' +
  1158. '</li>' +
  1159. '<li><a href="#Project-Name">Project Name</a></li>' +
  1160. '</ul>' +
  1161. '</li>' +
  1162. '</ul>'
  1163. @project = Project.find(1)
  1164. assert textilizable(raw).gsub("\n", "").include?(expected)
  1165. end
  1166. def test_table_of_content_should_generate_unique_anchors
  1167. set_language_if_valid 'en'
  1168. raw = <<-RAW
  1169. {{toc}}
  1170. h1. Title
  1171. h2. Subtitle
  1172. h2. Subtitle
  1173. RAW
  1174. expected = '<ul class="toc">' +
  1175. '<li><strong>Table of contents</strong></li>' +
  1176. '<li><a href="#Title">Title</a>' +
  1177. '<ul>' +
  1178. '<li><a href="#Subtitle">Subtitle</a></li>' +
  1179. '<li><a href="#Subtitle-2">Subtitle</a></li>' +
  1180. '</ul>' +
  1181. '</li>' +
  1182. '</ul>'
  1183. @project = Project.find(1)
  1184. result = textilizable(raw).gsub("\n", "")
  1185. assert_include expected, result
  1186. assert_include '<a name="Subtitle">', result
  1187. assert_include '<a name="Subtitle-2">', result
  1188. end
  1189. def test_table_of_content_should_contain_included_page_headings
  1190. set_language_if_valid 'en'
  1191. raw = <<-RAW
  1192. {{toc}}
  1193. h1. Included
  1194. {{include(Child_1)}}
  1195. RAW
  1196. expected = '<ul class="toc">' +
  1197. '<li><strong>Table of contents</strong></li>' +
  1198. '<li><a href="#Included">Included</a></li>' +
  1199. '<li><a href="#Child-page-1">Child page 1</a></li>' +
  1200. '</ul>'
  1201. @project = Project.find(1)
  1202. assert textilizable(raw).gsub("\n", "").include?(expected)
  1203. end
  1204. def test_toc_with_textile_formatting_should_be_parsed
  1205. with_settings :text_formatting => 'textile' do
  1206. assert_select_in textilizable("{{toc}}\n\nh1. Heading"), 'ul.toc li', :text => 'Heading'
  1207. assert_select_in textilizable("{{<toc}}\n\nh1. Heading"), 'ul.toc.left li', :text => 'Heading'
  1208. assert_select_in textilizable("{{>toc}}\n\nh1. Heading"), 'ul.toc.right li', :text => 'Heading'
  1209. end
  1210. end
  1211. if Object.const_defined?(:Redcarpet)
  1212. def test_toc_with_markdown_formatting_should_be_parsed
  1213. with_settings :text_formatting => 'markdown' do
  1214. assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading'
  1215. assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading'
  1216. assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading'
  1217. end
  1218. end
  1219. end
  1220. def test_section_edit_links
  1221. raw = <<-RAW
  1222. h1. Title
  1223. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
  1224. h2. Subtitle with a [[Wiki]] link
  1225. h2. Subtitle with *some* _modifiers_
  1226. h2. Subtitle with @inline code@
  1227. <pre>
  1228. some code
  1229. h2. heading inside pre
  1230. <h2>html heading inside pre</h2>
  1231. </pre>
  1232. h2. Subtitle after pre tag
  1233. RAW
  1234. @project = Project.find(1)
  1235. set_language_if_valid 'en'
  1236. result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "")
  1237. # heading that contains inline code
  1238. assert_match Regexp.new('<div class="contextual heading-2" title="Edit this section" id="section-4">' +
  1239. '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">Edit this section</a></div>' +
  1240. '<a name="Subtitle-with-inline-code"></a>' +
  1241. '<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a></h2>'),
  1242. result
  1243. # last heading
  1244. assert_match Regexp.new('<div class="contextual heading-2" title="Edit this section" id="section-5">' +
  1245. '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">Edit this section</a></div>' +
  1246. '<a name="Subtitle-after-pre-tag"></a>' +
  1247. '<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'),
  1248. result
  1249. end
  1250. def test_default_formatter
  1251. with_settings :text_formatting => 'unknown' do
  1252. text = 'a *link*: http://www.example.net/'
  1253. assert_equal '<p>a *link*: <a class="external" href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
  1254. end
  1255. end
  1256. def test_textilizable_with_formatting_set_to_false_should_not_format_text
  1257. assert_equal '*text*', textilizable("*text*", :formatting => false)
  1258. end
  1259. def test_textilizable_with_formatting_set_to_true_should_format_text
  1260. assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
  1261. end
  1262. def test_parse_redmine_links_should_handle_a_tag_without_attributes
  1263. text = +'<a>http://example.com</a>'
  1264. expected = text.dup
  1265. parse_redmine_links(text, nil, nil, nil, true, {})
  1266. assert_equal expected, text
  1267. end
  1268. def test_due_date_distance_in_words
  1269. to_test = { Date.today => 'Due in 0 days',
  1270. Date.today + 1 => 'Due in 1 day',
  1271. Date.today + 100 => 'Due in about 3 months',
  1272. Date.today + 20000 => 'Due in over 54 years',
  1273. Date.today - 1 => '1 day late',
  1274. Date.today - 100 => 'about 3 months late',
  1275. Date.today - 20000 => 'over 54 years late',
  1276. }
  1277. ::I18n.locale = :en
  1278. to_test.each do |date, expected|
  1279. assert_equal expected, due_date_distance_in_words(date)
  1280. end
  1281. end
  1282. def test_render_page_hierarchy
  1283. parent_page = WikiPage.find(1)
  1284. child_page = WikiPage.find_by(parent_id: parent_page.id)
  1285. pages_by_parent_id = { nil => [parent_page], parent_page.id => [child_page] }
  1286. result = render_page_hierarchy(pages_by_parent_id, nil)
  1287. assert_select_in result, 'ul.pages-hierarchy li a[href=?]', project_wiki_page_path(project_id: parent_page.project, id: parent_page.title, version: nil )
  1288. assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', project_wiki_page_path(project_id: child_page.project, id: child_page.title, version: nil )
  1289. end
  1290. def test_render_page_hierarchy_with_timestamp
  1291. parent_page = WikiPage.find(1)
  1292. child_page = WikiPage.find_by(parent_id: parent_page.id)
  1293. pages_by_parent_id = { nil => [parent_page], parent_page.id => [child_page] }
  1294. result = render_page_hierarchy(pages_by_parent_id, nil, :timestamp => true)
  1295. assert_select_in result, 'ul.pages-hierarchy li a[title=?]', l(:label_updated_time, distance_of_time_in_words(Time.now, parent_page.updated_on))
  1296. assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[title=?]', l(:label_updated_time, distance_of_time_in_words(Time.now, child_page.updated_on))
  1297. end
  1298. def test_render_page_hierarchy_when_action_is_export
  1299. parent_page = WikiPage.find(1)
  1300. child_page = WikiPage.find_by(parent_id: parent_page.id)
  1301. pages_by_parent_id = { nil => [parent_page], parent_page.id => [child_page] }
  1302. # Change controller and action using stub
  1303. controller.stubs(:controller_name).returns('wiki')
  1304. controller.stubs(:action_name).returns("export")
  1305. result = render_page_hierarchy(pages_by_parent_id, nil)
  1306. assert_select_in result, 'ul.pages-hierarchy li a[href=?]', "##{parent_page.title}"
  1307. assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}"
  1308. end
  1309. def test_link_to_user
  1310. user = User.find(2)
  1311. result = link_to("John Smith", "/users/2", :class => "user active")
  1312. assert_equal result, link_to_user(user)
  1313. end
  1314. def test_link_to_user_should_not_link_to_locked_user
  1315. with_current_user nil do
  1316. user = User.find(5)
  1317. assert user.locked?
  1318. assert_equal 'Dave2 Lopper2', link_to_user(user)
  1319. end
  1320. end
  1321. def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin
  1322. with_current_user User.find(1) do
  1323. user = User.find(5)
  1324. assert user.locked?
  1325. result = link_to("Dave2 Lopper2", "/users/5", :class => "user locked")
  1326. assert_equal result, link_to_user(user)
  1327. end
  1328. end
  1329. def test_link_to_group_should_return_only_group_name_for_non_admin_users
  1330. User.current = nil
  1331. group = Group.find(10)
  1332. assert_equal "A Team", link_to_group(group)
  1333. end
  1334. def test_link_to_group_should_link_to_group_edit_page_for_admin_users
  1335. User.current = User.find(1)
  1336. group = Group.find(10)
  1337. result = link_to("A Team", "/groups/10/edit")
  1338. assert_equal result, link_to_group(group)
  1339. end
  1340. def test_link_to_user_should_not_link_to_anonymous
  1341. user = User.anonymous
  1342. assert user.anonymous?
  1343. t = link_to_user(user)
  1344. assert_equal ::I18n.t(:label_user_anonymous), t
  1345. end
  1346. def test_link_to_attachment
  1347. a = Attachment.find(3)
  1348. assert_equal '<a href="/attachments/3">logo.gif</a>',
  1349. link_to_attachment(a)
  1350. assert_equal '<a href="/attachments/3">Text</a>',
  1351. link_to_attachment(a, :text => 'Text')
  1352. result = link_to("logo.gif", "/attachments/3", :class => "foo")
  1353. assert_equal result,
  1354. link_to_attachment(a, :class => 'foo')
  1355. assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
  1356. link_to_attachment(a, :download => true)
  1357. assert_equal '<a href="http://test.host/attachments/3">logo.gif</a>',
  1358. link_to_attachment(a, :only_path => false)
  1359. end
  1360. def test_thumbnail_tag
  1361. a = Attachment.find(3)
  1362. assert_select_in thumbnail_tag(a),
  1363. 'a[href=?][title=?] img[src=?]',
  1364. "/attachments/3", "logo.gif", "/attachments/thumbnail/3"
  1365. end
  1366. def test_link_to_project
  1367. project = Project.find(1)
  1368. assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
  1369. link_to_project(project)
  1370. assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
  1371. link_to_project(project, {:only_path => false, :jump => 'blah'})
  1372. end
  1373. def test_link_to_project_settings
  1374. project = Project.find(1)
  1375. assert_equal '<a href="/projects/ecookbook/settings">eCookbook</a>', link_to_project_settings(project)
  1376. project.status = Project::STATUS_CLOSED
  1377. assert_equal '<a href="/projects/ecookbook">eCookbook</a>', link_to_project_settings(project)
  1378. project.status = Project::STATUS_ARCHIVED
  1379. assert_equal 'eCookbook', link_to_project_settings(project)
  1380. end
  1381. def test_link_to_legacy_project_with_numerical_identifier_should_use_id
  1382. # numeric identifier are no longer allowed
  1383. Project.where(:id => 1).update_all(:identifier => 25)
  1384. assert_equal '<a href="/projects/1">eCookbook</a>',
  1385. link_to_project(Project.find(1))
  1386. end
  1387. def test_link_to_record
  1388. [
  1389. [custom_values(:custom_values_007), '<a href="/projects/ecookbook">eCookbook</a>'],
  1390. [documents(:documents_001), '<a href="/documents/1">Test document</a>'],
  1391. [Group.find(10), '<a href="/groups/10">A Team</a>'],
  1392. [issues(:issues_001), link_to_issue(issues(:issues_001), :subject => false)],
  1393. [messages(:messages_001), '<a href="/boards/1/topics/1">First post</a>'],
  1394. [news(:news_001), '<a href="/news/1">eCookbook first release !</a>'],
  1395. [projects(:projects_001), '<a href="/projects/ecookbook">eCookbook</a>'],
  1396. [users(:users_001), '<a class="user active" href="/users/1">Redmine Admin</a>'],
  1397. [versions(:versions_001), '<a title="07/01/2006" href="/versions/1">eCookbook - 0.1</a>'],
  1398. [wiki_pages(:wiki_pages_001), '<a href="/projects/ecookbook/wiki/CookBook_documentation">CookBook documentation</a>']
  1399. ].each do |record, link|
  1400. assert_equal link, link_to_record(record)
  1401. end
  1402. end
  1403. def test_link_to_attachment_container
  1404. field = ProjectCustomField.generate!(:name => "File", :field_format => 'attachment')
  1405. project = projects(:projects_001)
  1406. project_custom_value_attachment = new_record(Attachment) do
  1407. project.custom_field_values = {field.id => {:file => mock_file}}
  1408. project.save
  1409. end
  1410. news_attachment = attachments(:attachments_004)
  1411. news_attachment.container = news(:news_001)
  1412. news_attachment.save!
  1413. [
  1414. [project_custom_value_attachment, '<a href="/projects/ecookbook">eCookbook</a>'],
  1415. [attachments(:attachments_002), '<a href="/documents/1">Test document</a>'],
  1416. [attachments(:attachments_001), link_to_issue(issues(:issues_003), :subject => false)],
  1417. [attachments(:attachments_013), '<a href="/boards/1/topics/1">First post</a>'],
  1418. [news_attachment, '<a href="/news/1">eCookbook first release !</a>'],
  1419. [attachments(:attachments_008), '<a href="/projects/ecookbook/files">Files</a>'],
  1420. [attachments(:attachments_009), '<a href="/projects/ecookbook/files">Files</a>'],
  1421. [attachments(:attachments_003), '<a href="/projects/ecookbook/wiki/Page_with_an_inline_image">Page with an inline image</a>'],
  1422. ].each do |attachment, link|
  1423. assert_equal link, link_to_attachment_container(attachment.container)
  1424. end
  1425. end
  1426. def test_principals_options_for_select_with_users
  1427. User.current = nil
  1428. users = [User.find(2), User.find(4)]
  1429. assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
  1430. principals_options_for_select(users)
  1431. end
  1432. def test_principals_options_for_select_with_selected
  1433. User.current = nil
  1434. users = [User.find(2), User.find(4)]
  1435. assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
  1436. principals_options_for_select(users, User.find(4))
  1437. end
  1438. def test_principals_options_for_select_with_users_and_groups
  1439. User.current = nil
  1440. set_language_if_valid 'en'
  1441. users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
  1442. assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
  1443. %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
  1444. principals_options_for_select(users)
  1445. end
  1446. def test_principals_options_for_select_with_empty_collection
  1447. assert_equal '', principals_options_for_select([])
  1448. end
  1449. def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection
  1450. set_language_if_valid 'en'
  1451. users = [User.find(2), User.find(4)]
  1452. User.current = User.find(4)
  1453. assert_include '<option value="4">&lt;&lt; me &gt;&gt;</option>', principals_options_for_select(users)
  1454. end
  1455. def test_stylesheet_link_tag_should_pick_the_default_stylesheet
  1456. assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
  1457. end
  1458. def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet
  1459. assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo)
  1460. end
  1461. def test_image_tag_should_pick_the_default_image
  1462. assert_match 'src="/images/image.png"', image_tag("image.png")
  1463. end
  1464. def test_image_tag_should_pick_the_theme_image_if_it_exists
  1465. theme = Redmine::Themes.themes.last
  1466. theme.images << 'image.png'
  1467. with_settings :ui_theme => theme.id do
  1468. assert_match %|src="/themes/#{theme.dir}/images/image.png"|, image_tag("image.png")
  1469. assert_match %|src="/images/other.png"|, image_tag("other.png")
  1470. end
  1471. ensure
  1472. theme.images.delete 'image.png'
  1473. end
  1474. def test_image_tag_sfor_plugin_should_pick_the_plugin_image
  1475. assert_match 'src="/plugin_assets/foo/images/image.png"', image_tag("image.png", :plugin => :foo)
  1476. end
  1477. def test_javascript_include_tag_should_pick_the_default_javascript
  1478. assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts")
  1479. end
  1480. def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript
  1481. assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo)
  1482. end
  1483. def test_raw_json_should_escape_closing_tags
  1484. s = raw_json(["<foo>bar</foo>"])
  1485. assert_include '\/foo', s
  1486. end
  1487. def test_raw_json_should_be_html_safe
  1488. s = raw_json(["foo"])
  1489. assert s.html_safe?
  1490. end
  1491. def test_html_title_should_app_title_if_not_set
  1492. assert_equal 'Redmine', html_title
  1493. end
  1494. def test_html_title_should_join_items
  1495. html_title 'Foo', 'Bar'
  1496. assert_equal 'Foo - Bar - Redmine', html_title
  1497. end
  1498. def test_html_title_should_append_current_project_name
  1499. @project = Project.find(1)
  1500. html_title 'Foo', 'Bar'
  1501. assert_equal 'Foo - Bar - eCookbook - Redmine', html_title
  1502. end
  1503. def test_title_should_return_a_h2_tag
  1504. assert_equal '<h2>Foo</h2>', title('Foo')
  1505. end
  1506. def test_title_should_set_html_title
  1507. title('Foo')
  1508. assert_equal 'Foo - Redmine', html_title
  1509. end
  1510. def test_title_should_turn_arrays_into_links
  1511. assert_equal '<h2><a href="/foo">Foo</a></h2>', title(['Foo', '/foo'])
  1512. assert_equal 'Foo - Redmine', html_title
  1513. end
  1514. def test_title_should_join_items
  1515. assert_equal '<h2>Foo &#187; Bar</h2>', title('Foo', 'Bar')
  1516. assert_equal 'Bar - Foo - Redmine', html_title
  1517. end
  1518. def test_favicon_path
  1519. assert_match %r{^/favicon\.ico}, favicon_path
  1520. end
  1521. def test_favicon_path_with_suburi
  1522. Redmine::Utils.relative_url_root = '/foo'
  1523. assert_match %r{^/foo/favicon\.ico}, favicon_path
  1524. ensure
  1525. Redmine::Utils.relative_url_root = ''
  1526. end
  1527. def test_favicon_url
  1528. assert_match %r{^http://test\.host/favicon\.ico}, favicon_url
  1529. end
  1530. def test_favicon_url_with_suburi
  1531. Redmine::Utils.relative_url_root = '/foo'
  1532. assert_match %r{^http://test\.host/foo/favicon\.ico}, favicon_url
  1533. ensure
  1534. Redmine::Utils.relative_url_root = ''
  1535. end
  1536. def test_truncate_single_line
  1537. str = "01234"
  1538. result = truncate_single_line_raw("#{str}\n#{str}", 10)
  1539. assert_equal "01234 0...", result
  1540. assert !result.html_safe?
  1541. result = truncate_single_line_raw("#{str}<&#>\n#{str}#{str}", 16)
  1542. assert_equal "01234<&#> 012...", result
  1543. assert !result.html_safe?
  1544. end
  1545. def test_truncate_single_line_non_ascii
  1546. ja = '日本語'
  1547. result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10)
  1548. assert_equal "#{ja} #{ja}...", result
  1549. assert !result.html_safe?
  1550. end
  1551. def test_back_url_should_remove_utf8_checkmark_from_referer
  1552. stubs(:request).returns(stub(:env => {'HTTP_REFERER' => "/path?utf8=\u2713&foo=bar"}))
  1553. assert_equal "/path?foo=bar", back_url
  1554. end
  1555. def test_hours_formatting
  1556. set_language_if_valid 'en'
  1557. with_settings :timespan_format => 'minutes' do
  1558. assert_equal '0:45', format_hours(0.75)
  1559. assert_equal '0:45 h', l_hours_short(0.75)
  1560. assert_equal '0:45 hour', l_hours(0.75)
  1561. end
  1562. with_settings :timespan_format => 'decimal' do
  1563. assert_equal '0.75', format_hours(0.75)
  1564. assert_equal '0.75 h', l_hours_short(0.75)
  1565. assert_equal '0.75 hour', l_hours(0.75)
  1566. end
  1567. end
  1568. def test_html_hours
  1569. assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>', html_hours('0:45')
  1570. assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">.75</span>', html_hours('0.75')
  1571. end
  1572. def test_form_for_includes_name_attribute
  1573. assert_match(/name="new_issue-[a-z0-9]{8}"/, form_for(Issue.new){})
  1574. end
  1575. def test_labelled_form_for_includes_name_attribute
  1576. assert_match(/name="new_issue-[a-z0-9]{8}"/, labelled_form_for(Issue.new){})
  1577. end
  1578. private
  1579. def wiki_links_with_special_characters
  1580. return {
  1581. '[[Jack & Coke]]' =>
  1582. link_to("Jack & Coke",
  1583. "/projects/ecookbook/wiki/Jack_&_Coke",
  1584. :class => "wiki-page new"),
  1585. '[[a "quoted" name]]' =>
  1586. link_to("a \"quoted\" name",
  1587. "/projects/ecookbook/wiki/A_%22quoted%22_name",
  1588. :class => "wiki-page new"),
  1589. '[[le français, c\'est super]]' =>
  1590. link_to("le français, c\'est super",
  1591. "/projects/ecookbook/wiki/Le_fran%C3%A7ais_c'est_super",
  1592. :class => "wiki-page new"),
  1593. '[[broken < less]]' =>
  1594. link_to("broken < less",
  1595. "/projects/ecookbook/wiki/Broken_%3C_less",
  1596. :class => "wiki-page new"),
  1597. '[[broken > more]]' =>
  1598. link_to("broken > more",
  1599. "/projects/ecookbook/wiki/Broken_%3E_more",
  1600. :class => "wiki-page new"),
  1601. '[[[foo]Including [square brackets] in wiki title]]' =>
  1602. link_to("[foo]Including [square brackets] in wiki title",
  1603. "/projects/ecookbook/wiki/%5Bfoo%5DIncluding_%5Bsquare_brackets%5D_in_wiki_title",
  1604. :class => "wiki-page new"),
  1605. }
  1606. end
  1607. def test_export_csv_encoding_select_tag_should_return_nil_when_general_csv_encoding_is_UTF8
  1608. with_locale 'az' do
  1609. assert_equal l(:general_csv_encoding), 'UTF-8'
  1610. assert_nil export_csv_encoding_select_tag
  1611. end
  1612. end
  1613. def test_export_csv_encoding_select_tag_should_have_two_option_when_general_csv_encoding_is_not_UTF8
  1614. with_locale 'en' do
  1615. assert_not_equal l(:general_csv_encoding), 'UTF-8'
  1616. result = export_csv_encoding_select_tag
  1617. assert_select_in result, "option[selected='selected'][value=#{l(:general_csv_encoding)}]", :text => l(:general_csv_encoding)
  1618. assert_select_in result, "option[value='UTF-8']", :text => 'UTF-8'
  1619. end
  1620. end
  1621. end