comparison test/unit/helpers/application_helper_test.rb @ 119:8661b858af72

* Update to Redmine trunk rev 4705
author Chris Cannam
date Thu, 13 Jan 2011 14:12:06 +0000
parents 94944d00e43c
children cd2282d2aa55 0579821a129a
comparison
equal deleted inserted replaced
39:150ceac17a8d 119:8661b858af72
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.dirname(__FILE__) + '/../../test_helper' 18 require File.expand_path('../../../test_helper', __FILE__)
19 19
20 class ApplicationHelperTest < ActionView::TestCase 20 class ApplicationHelperTest < ActionView::TestCase
21 21
22 fixtures :projects, :roles, :enabled_modules, :users, 22 fixtures :projects, :roles, :enabled_modules, :users,
23 :repositories, :changesets, 23 :repositories, :changesets,
145 # escaping 145 # escaping
146 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>', 146 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
147 } 147 }
148 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } 148 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
149 end 149 end
150 150
151 def test_redmine_links 151 def test_redmine_links
152 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, 152 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
153 :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') 153 :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
154 154
155 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, 155 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
222 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', 222 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
223 } 223 }
224 @project = Project.find(1) 224 @project = Project.find(1)
225 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } 225 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
226 end 226 end
227 227
228 def test_redmine_links_git_commit
229 changeset_link = link_to('abcd',
230 {
231 :controller => 'repositories',
232 :action => 'revision',
233 :id => 'subproject1',
234 :rev => 'abcd',
235 },
236 :class => 'changeset', :title => 'test commit')
237 to_test = {
238 'commit:abcd' => changeset_link,
239 }
240 @project = Project.find(3)
241 r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
242 assert r
243 c = Changeset.new(:repository => r,
244 :committed_on => Time.now,
245 :revision => 'abcd',
246 :scmid => 'abcd',
247 :comments => 'test commit')
248 assert( c.save )
249 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
250 end
251
252 # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
253 def test_redmine_links_darcs_commit
254 changeset_link = link_to('20080308225258-98289-abcd456efg.gz',
255 {
256 :controller => 'repositories',
257 :action => 'revision',
258 :id => 'subproject1',
259 :rev => '123',
260 },
261 :class => 'changeset', :title => 'test commit')
262 to_test = {
263 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
264 }
265 @project = Project.find(3)
266 r = Repository::Darcs.create!(:project => @project, :url => '/tmp/test/darcs')
267 assert r
268 c = Changeset.new(:repository => r,
269 :committed_on => Time.now,
270 :revision => '123',
271 :scmid => '20080308225258-98289-abcd456efg.gz',
272 :comments => 'test commit')
273 assert( c.save )
274 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
275 end
276
277 def test_redmine_links_mercurial_commit
278 changeset_link_rev = link_to('r123',
279 {
280 :controller => 'repositories',
281 :action => 'revision',
282 :id => 'subproject1',
283 :rev => '123' ,
284 },
285 :class => 'changeset', :title => 'test commit')
286 changeset_link_commit = link_to('abcd',
287 {
288 :controller => 'repositories',
289 :action => 'revision',
290 :id => 'subproject1',
291 :rev => 'abcd' ,
292 },
293 :class => 'changeset', :title => 'test commit')
294 to_test = {
295 'r123' => changeset_link_rev,
296 'commit:abcd' => changeset_link_commit,
297 }
298 @project = Project.find(3)
299 r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
300 assert r
301 c = Changeset.new(:repository => r,
302 :committed_on => Time.now,
303 :revision => '123',
304 :scmid => 'abcd',
305 :comments => 'test commit')
306 assert( c.save )
307 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
308 end
309
228 def test_attachment_links 310 def test_attachment_links
229 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment') 311 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment')
230 to_test = { 312 to_test = {
231 'attachment:error281.txt' => attachment_link 313 'attachment:error281.txt' => attachment_link
232 } 314 }
273 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>", 355 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
274 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>", 356 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
275 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>", 357 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
276 # remove attributes except class 358 # remove attributes except class
277 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>", 359 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
360 '<pre class="foo">some text</pre>' => '<pre class="foo">some text</pre>',
361 "<pre class='foo bar'>some text</pre>" => "<pre class='foo bar'>some text</pre>",
362 '<pre class="foo bar">some text</pre>' => '<pre class="foo bar">some text</pre>',
278 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>", 363 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
364 # xss
365 '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
366 '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
279 } 367 }
280 to_test.each { |text, result| assert_equal result, textilizable(text) } 368 to_test.each { |text, result| assert_equal result, textilizable(text) }
281 end 369 end
282 370
283 def test_allowed_html_tags 371 def test_allowed_html_tags
420 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. 508 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
421 509
422 h2. Subtitle with [[Wiki|another Wiki]] link 510 h2. Subtitle with [[Wiki|another Wiki]] link
423 511
424 h2. Subtitle with %{color:red}red text% 512 h2. Subtitle with %{color:red}red text%
425 513
514 <pre>
515 some code
516 </pre>
517
426 h3. Subtitle with *some* _modifiers_ 518 h3. Subtitle with *some* _modifiers_
427 519
428 h1. Another title 520 h1. Another title
429 521
430 h3. An "Internet link":http://www.redmine.org/ inside subtitle 522 h3. An "Internet link":http://www.redmine.org/ inside subtitle
456 '</ul>' + 548 '</ul>' +
457 '</li>' + 549 '</li>' +
458 '</ul>' 550 '</ul>'
459 551
460 @project = Project.find(1) 552 @project = Project.find(1)
461 assert textilizable(raw).gsub("\n", "").include?(expected) 553 assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw)
462 end 554 end
463 555
464 def test_table_of_content_should_contain_included_page_headings 556 def test_table_of_content_should_contain_included_page_headings
465 raw = <<-RAW 557 raw = <<-RAW
466 {{toc}} 558 {{toc}}
598 Date.today + 20000 => 'Due in over 54 years', 690 Date.today + 20000 => 'Due in over 54 years',
599 Date.today - 1 => '1 day late', 691 Date.today - 1 => '1 day late',
600 Date.today - 100 => 'about 3 months late', 692 Date.today - 100 => 'about 3 months late',
601 Date.today - 20000 => 'over 54 years late', 693 Date.today - 20000 => 'over 54 years late',
602 } 694 }
695 ::I18n.locale = :en
603 to_test.each do |date, expected| 696 to_test.each do |date, expected|
604 assert_equal expected, due_date_distance_in_words(date) 697 assert_equal expected, due_date_distance_in_words(date)
605 end 698 end
606 end 699 end
607 700