##// END OF EJS Templates
Add test for r2664 (#3127)....
Jean-Philippe Lang -
r2573:a6acc7790406
parent child
Show More
@@ -1,421 +1,423
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
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.dirname(__FILE__) + '/../../test_helper'
19
19
20 class ApplicationHelperTest < HelperTestCase
20 class ApplicationHelperTest < HelperTestCase
21 include ApplicationHelper
21 include ApplicationHelper
22 include ActionView::Helpers::TextHelper
22 include ActionView::Helpers::TextHelper
23 include ActionView::Helpers::DateHelper
23 include ActionView::Helpers::DateHelper
24
24
25 fixtures :projects, :roles, :enabled_modules, :users,
25 fixtures :projects, :roles, :enabled_modules, :users,
26 :repositories, :changesets,
26 :repositories, :changesets,
27 :trackers, :issue_statuses, :issues, :versions, :documents,
27 :trackers, :issue_statuses, :issues, :versions, :documents,
28 :wikis, :wiki_pages, :wiki_contents,
28 :wikis, :wiki_pages, :wiki_contents,
29 :boards, :messages,
29 :boards, :messages,
30 :attachments
30 :attachments
31
31
32 def setup
32 def setup
33 super
33 super
34 end
34 end
35
35
36 def test_auto_links
36 def test_auto_links
37 to_test = {
37 to_test = {
38 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
38 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
39 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
39 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
40 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
40 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
41 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
41 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
42 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
42 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
43 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
43 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
44 '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>.',
44 '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>.',
45 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
45 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
46 '(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>)',
46 '(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>)',
47 '(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>)',
47 '(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>)',
48 '(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>).',
48 '(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>).',
49 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
49 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
50 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
50 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
51 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
51 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
52 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
52 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
53 '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>',
53 '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>',
54 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
54 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
55 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
55 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
56 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
56 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
57 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
57 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
58 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
58 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
59 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
59 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
60 }
60 }
61 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
61 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
62 end
62 end
63
63
64 def test_auto_mailto
64 def test_auto_mailto
65 assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
65 assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
66 textilizable('test@foo.bar')
66 textilizable('test@foo.bar')
67 end
67 end
68
68
69 def test_inline_images
69 def test_inline_images
70 to_test = {
70 to_test = {
71 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
71 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
72 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
72 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
73 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
73 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
74 # inline styles should be stripped
74 # inline styles should be stripped
75 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
75 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
76 '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" />',
76 '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" />',
77 '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;" />',
77 '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;" />',
78 }
78 }
79 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
79 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
80 end
80 end
81
81
82 def test_acronyms
82 def test_acronyms
83 to_test = {
83 to_test = {
84 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
84 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
85 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
85 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
86 }
86 }
87 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
87 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
88
88
89 end
89 end
90
90
91 def test_attached_images
91 def test_attached_images
92 to_test = {
92 to_test = {
93 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
93 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
94 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
94 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
95 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
95 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
96 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />'
96 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />'
97 }
97 }
98 attachments = Attachment.find(:all)
98 attachments = Attachment.find(:all)
99 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
99 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
100 end
100 end
101
101
102 def test_textile_external_links
102 def test_textile_external_links
103 to_test = {
103 to_test = {
104 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
104 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
105 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
105 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
106 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
106 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
107 '"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>',
107 '"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>',
108 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
108 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
109 # no multiline link text
109 # no multiline link text
110 "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 />\nand another on a second line\":test"
110 "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 />\nand another on a second line\":test",
111 # mailto link
112 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
111 }
113 }
112 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
114 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
113 end
115 end
114
116
115 def test_redmine_links
117 def test_redmine_links
116 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
118 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
117 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
119 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
118
120
119 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
121 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
120 :class => 'changeset', :title => 'My very first commit')
122 :class => 'changeset', :title => 'My very first commit')
121
123
122 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
124 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
123 :class => 'document')
125 :class => 'document')
124
126
125 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
127 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
126 :class => 'version')
128 :class => 'version')
127
129
128 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
130 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
129
131
130 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
132 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
131 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
133 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
132
134
133 to_test = {
135 to_test = {
134 # tickets
136 # tickets
135 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
137 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
136 # changesets
138 # changesets
137 'r1' => changeset_link,
139 'r1' => changeset_link,
138 # documents
140 # documents
139 'document#1' => document_link,
141 'document#1' => document_link,
140 'document:"Test document"' => document_link,
142 'document:"Test document"' => document_link,
141 # versions
143 # versions
142 'version#2' => version_link,
144 'version#2' => version_link,
143 'version:1.0' => version_link,
145 'version:1.0' => version_link,
144 'version:"1.0"' => version_link,
146 'version:"1.0"' => version_link,
145 # source
147 # source
146 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
148 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
147 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
149 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
148 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
150 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
149 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
151 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
150 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
152 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
151 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
153 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
152 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
154 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
153 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
155 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
154 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
156 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
155 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
157 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
156 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
158 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
157 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
159 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
158 # message
160 # message
159 'message#4' => link_to('Post 2', message_url, :class => 'message'),
161 'message#4' => link_to('Post 2', message_url, :class => 'message'),
160 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
162 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
161 # escaping
163 # escaping
162 '!#3.' => '#3.',
164 '!#3.' => '#3.',
163 '!r1' => 'r1',
165 '!r1' => 'r1',
164 '!document#1' => 'document#1',
166 '!document#1' => 'document#1',
165 '!document:"Test document"' => 'document:"Test document"',
167 '!document:"Test document"' => 'document:"Test document"',
166 '!version#2' => 'version#2',
168 '!version#2' => 'version#2',
167 '!version:1.0' => 'version:1.0',
169 '!version:1.0' => 'version:1.0',
168 '!version:"1.0"' => 'version:"1.0"',
170 '!version:"1.0"' => 'version:"1.0"',
169 '!source:/some/file' => 'source:/some/file',
171 '!source:/some/file' => 'source:/some/file',
170 # invalid expressions
172 # invalid expressions
171 'source:' => 'source:',
173 'source:' => 'source:',
172 # url hash
174 # url hash
173 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
175 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
174 }
176 }
175 @project = Project.find(1)
177 @project = Project.find(1)
176 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
178 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
177 end
179 end
178
180
179 def test_wiki_links
181 def test_wiki_links
180 to_test = {
182 to_test = {
181 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
183 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
182 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
184 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
183 # link with anchor
185 # link with anchor
184 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
186 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
185 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
187 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
186 # page that doesn't exist
188 # page that doesn't exist
187 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
189 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
188 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
190 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
189 # link to another project wiki
191 # link to another project wiki
190 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
192 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
191 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
193 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
192 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
194 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
193 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
195 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
194 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
196 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
195 # striked through link
197 # striked through link
196 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
198 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
197 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
199 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
198 # escaping
200 # escaping
199 '![[Another page|Page]]' => '[[Another page|Page]]',
201 '![[Another page|Page]]' => '[[Another page|Page]]',
200 # project does not exist
202 # project does not exist
201 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
203 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
202 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
204 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
203 }
205 }
204 @project = Project.find(1)
206 @project = Project.find(1)
205 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
207 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
206 end
208 end
207
209
208 def test_html_tags
210 def test_html_tags
209 to_test = {
211 to_test = {
210 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
212 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
211 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
213 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
212 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
214 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
213 # do not escape pre/code tags
215 # do not escape pre/code tags
214 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
216 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
215 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
217 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
216 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
218 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
217 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
219 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
218 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
220 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
219 # remove attributes except class
221 # remove attributes except class
220 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
222 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
221 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
223 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
222 }
224 }
223 to_test.each { |text, result| assert_equal result, textilizable(text) }
225 to_test.each { |text, result| assert_equal result, textilizable(text) }
224 end
226 end
225
227
226 def test_allowed_html_tags
228 def test_allowed_html_tags
227 to_test = {
229 to_test = {
228 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
230 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
229 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
231 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
230 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
232 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
231 }
233 }
232 to_test.each { |text, result| assert_equal result, textilizable(text) }
234 to_test.each { |text, result| assert_equal result, textilizable(text) }
233 end
235 end
234
236
235 def syntax_highlight
237 def syntax_highlight
236 raw = <<-RAW
238 raw = <<-RAW
237 <pre><code class="ruby">
239 <pre><code class="ruby">
238 # Some ruby code here
240 # Some ruby code here
239 </pre></code>
241 </pre></code>
240 RAW
242 RAW
241
243
242 expected = <<-EXPECTED
244 expected = <<-EXPECTED
243 <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span>
245 <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span>
244 </pre></code>
246 </pre></code>
245 EXPECTED
247 EXPECTED
246
248
247 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
249 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
248 end
250 end
249
251
250 def test_wiki_links_in_tables
252 def test_wiki_links_in_tables
251 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
253 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
252 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
254 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
253 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
255 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
254 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
256 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
255 }
257 }
256 @project = Project.find(1)
258 @project = Project.find(1)
257 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
259 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
258 end
260 end
259
261
260 def test_text_formatting
262 def test_text_formatting
261 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
263 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
262 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
264 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
263 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
265 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
264 '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>',
266 '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>',
265 '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',
267 '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',
266 }
268 }
267 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
269 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
268 end
270 end
269
271
270 def test_wiki_horizontal_rule
272 def test_wiki_horizontal_rule
271 assert_equal '<hr />', textilizable('---')
273 assert_equal '<hr />', textilizable('---')
272 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
274 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
273 end
275 end
274
276
275 def test_acronym
277 def test_acronym
276 assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
278 assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
277 textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
279 textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
278 end
280 end
279
281
280 def test_footnotes
282 def test_footnotes
281 raw = <<-RAW
283 raw = <<-RAW
282 This is some text[1].
284 This is some text[1].
283
285
284 fn1. This is the foot note
286 fn1. This is the foot note
285 RAW
287 RAW
286
288
287 expected = <<-EXPECTED
289 expected = <<-EXPECTED
288 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
290 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
289 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
291 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
290 EXPECTED
292 EXPECTED
291
293
292 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
294 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
293 end
295 end
294
296
295 def test_table_of_content
297 def test_table_of_content
296 raw = <<-RAW
298 raw = <<-RAW
297 {{toc}}
299 {{toc}}
298
300
299 h1. Title
301 h1. Title
300
302
301 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
303 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
302
304
303 h2. Subtitle with a [[Wiki]] link
305 h2. Subtitle with a [[Wiki]] link
304
306
305 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
307 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
306
308
307 h2. Subtitle with [[Wiki|another Wiki]] link
309 h2. Subtitle with [[Wiki|another Wiki]] link
308
310
309 h2. Subtitle with %{color:red}red text%
311 h2. Subtitle with %{color:red}red text%
310
312
311 h1. Another title
313 h1. Another title
312
314
313 RAW
315 RAW
314
316
315 expected = '<ul class="toc">' +
317 expected = '<ul class="toc">' +
316 '<li class="heading1"><a href="#Title">Title</a></li>' +
318 '<li class="heading1"><a href="#Title">Title</a></li>' +
317 '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
319 '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
318 '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
320 '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
319 '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
321 '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
320 '<li class="heading1"><a href="#Another-title">Another title</a></li>' +
322 '<li class="heading1"><a href="#Another-title">Another title</a></li>' +
321 '</ul>'
323 '</ul>'
322
324
323 assert textilizable(raw).gsub("\n", "").include?(expected)
325 assert textilizable(raw).gsub("\n", "").include?(expected)
324 end
326 end
325
327
326 def test_blockquote
328 def test_blockquote
327 # orig raw text
329 # orig raw text
328 raw = <<-RAW
330 raw = <<-RAW
329 John said:
331 John said:
330 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
332 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
331 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
333 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
332 > * Donec odio lorem,
334 > * Donec odio lorem,
333 > * sagittis ac,
335 > * sagittis ac,
334 > * malesuada in,
336 > * malesuada in,
335 > * adipiscing eu, dolor.
337 > * adipiscing eu, dolor.
336 >
338 >
337 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
339 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
338 > Proin a tellus. Nam vel neque.
340 > Proin a tellus. Nam vel neque.
339
341
340 He's right.
342 He's right.
341 RAW
343 RAW
342
344
343 # expected html
345 # expected html
344 expected = <<-EXPECTED
346 expected = <<-EXPECTED
345 <p>John said:</p>
347 <p>John said:</p>
346 <blockquote>
348 <blockquote>
347 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
349 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
348 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
350 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
349 <ul>
351 <ul>
350 <li>Donec odio lorem,</li>
352 <li>Donec odio lorem,</li>
351 <li>sagittis ac,</li>
353 <li>sagittis ac,</li>
352 <li>malesuada in,</li>
354 <li>malesuada in,</li>
353 <li>adipiscing eu, dolor.</li>
355 <li>adipiscing eu, dolor.</li>
354 </ul>
356 </ul>
355 <blockquote>
357 <blockquote>
356 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
358 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
357 </blockquote>
359 </blockquote>
358 <p>Proin a tellus. Nam vel neque.</p>
360 <p>Proin a tellus. Nam vel neque.</p>
359 </blockquote>
361 </blockquote>
360 <p>He's right.</p>
362 <p>He's right.</p>
361 EXPECTED
363 EXPECTED
362
364
363 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
365 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
364 end
366 end
365
367
366 def test_table
368 def test_table
367 raw = <<-RAW
369 raw = <<-RAW
368 This is a table with empty cells:
370 This is a table with empty cells:
369
371
370 |cell11|cell12||
372 |cell11|cell12||
371 |cell21||cell23|
373 |cell21||cell23|
372 |cell31|cell32|cell33|
374 |cell31|cell32|cell33|
373 RAW
375 RAW
374
376
375 expected = <<-EXPECTED
377 expected = <<-EXPECTED
376 <p>This is a table with empty cells:</p>
378 <p>This is a table with empty cells:</p>
377
379
378 <table>
380 <table>
379 <tr><td>cell11</td><td>cell12</td><td></td></tr>
381 <tr><td>cell11</td><td>cell12</td><td></td></tr>
380 <tr><td>cell21</td><td></td><td>cell23</td></tr>
382 <tr><td>cell21</td><td></td><td>cell23</td></tr>
381 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
383 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
382 </table>
384 </table>
383 EXPECTED
385 EXPECTED
384
386
385 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
387 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
386 end
388 end
387
389
388 def test_default_formatter
390 def test_default_formatter
389 Setting.text_formatting = 'unknown'
391 Setting.text_formatting = 'unknown'
390 text = 'a *link*: http://www.example.net/'
392 text = 'a *link*: http://www.example.net/'
391 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
393 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
392 Setting.text_formatting = 'textile'
394 Setting.text_formatting = 'textile'
393 end
395 end
394
396
395 def test_due_date_distance_in_words
397 def test_due_date_distance_in_words
396 to_test = { Date.today => 'Due in 0 days',
398 to_test = { Date.today => 'Due in 0 days',
397 Date.today + 1 => 'Due in 1 day',
399 Date.today + 1 => 'Due in 1 day',
398 Date.today + 100 => 'Due in about 3 months',
400 Date.today + 100 => 'Due in about 3 months',
399 Date.today + 20000 => 'Due in over 55 years',
401 Date.today + 20000 => 'Due in over 55 years',
400 Date.today - 1 => '1 day late',
402 Date.today - 1 => '1 day late',
401 Date.today - 100 => 'about 3 months late',
403 Date.today - 100 => 'about 3 months late',
402 Date.today - 20000 => 'over 55 years late',
404 Date.today - 20000 => 'over 55 years late',
403 }
405 }
404 to_test.each do |date, expected|
406 to_test.each do |date, expected|
405 assert_equal expected, due_date_distance_in_words(date)
407 assert_equal expected, due_date_distance_in_words(date)
406 end
408 end
407 end
409 end
408
410
409 def test_avatar
411 def test_avatar
410 # turn on avatars
412 # turn on avatars
411 Setting.gravatar_enabled = '1'
413 Setting.gravatar_enabled = '1'
412 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
414 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
413 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
415 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
414 assert_nil avatar('jsmith')
416 assert_nil avatar('jsmith')
415 assert_nil avatar(nil)
417 assert_nil avatar(nil)
416
418
417 # turn off avatars
419 # turn off avatars
418 Setting.gravatar_enabled = '0'
420 Setting.gravatar_enabled = '0'
419 assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
421 assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
420 end
422 end
421 end
423 end
General Comments 0
You need to be logged in to leave comments. Login now