Mercurial > hg > soundsoftware-site
comparison test/unit/helpers/application_helper_test.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children | fb9a13467253 |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
374 end | 374 end |
375 | 375 |
376 def test_redmine_links_with_a_different_project_before_current_project | 376 def test_redmine_links_with_a_different_project_before_current_project |
377 vp1 = Version.generate!(:project_id => 1, :name => '1.4.4') | 377 vp1 = Version.generate!(:project_id => 1, :name => '1.4.4') |
378 vp3 = Version.generate!(:project_id => 3, :name => '1.4.4') | 378 vp3 = Version.generate!(:project_id => 3, :name => '1.4.4') |
379 | |
380 @project = Project.find(3) | 379 @project = Project.find(3) |
381 assert_equal %(<p><a href="/versions/#{vp1.id}" class="version">1.4.4</a> <a href="/versions/#{vp3.id}" class="version">1.4.4</a></p>), | 380 result1 = link_to("1.4.4", "/versions/#{vp1.id}", :class => "version") |
382 textilizable("ecookbook:version:1.4.4 version:1.4.4") | 381 result2 = link_to("1.4.4", "/versions/#{vp3.id}", :class => "version") |
382 assert_equal "<p>#{result1} #{result2}</p>", | |
383 textilizable("ecookbook:version:1.4.4 version:1.4.4") | |
383 end | 384 end |
384 | 385 |
385 def test_escaped_redmine_links_should_not_be_parsed | 386 def test_escaped_redmine_links_should_not_be_parsed |
386 to_test = [ | 387 to_test = [ |
387 '#3.', | 388 '#3.', |
398 @project = Project.find(1) | 399 @project = Project.find(1) |
399 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" } | 400 to_test.each { |text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed" } |
400 end | 401 end |
401 | 402 |
402 def test_cross_project_redmine_links | 403 def test_cross_project_redmine_links |
403 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, | 404 source_link = link_to('ecookbook:source:/some/file', |
404 :class => 'source') | 405 {:controller => 'repositories', :action => 'entry', |
405 | 406 :id => 'ecookbook', :path => ['some', 'file']}, |
406 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, | 407 :class => 'source') |
407 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') | 408 changeset_link = link_to('ecookbook:r2', |
408 | 409 {:controller => 'repositories', :action => 'revision', |
410 :id => 'ecookbook', :rev => 2}, | |
411 :class => 'changeset', | |
412 :title => 'This commit fixes #1, #2 and references #1 & #3') | |
409 to_test = { | 413 to_test = { |
410 # documents | 414 # documents |
411 'document:"Test document"' => 'document:"Test document"', | 415 'document:"Test document"' => 'document:"Test document"', |
412 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>', | 416 'ecookbook:document:"Test document"' => |
417 link_to("Test document", "/documents/1", :class => "document"), | |
413 'invalid:document:"Test document"' => 'invalid:document:"Test document"', | 418 'invalid:document:"Test document"' => 'invalid:document:"Test document"', |
414 # versions | 419 # versions |
415 'version:"1.0"' => 'version:"1.0"', | 420 'version:"1.0"' => 'version:"1.0"', |
416 'ecookbook:version:"1.0"' => '<a href="/versions/2" class="version">1.0</a>', | 421 'ecookbook:version:"1.0"' => |
422 link_to("1.0", "/versions/2", :class => "version"), | |
417 'invalid:version:"1.0"' => 'invalid:version:"1.0"', | 423 'invalid:version:"1.0"' => 'invalid:version:"1.0"', |
418 # changeset | 424 # changeset |
419 'r2' => 'r2', | 425 'r2' => 'r2', |
420 'ecookbook:r2' => changeset_link, | 426 'ecookbook:r2' => changeset_link, |
421 'invalid:r2' => 'invalid:r2', | 427 'invalid:r2' => 'invalid:r2', |
423 'source:/some/file' => 'source:/some/file', | 429 'source:/some/file' => 'source:/some/file', |
424 'ecookbook:source:/some/file' => source_link, | 430 'ecookbook:source:/some/file' => source_link, |
425 'invalid:source:/some/file' => 'invalid:source:/some/file', | 431 'invalid:source:/some/file' => 'invalid:source:/some/file', |
426 } | 432 } |
427 @project = Project.find(3) | 433 @project = Project.find(3) |
428 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } | 434 to_test.each do |text, result| |
435 assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" | |
436 end | |
437 end | |
438 | |
439 def test_redmine_links_by_name_should_work_with_html_escaped_characters | |
440 v = Version.generate!(:name => "Test & Show.txt", :project_id => 1) | |
441 link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version") | |
442 | |
443 @project = v.project | |
444 assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"') | |
445 end | |
446 | |
447 def test_link_to_issue_subject | |
448 issue = Issue.generate!(:subject => "01234567890123456789") | |
449 str = link_to_issue(issue, :truncate => 10) | |
450 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes) | |
451 assert_equal "#{result}: 0123456...", str | |
452 | |
453 issue = Issue.generate!(:subject => "<&>") | |
454 str = link_to_issue(issue) | |
455 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes) | |
456 assert_equal "#{result}: <&>", str | |
457 | |
458 issue = Issue.generate!(:subject => "<&>0123456789012345") | |
459 str = link_to_issue(issue, :truncate => 10) | |
460 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", :class => issue.css_classes) | |
461 assert_equal "#{result}: <&>0123...", str | |
462 end | |
463 | |
464 def test_link_to_issue_title | |
465 long_str = "0123456789" * 5 | |
466 | |
467 issue = Issue.generate!(:subject => "#{long_str}01234567890123456789") | |
468 str = link_to_issue(issue, :subject => false) | |
469 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", | |
470 :class => issue.css_classes, | |
471 :title => "#{long_str}0123456...") | |
472 assert_equal result, str | |
473 | |
474 issue = Issue.generate!(:subject => "<&>#{long_str}01234567890123456789") | |
475 str = link_to_issue(issue, :subject => false) | |
476 result = link_to("Bug ##{issue.id}", "/issues/#{issue.id}", | |
477 :class => issue.css_classes, | |
478 :title => "<&>#{long_str}0123...") | |
479 assert_equal result, str | |
429 end | 480 end |
430 | 481 |
431 def test_multiple_repositories_redmine_links | 482 def test_multiple_repositories_redmine_links |
432 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg') | 483 svn = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn_repo-1', :url => 'file:///foo/hg') |
433 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123') | 484 Changeset.create!(:repository => svn, :committed_on => Time.now, :revision => '123') |
577 assert( c.save ) | 628 assert( c.save ) |
578 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | 629 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
579 end | 630 end |
580 | 631 |
581 def test_attachment_links | 632 def test_attachment_links |
582 to_test = { | 633 text = 'attachment:error281.txt' |
583 'attachment:error281.txt' => '<a href="/attachments/download/1/error281.txt" class="attachment">error281.txt</a>' | 634 result = link_to("error281.txt", "/attachments/download/1/error281.txt", |
584 } | 635 :class => "attachment") |
585 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } | 636 assert_equal "<p>#{result}</p>", |
637 textilizable(text, | |
638 :attachments => Issue.find(3).attachments), | |
639 "#{text} failed" | |
586 end | 640 end |
587 | 641 |
588 def test_attachment_link_should_link_to_latest_attachment | 642 def test_attachment_link_should_link_to_latest_attachment |
589 set_tmp_attachments_directory | 643 set_tmp_attachments_directory |
590 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago) | 644 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago) |
591 a2 = Attachment.generate!(:filename => "test.txt") | 645 a2 = Attachment.generate!(:filename => "test.txt") |
592 | 646 result = link_to("test.txt", "/attachments/download/#{a2.id}/test.txt", |
593 assert_equal %(<p><a href="/attachments/download/#{a2.id}/test.txt" class="attachment">test.txt</a></p>), | 647 :class => "attachment") |
594 textilizable('attachment:test.txt', :attachments => [a1, a2]) | 648 assert_equal "<p>#{result}</p>", |
649 textilizable('attachment:test.txt', :attachments => [a1, a2]) | |
595 end | 650 end |
596 | 651 |
597 def test_wiki_links | 652 def test_wiki_links |
598 russian_eacape = CGI.escape(@russian_test) | 653 russian_eacape = CGI.escape(@russian_test) |
599 to_test = { | 654 to_test = { |
600 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', | 655 '[[CookBook documentation]]' => |
601 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', | 656 link_to("CookBook documentation", |
657 "/projects/ecookbook/wiki/CookBook_documentation", | |
658 :class => "wiki-page"), | |
659 '[[Another page|Page]]' => | |
660 link_to("Page", | |
661 "/projects/ecookbook/wiki/Another_page", | |
662 :class => "wiki-page"), | |
602 # title content should be formatted | 663 # title content should be formatted |
603 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>', | 664 '[[Another page|With _styled_ *title*]]' => |
604 '[[Another page|With title containing <strong>HTML entities & markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing <strong>HTML entities & markups</strong></a>', | 665 link_to("With <em>styled</em> <strong>title</strong>".html_safe, |
666 "/projects/ecookbook/wiki/Another_page", | |
667 :class => "wiki-page"), | |
668 '[[Another page|With title containing <strong>HTML entities & markups</strong>]]' => | |
669 link_to("With title containing <strong>HTML entities & markups</strong>".html_safe, | |
670 "/projects/ecookbook/wiki/Another_page", | |
671 :class => "wiki-page"), | |
605 # link with anchor | 672 # link with anchor |
606 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', | 673 '[[CookBook documentation#One-section]]' => |
607 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>', | 674 link_to("CookBook documentation", |
675 "/projects/ecookbook/wiki/CookBook_documentation#One-section", | |
676 :class => "wiki-page"), | |
677 '[[Another page#anchor|Page]]' => | |
678 link_to("Page", | |
679 "/projects/ecookbook/wiki/Another_page#anchor", | |
680 :class => "wiki-page"), | |
608 # UTF8 anchor | 681 # UTF8 anchor |
609 "[[Another_page##{@russian_test}|#{@russian_test}]]" => | 682 "[[Another_page##{@russian_test}|#{@russian_test}]]" => |
610 %|<a href="/projects/ecookbook/wiki/Another_page##{russian_eacape}" class="wiki-page">#{@russian_test}</a>|, | 683 link_to(@russian_test, |
684 "/projects/ecookbook/wiki/Another_page##{russian_eacape}", | |
685 :class => "wiki-page"), | |
611 # page that doesn't exist | 686 # page that doesn't exist |
612 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', | 687 '[[Unknown page]]' => |
613 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', | 688 link_to("Unknown page", |
689 "/projects/ecookbook/wiki/Unknown_page", | |
690 :class => "wiki-page new"), | |
691 '[[Unknown page|404]]' => | |
692 link_to("404", | |
693 "/projects/ecookbook/wiki/Unknown_page", | |
694 :class => "wiki-page new"), | |
614 # link to another project wiki | 695 # link to another project wiki |
615 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>', | 696 '[[onlinestore:]]' => |
616 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">Wiki</a>', | 697 link_to("onlinestore", |
617 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>', | 698 "/projects/onlinestore/wiki", |
618 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>', | 699 :class => "wiki-page"), |
619 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', | 700 '[[onlinestore:|Wiki]]' => |
701 link_to("Wiki", | |
702 "/projects/onlinestore/wiki", | |
703 :class => "wiki-page"), | |
704 '[[onlinestore:Start page]]' => | |
705 link_to("Start page", | |
706 "/projects/onlinestore/wiki/Start_page", | |
707 :class => "wiki-page"), | |
708 '[[onlinestore:Start page|Text]]' => | |
709 link_to("Text", | |
710 "/projects/onlinestore/wiki/Start_page", | |
711 :class => "wiki-page"), | |
712 '[[onlinestore:Unknown page]]' => | |
713 link_to("Unknown page", | |
714 "/projects/onlinestore/wiki/Unknown_page", | |
715 :class => "wiki-page new"), | |
620 # striked through link | 716 # striked through link |
621 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>', | 717 '-[[Another page|Page]]-' => |
622 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>', | 718 "<del>".html_safe + |
719 link_to("Page", | |
720 "/projects/ecookbook/wiki/Another_page", | |
721 :class => "wiki-page").html_safe + | |
722 "</del>".html_safe, | |
723 '-[[Another page|Page]] link-' => | |
724 "<del>".html_safe + | |
725 link_to("Page", | |
726 "/projects/ecookbook/wiki/Another_page", | |
727 :class => "wiki-page").html_safe + | |
728 " link</del>".html_safe, | |
623 # escaping | 729 # escaping |
624 '![[Another page|Page]]' => '[[Another page|Page]]', | 730 '![[Another page|Page]]' => '[[Another page|Page]]', |
625 # project does not exist | 731 # project does not exist |
626 '[[unknowproject:Start]]' => '[[unknowproject:Start]]', | 732 '[[unknowproject:Start]]' => '[[unknowproject:Start]]', |
627 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]', | 733 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]', |
628 } | 734 } |
629 | |
630 @project = Project.find(1) | 735 @project = Project.find(1) |
631 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | 736 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
632 end | 737 end |
633 | 738 |
634 def test_wiki_links_within_local_file_generation_context | 739 def test_wiki_links_within_local_file_generation_context |
635 | |
636 to_test = { | 740 to_test = { |
637 # link to a page | 741 # link to a page |
638 '[[CookBook documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">CookBook documentation</a>', | 742 '[[CookBook documentation]]' => |
639 '[[CookBook documentation|documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">documentation</a>', | 743 link_to("CookBook documentation", "CookBook_documentation.html", |
640 '[[CookBook documentation#One-section]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">CookBook documentation</a>', | 744 :class => "wiki-page"), |
641 '[[CookBook documentation#One-section|documentation]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">documentation</a>', | 745 '[[CookBook documentation|documentation]]' => |
746 link_to("documentation", "CookBook_documentation.html", | |
747 :class => "wiki-page"), | |
748 '[[CookBook documentation#One-section]]' => | |
749 link_to("CookBook documentation", "CookBook_documentation.html#One-section", | |
750 :class => "wiki-page"), | |
751 '[[CookBook documentation#One-section|documentation]]' => | |
752 link_to("documentation", "CookBook_documentation.html#One-section", | |
753 :class => "wiki-page"), | |
642 # page that doesn't exist | 754 # page that doesn't exist |
643 '[[Unknown page]]' => '<a href="Unknown_page.html" class="wiki-page new">Unknown page</a>', | 755 '[[Unknown page]]' => |
644 '[[Unknown page|404]]' => '<a href="Unknown_page.html" class="wiki-page new">404</a>', | 756 link_to("Unknown page", "Unknown_page.html", |
645 '[[Unknown page#anchor]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">Unknown page</a>', | 757 :class => "wiki-page new"), |
646 '[[Unknown page#anchor|404]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">404</a>', | 758 '[[Unknown page|404]]' => |
647 } | 759 link_to("404", "Unknown_page.html", |
648 | 760 :class => "wiki-page new"), |
761 '[[Unknown page#anchor]]' => | |
762 link_to("Unknown page", "Unknown_page.html#anchor", | |
763 :class => "wiki-page new"), | |
764 '[[Unknown page#anchor|404]]' => | |
765 link_to("404", "Unknown_page.html#anchor", | |
766 :class => "wiki-page new"), | |
767 } | |
649 @project = Project.find(1) | 768 @project = Project.find(1) |
650 | 769 to_test.each do |text, result| |
651 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) } | 770 assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) |
771 end | |
652 end | 772 end |
653 | 773 |
654 def test_wiki_links_within_wiki_page_context | 774 def test_wiki_links_within_wiki_page_context |
655 | |
656 page = WikiPage.find_by_title('Another_page' ) | 775 page = WikiPage.find_by_title('Another_page' ) |
657 | 776 to_test = { |
658 to_test = { | 777 '[[CookBook documentation]]' => |
659 # link to another page | 778 link_to("CookBook documentation", |
660 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', | 779 "/projects/ecookbook/wiki/CookBook_documentation", |
661 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>', | 780 :class => "wiki-page"), |
662 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', | 781 '[[CookBook documentation|documentation]]' => |
663 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>', | 782 link_to("documentation", |
783 "/projects/ecookbook/wiki/CookBook_documentation", | |
784 :class => "wiki-page"), | |
785 '[[CookBook documentation#One-section]]' => | |
786 link_to("CookBook documentation", | |
787 "/projects/ecookbook/wiki/CookBook_documentation#One-section", | |
788 :class => "wiki-page"), | |
789 '[[CookBook documentation#One-section|documentation]]' => | |
790 link_to("documentation", | |
791 "/projects/ecookbook/wiki/CookBook_documentation#One-section", | |
792 :class => "wiki-page"), | |
664 # link to the current page | 793 # link to the current page |
665 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>', | 794 '[[Another page]]' => |
666 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', | 795 link_to("Another page", |
667 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>', | 796 "/projects/ecookbook/wiki/Another_page", |
668 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>', | 797 :class => "wiki-page"), |
798 '[[Another page|Page]]' => | |
799 link_to("Page", | |
800 "/projects/ecookbook/wiki/Another_page", | |
801 :class => "wiki-page"), | |
802 '[[Another page#anchor]]' => | |
803 link_to("Another page", | |
804 "#anchor", | |
805 :class => "wiki-page"), | |
806 '[[Another page#anchor|Page]]' => | |
807 link_to("Page", | |
808 "#anchor", | |
809 :class => "wiki-page"), | |
669 # page that doesn't exist | 810 # page that doesn't exist |
670 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>', | 811 '[[Unknown page]]' => |
671 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>', | 812 link_to("Unknown page", |
672 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>', | 813 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page", |
673 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>', | 814 :class => "wiki-page new"), |
674 } | 815 '[[Unknown page|404]]' => |
675 | 816 link_to("404", |
817 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page", | |
818 :class => "wiki-page new"), | |
819 '[[Unknown page#anchor]]' => | |
820 link_to("Unknown page", | |
821 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor", | |
822 :class => "wiki-page new"), | |
823 '[[Unknown page#anchor|404]]' => | |
824 link_to("404", | |
825 "/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor", | |
826 :class => "wiki-page new"), | |
827 } | |
676 @project = Project.find(1) | 828 @project = Project.find(1) |
677 | 829 to_test.each do |text, result| |
678 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text) } | 830 assert_equal "<p>#{result}</p>", |
831 textilizable(WikiContent.new( :text => text, :page => page ), :text) | |
832 end | |
679 end | 833 end |
680 | 834 |
681 def test_wiki_links_anchor_option_should_prepend_page_title_to_href | 835 def test_wiki_links_anchor_option_should_prepend_page_title_to_href |
682 | |
683 to_test = { | 836 to_test = { |
684 # link to a page | 837 # link to a page |
685 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>', | 838 '[[CookBook documentation]]' => |
686 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>', | 839 link_to("CookBook documentation", |
687 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>', | 840 "#CookBook_documentation", |
688 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>', | 841 :class => "wiki-page"), |
842 '[[CookBook documentation|documentation]]' => | |
843 link_to("documentation", | |
844 "#CookBook_documentation", | |
845 :class => "wiki-page"), | |
846 '[[CookBook documentation#One-section]]' => | |
847 link_to("CookBook documentation", | |
848 "#CookBook_documentation_One-section", | |
849 :class => "wiki-page"), | |
850 '[[CookBook documentation#One-section|documentation]]' => | |
851 link_to("documentation", | |
852 "#CookBook_documentation_One-section", | |
853 :class => "wiki-page"), | |
689 # page that doesn't exist | 854 # page that doesn't exist |
690 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>', | 855 '[[Unknown page]]' => |
691 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>', | 856 link_to("Unknown page", |
692 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>', | 857 "#Unknown_page", |
693 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>', | 858 :class => "wiki-page new"), |
694 } | 859 '[[Unknown page|404]]' => |
695 | 860 link_to("404", |
861 "#Unknown_page", | |
862 :class => "wiki-page new"), | |
863 '[[Unknown page#anchor]]' => | |
864 link_to("Unknown page", | |
865 "#Unknown_page_anchor", | |
866 :class => "wiki-page new"), | |
867 '[[Unknown page#anchor|404]]' => | |
868 link_to("404", | |
869 "#Unknown_page_anchor", | |
870 :class => "wiki-page new"), | |
871 } | |
696 @project = Project.find(1) | 872 @project = Project.find(1) |
697 | 873 to_test.each do |text, result| |
698 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) } | 874 assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) |
875 end | |
699 end | 876 end |
700 | 877 |
701 def test_html_tags | 878 def test_html_tags |
702 to_test = { | 879 to_test = { |
703 "<div>content</div>" => "<p><div>content</div></p>", | 880 "<div>content</div>" => "<p><div>content</div></p>", |
764 | 941 |
765 #1 | 942 #1 |
766 </pre> | 943 </pre> |
767 RAW | 944 RAW |
768 | 945 |
946 result1 = link_to("CookBook documentation", | |
947 "/projects/ecookbook/wiki/CookBook_documentation", | |
948 :class => "wiki-page") | |
949 result2 = link_to('#1', | |
950 "/issues/1", | |
951 :class => Issue.find(1).css_classes, | |
952 :title => "Can't print recipes (New)") | |
953 | |
769 expected = <<-EXPECTED | 954 expected = <<-EXPECTED |
770 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p> | 955 <p>#{result1}</p> |
771 <p><a href="/issues/1" class="#{Issue.find(1).css_classes}" title="Can't print recipes (New)">#1</a></p> | 956 <p>#{result2}</p> |
772 <pre> | 957 <pre> |
773 [[CookBook documentation]] | 958 [[CookBook documentation]] |
774 | 959 |
775 #1 | 960 #1 |
776 </pre> | 961 </pre> |
815 assert_equal 'test1/test2', to_path_param('//test1/test2/') | 1000 assert_equal 'test1/test2', to_path_param('//test1/test2/') |
816 assert_equal nil, to_path_param('/') | 1001 assert_equal nil, to_path_param('/') |
817 end | 1002 end |
818 | 1003 |
819 def test_wiki_links_in_tables | 1004 def test_wiki_links_in_tables |
820 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => | 1005 text = "|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" |
821 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' + | 1006 link1 = link_to("Link title", "/projects/ecookbook/wiki/Page", :class => "wiki-page new") |
822 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' + | 1007 link2 = link_to("Other title", "/projects/ecookbook/wiki/Other_Page", :class => "wiki-page new") |
823 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>' | 1008 link3 = link_to("Last page", "/projects/ecookbook/wiki/Last_page", :class => "wiki-page new") |
824 } | 1009 result = "<tr><td>#{link1}</td>" + |
1010 "<td>#{link2}</td>" + | |
1011 "</tr><tr><td>Cell 21</td><td>#{link3}</td></tr>" | |
825 @project = Project.find(1) | 1012 @project = Project.find(1) |
826 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } | 1013 assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') |
827 end | 1014 end |
828 | 1015 |
829 def test_text_formatting | 1016 def test_text_formatting |
830 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', | 1017 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', |
831 '(_text within parentheses_)' => '(<em>text within parentheses</em>)', | 1018 '(_text within parentheses_)' => '(<em>text within parentheses</em>)', |
986 | 1173 |
987 @project = Project.find(1) | 1174 @project = Project.find(1) |
988 assert textilizable(raw).gsub("\n", "").include?(expected) | 1175 assert textilizable(raw).gsub("\n", "").include?(expected) |
989 end | 1176 end |
990 | 1177 |
1178 def test_toc_with_textile_formatting_should_be_parsed | |
1179 with_settings :text_formatting => 'textile' do | |
1180 assert_select_in textilizable("{{toc}}\n\nh1. Heading"), 'ul.toc li', :text => 'Heading' | |
1181 assert_select_in textilizable("{{<toc}}\n\nh1. Heading"), 'ul.toc.left li', :text => 'Heading' | |
1182 assert_select_in textilizable("{{>toc}}\n\nh1. Heading"), 'ul.toc.right li', :text => 'Heading' | |
1183 end | |
1184 end | |
1185 | |
1186 if Object.const_defined?(:Redcarpet) | |
1187 def test_toc_with_markdown_formatting_should_be_parsed | |
1188 with_settings :text_formatting => 'markdown' do | |
1189 assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading' | |
1190 assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading' | |
1191 assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading' | |
1192 end | |
1193 end | |
1194 end | |
1195 | |
991 def test_section_edit_links | 1196 def test_section_edit_links |
992 raw = <<-RAW | 1197 raw = <<-RAW |
993 h1. Title | 1198 h1. Title |
994 | 1199 |
995 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | 1200 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
1075 end | 1280 end |
1076 end | 1281 end |
1077 | 1282 |
1078 def test_link_to_user | 1283 def test_link_to_user |
1079 user = User.find(2) | 1284 user = User.find(2) |
1080 assert_equal '<a href="/users/2" class="user active">John Smith</a>', link_to_user(user) | 1285 result = link_to("John Smith", "/users/2", :class => "user active") |
1286 assert_equal result, link_to_user(user) | |
1081 end | 1287 end |
1082 | 1288 |
1083 def test_link_to_user_should_not_link_to_locked_user | 1289 def test_link_to_user_should_not_link_to_locked_user |
1084 with_current_user nil do | 1290 with_current_user nil do |
1085 user = User.find(5) | 1291 user = User.find(5) |
1090 | 1296 |
1091 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin | 1297 def test_link_to_user_should_link_to_locked_user_if_current_user_is_admin |
1092 with_current_user User.find(1) do | 1298 with_current_user User.find(1) do |
1093 user = User.find(5) | 1299 user = User.find(5) |
1094 assert user.locked? | 1300 assert user.locked? |
1095 assert_equal '<a href="/users/5" class="user locked">Dave2 Lopper2</a>', link_to_user(user) | 1301 result = link_to("Dave2 Lopper2", "/users/5", :class => "user locked") |
1302 assert_equal result, link_to_user(user) | |
1096 end | 1303 end |
1097 end | 1304 end |
1098 | 1305 |
1099 def test_link_to_user_should_not_link_to_anonymous | 1306 def test_link_to_user_should_not_link_to_anonymous |
1100 user = User.anonymous | 1307 user = User.anonymous |
1107 a = Attachment.find(3) | 1314 a = Attachment.find(3) |
1108 assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>', | 1315 assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>', |
1109 link_to_attachment(a) | 1316 link_to_attachment(a) |
1110 assert_equal '<a href="/attachments/3/logo.gif">Text</a>', | 1317 assert_equal '<a href="/attachments/3/logo.gif">Text</a>', |
1111 link_to_attachment(a, :text => 'Text') | 1318 link_to_attachment(a, :text => 'Text') |
1112 assert_equal '<a href="/attachments/3/logo.gif" class="foo">logo.gif</a>', | 1319 result = link_to("logo.gif", "/attachments/3/logo.gif", :class => "foo") |
1320 assert_equal result, | |
1113 link_to_attachment(a, :class => 'foo') | 1321 link_to_attachment(a, :class => 'foo') |
1114 assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>', | 1322 assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>', |
1115 link_to_attachment(a, :download => true) | 1323 link_to_attachment(a, :download => true) |
1116 assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>', | 1324 assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>', |
1117 link_to_attachment(a, :only_path => false) | 1325 link_to_attachment(a, :only_path => false) |
1129 link_to_project(project) | 1337 link_to_project(project) |
1130 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>), | 1338 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>), |
1131 link_to_project(project, :action => 'settings') | 1339 link_to_project(project, :action => 'settings') |
1132 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>), | 1340 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>), |
1133 link_to_project(project, {:only_path => false, :jump => 'blah'}) | 1341 link_to_project(project, {:only_path => false, :jump => 'blah'}) |
1134 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>), | 1342 result = link_to("eCookbook", "/projects/ecookbook/settings", :class => "project") |
1343 assert_equal result, | |
1135 link_to_project(project, {:action => 'settings'}, :class => "project") | 1344 link_to_project(project, {:action => 'settings'}, :class => "project") |
1136 end | 1345 end |
1137 | 1346 |
1138 def test_link_to_project_settings | 1347 def test_link_to_project_settings |
1139 project = Project.find(1) | 1348 project = Project.find(1) |
1146 assert_equal 'eCookbook', link_to_project_settings(project) | 1355 assert_equal 'eCookbook', link_to_project_settings(project) |
1147 end | 1356 end |
1148 | 1357 |
1149 def test_link_to_legacy_project_with_numerical_identifier_should_use_id | 1358 def test_link_to_legacy_project_with_numerical_identifier_should_use_id |
1150 # numeric identifier are no longer allowed | 1359 # numeric identifier are no longer allowed |
1151 Project.update_all "identifier=25", "id=1" | 1360 Project.where(:id => 1).update_all(:identifier => 25) |
1152 | |
1153 assert_equal '<a href="/projects/1">eCookbook</a>', | 1361 assert_equal '<a href="/projects/1">eCookbook</a>', |
1154 link_to_project(Project.find(1)) | 1362 link_to_project(Project.find(1)) |
1155 end | 1363 end |
1156 | 1364 |
1157 def test_principals_options_for_select_with_users | 1365 def test_principals_options_for_select_with_users |
1263 | 1471 |
1264 def test_title_should_join_items | 1472 def test_title_should_join_items |
1265 assert_equal '<h2>Foo » Bar</h2>', title('Foo', 'Bar') | 1473 assert_equal '<h2>Foo » Bar</h2>', title('Foo', 'Bar') |
1266 assert_equal 'Bar - Foo - Redmine', html_title | 1474 assert_equal 'Bar - Foo - Redmine', html_title |
1267 end | 1475 end |
1476 | |
1477 def test_favicon_path | |
1478 assert_match %r{^/favicon\.ico}, favicon_path | |
1479 end | |
1480 | |
1481 def test_favicon_path_with_suburi | |
1482 Redmine::Utils.relative_url_root = '/foo' | |
1483 assert_match %r{^/foo/favicon\.ico}, favicon_path | |
1484 ensure | |
1485 Redmine::Utils.relative_url_root = '' | |
1486 end | |
1487 | |
1488 def test_favicon_url | |
1489 assert_match %r{^http://test\.host/favicon\.ico}, favicon_url | |
1490 end | |
1491 | |
1492 def test_favicon_url_with_suburi | |
1493 Redmine::Utils.relative_url_root = '/foo' | |
1494 assert_match %r{^http://test\.host/foo/favicon\.ico}, favicon_url | |
1495 ensure | |
1496 Redmine::Utils.relative_url_root = '' | |
1497 end | |
1498 | |
1499 def test_truncate_single_line | |
1500 str = "01234" | |
1501 result = truncate_single_line_raw("#{str}\n#{str}", 10) | |
1502 assert_equal "01234 0...", result | |
1503 assert !result.html_safe? | |
1504 result = truncate_single_line_raw("#{str}<&#>\n#{str}#{str}", 16) | |
1505 assert_equal "01234<&#> 012...", result | |
1506 assert !result.html_safe? | |
1507 end | |
1508 | |
1509 def test_truncate_single_line_non_ascii | |
1510 ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" | |
1511 ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding) | |
1512 result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10) | |
1513 assert_equal "#{ja} #{ja}...", result | |
1514 assert !result.html_safe? | |
1515 end | |
1268 end | 1516 end |