##// END OF EJS Templates
Adds a test for attached image inside a link (#4033)....
Jean-Philippe Lang -
r2848:9233a07a2355
parent child
Show More
@@ -1,471 +1,473
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 # two exclamation marks
60 # two exclamation marks
61 '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>',
61 '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>',
62 }
62 }
63 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
63 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
64 end
64 end
65
65
66 def test_auto_mailto
66 def test_auto_mailto
67 assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
67 assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
68 textilizable('test@foo.bar')
68 textilizable('test@foo.bar')
69 end
69 end
70
70
71 def test_inline_images
71 def test_inline_images
72 to_test = {
72 to_test = {
73 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
73 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
74 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
74 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
75 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
75 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
76 # inline styles should be stripped
76 # inline styles should be stripped
77 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
77 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
78 '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" />',
78 '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" />',
79 '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;" />',
79 '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;" />',
80 }
80 }
81 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
81 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
82 end
82 end
83
83
84 def test_acronyms
84 def test_acronyms
85 to_test = {
85 to_test = {
86 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
86 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>',
87 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
87 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted &quot;title&quot;">GPL</acronym>',
88 }
88 }
89 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
89 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
90
90
91 end
91 end
92
92
93 def test_attached_images
93 def test_attached_images
94 to_test = {
94 to_test = {
95 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
95 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
96 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
96 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
97 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
97 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
98 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />'
98 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
99 # link image
100 '!logo.gif!:http://foo.bar/' => '<a href="http://foo.bar/"><img src="/attachments/download/3" title="This is a logo" alt="This is a logo" /></a>',
99 }
101 }
100 attachments = Attachment.find(:all)
102 attachments = Attachment.find(:all)
101 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
103 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
102 end
104 end
103
105
104 def test_textile_external_links
106 def test_textile_external_links
105 to_test = {
107 to_test = {
106 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
108 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
107 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
109 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
108 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
110 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
109 '"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>',
111 '"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>',
110 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
112 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
111 # no multiline link text
113 # no multiline link text
112 "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",
114 "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",
113 # mailto link
115 # mailto link
114 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
116 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
115 # two exclamation marks
117 # two exclamation marks
116 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
118 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
117 }
119 }
118 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
120 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
119 end
121 end
120
122
121 def test_redmine_links
123 def test_redmine_links
122 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
124 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
123 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
125 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
124
126
125 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
127 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
126 :class => 'changeset', :title => 'My very first commit')
128 :class => 'changeset', :title => 'My very first commit')
127 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
129 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
128 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
130 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
129
131
130 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
132 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
131 :class => 'document')
133 :class => 'document')
132
134
133 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
135 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
134 :class => 'version')
136 :class => 'version')
135
137
136 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
138 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
137
139
138 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
140 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
139 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
141 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
140
142
141 to_test = {
143 to_test = {
142 # tickets
144 # tickets
143 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
145 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
144 # changesets
146 # changesets
145 'r1' => changeset_link,
147 'r1' => changeset_link,
146 'r1.' => "#{changeset_link}.",
148 'r1.' => "#{changeset_link}.",
147 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
149 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
148 'r1,r2' => "#{changeset_link},#{changeset_link2}",
150 'r1,r2' => "#{changeset_link},#{changeset_link2}",
149 # documents
151 # documents
150 'document#1' => document_link,
152 'document#1' => document_link,
151 'document:"Test document"' => document_link,
153 'document:"Test document"' => document_link,
152 # versions
154 # versions
153 'version#2' => version_link,
155 'version#2' => version_link,
154 'version:1.0' => version_link,
156 'version:1.0' => version_link,
155 'version:"1.0"' => version_link,
157 'version:"1.0"' => version_link,
156 # source
158 # source
157 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
159 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
158 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
160 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
159 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
161 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
160 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
162 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
161 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
163 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
162 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
164 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
163 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
165 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
164 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
166 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
165 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
167 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
166 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
168 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
167 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
169 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
168 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
170 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
169 # message
171 # message
170 'message#4' => link_to('Post 2', message_url, :class => 'message'),
172 'message#4' => link_to('Post 2', message_url, :class => 'message'),
171 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
173 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
172 # escaping
174 # escaping
173 '!#3.' => '#3.',
175 '!#3.' => '#3.',
174 '!r1' => 'r1',
176 '!r1' => 'r1',
175 '!document#1' => 'document#1',
177 '!document#1' => 'document#1',
176 '!document:"Test document"' => 'document:"Test document"',
178 '!document:"Test document"' => 'document:"Test document"',
177 '!version#2' => 'version#2',
179 '!version#2' => 'version#2',
178 '!version:1.0' => 'version:1.0',
180 '!version:1.0' => 'version:1.0',
179 '!version:"1.0"' => 'version:"1.0"',
181 '!version:"1.0"' => 'version:"1.0"',
180 '!source:/some/file' => 'source:/some/file',
182 '!source:/some/file' => 'source:/some/file',
181 # invalid expressions
183 # invalid expressions
182 'source:' => 'source:',
184 'source:' => 'source:',
183 # url hash
185 # url hash
184 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
186 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
185 }
187 }
186 @project = Project.find(1)
188 @project = Project.find(1)
187 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
189 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
188 end
190 end
189
191
190 def test_wiki_links
192 def test_wiki_links
191 to_test = {
193 to_test = {
192 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
194 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
193 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
195 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
194 # link with anchor
196 # link with anchor
195 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
197 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
196 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
198 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
197 # page that doesn't exist
199 # page that doesn't exist
198 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
200 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
199 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
201 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
200 # link to another project wiki
202 # link to another project wiki
201 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
203 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
202 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
204 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
203 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
205 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
204 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
206 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
205 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
207 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
206 # striked through link
208 # striked through link
207 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
209 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
208 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
210 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
209 # escaping
211 # escaping
210 '![[Another page|Page]]' => '[[Another page|Page]]',
212 '![[Another page|Page]]' => '[[Another page|Page]]',
211 # project does not exist
213 # project does not exist
212 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
214 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
213 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
215 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
214 }
216 }
215 @project = Project.find(1)
217 @project = Project.find(1)
216 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
218 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
217 end
219 end
218
220
219 def test_html_tags
221 def test_html_tags
220 to_test = {
222 to_test = {
221 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
223 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
222 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
224 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
223 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
225 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
224 # do not escape pre/code tags
226 # do not escape pre/code tags
225 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
227 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
226 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
228 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
227 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
229 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
228 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
230 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
229 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
231 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
230 # remove attributes except class
232 # remove attributes except class
231 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
233 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
232 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
234 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
233 }
235 }
234 to_test.each { |text, result| assert_equal result, textilizable(text) }
236 to_test.each { |text, result| assert_equal result, textilizable(text) }
235 end
237 end
236
238
237 def test_allowed_html_tags
239 def test_allowed_html_tags
238 to_test = {
240 to_test = {
239 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
241 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
240 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
242 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
241 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
243 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
242 }
244 }
243 to_test.each { |text, result| assert_equal result, textilizable(text) }
245 to_test.each { |text, result| assert_equal result, textilizable(text) }
244 end
246 end
245
247
246 def test_syntax_highlight
248 def test_syntax_highlight
247 raw = <<-RAW
249 raw = <<-RAW
248 <pre><code class="ruby">
250 <pre><code class="ruby">
249 # Some ruby code here
251 # Some ruby code here
250 </pre></code>
252 </pre></code>
251 RAW
253 RAW
252
254
253 expected = <<-EXPECTED
255 expected = <<-EXPECTED
254 <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span>
256 <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span>
255 </pre></code>
257 </pre></code>
256 EXPECTED
258 EXPECTED
257
259
258 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
260 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
259 end
261 end
260
262
261 def test_wiki_links_in_tables
263 def test_wiki_links_in_tables
262 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
264 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
263 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
265 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
264 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
266 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
265 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
267 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
266 }
268 }
267 @project = Project.find(1)
269 @project = Project.find(1)
268 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
270 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
269 end
271 end
270
272
271 def test_text_formatting
273 def test_text_formatting
272 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
274 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
273 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
275 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
274 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
276 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
275 '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>',
277 '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>',
276 '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',
278 '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',
277 }
279 }
278 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
280 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
279 end
281 end
280
282
281 def test_wiki_horizontal_rule
283 def test_wiki_horizontal_rule
282 assert_equal '<hr />', textilizable('---')
284 assert_equal '<hr />', textilizable('---')
283 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
285 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
284 end
286 end
285
287
286 def test_acronym
288 def test_acronym
287 assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
289 assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>',
288 textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
290 textilizable('This is an acronym: ACLU(American Civil Liberties Union).')
289 end
291 end
290
292
291 def test_footnotes
293 def test_footnotes
292 raw = <<-RAW
294 raw = <<-RAW
293 This is some text[1].
295 This is some text[1].
294
296
295 fn1. This is the foot note
297 fn1. This is the foot note
296 RAW
298 RAW
297
299
298 expected = <<-EXPECTED
300 expected = <<-EXPECTED
299 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
301 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
300 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
302 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
301 EXPECTED
303 EXPECTED
302
304
303 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
305 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
304 end
306 end
305
307
306 def test_table_of_content
308 def test_table_of_content
307 raw = <<-RAW
309 raw = <<-RAW
308 {{toc}}
310 {{toc}}
309
311
310 h1. Title
312 h1. Title
311
313
312 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
314 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
313
315
314 h2. Subtitle with a [[Wiki]] link
316 h2. Subtitle with a [[Wiki]] link
315
317
316 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
318 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
317
319
318 h2. Subtitle with [[Wiki|another Wiki]] link
320 h2. Subtitle with [[Wiki|another Wiki]] link
319
321
320 h2. Subtitle with %{color:red}red text%
322 h2. Subtitle with %{color:red}red text%
321
323
322 h1. Another title
324 h1. Another title
323
325
324 RAW
326 RAW
325
327
326 expected = '<ul class="toc">' +
328 expected = '<ul class="toc">' +
327 '<li class="heading1"><a href="#Title">Title</a></li>' +
329 '<li class="heading1"><a href="#Title">Title</a></li>' +
328 '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
330 '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
329 '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
331 '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
330 '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
332 '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' +
331 '<li class="heading1"><a href="#Another-title">Another title</a></li>' +
333 '<li class="heading1"><a href="#Another-title">Another title</a></li>' +
332 '</ul>'
334 '</ul>'
333
335
334 assert textilizable(raw).gsub("\n", "").include?(expected)
336 assert textilizable(raw).gsub("\n", "").include?(expected)
335 end
337 end
336
338
337 def test_blockquote
339 def test_blockquote
338 # orig raw text
340 # orig raw text
339 raw = <<-RAW
341 raw = <<-RAW
340 John said:
342 John said:
341 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
343 > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
342 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
344 > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
343 > * Donec odio lorem,
345 > * Donec odio lorem,
344 > * sagittis ac,
346 > * sagittis ac,
345 > * malesuada in,
347 > * malesuada in,
346 > * adipiscing eu, dolor.
348 > * adipiscing eu, dolor.
347 >
349 >
348 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
350 > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.
349 > Proin a tellus. Nam vel neque.
351 > Proin a tellus. Nam vel neque.
350
352
351 He's right.
353 He's right.
352 RAW
354 RAW
353
355
354 # expected html
356 # expected html
355 expected = <<-EXPECTED
357 expected = <<-EXPECTED
356 <p>John said:</p>
358 <p>John said:</p>
357 <blockquote>
359 <blockquote>
358 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
360 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
359 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
361 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
360 <ul>
362 <ul>
361 <li>Donec odio lorem,</li>
363 <li>Donec odio lorem,</li>
362 <li>sagittis ac,</li>
364 <li>sagittis ac,</li>
363 <li>malesuada in,</li>
365 <li>malesuada in,</li>
364 <li>adipiscing eu, dolor.</li>
366 <li>adipiscing eu, dolor.</li>
365 </ul>
367 </ul>
366 <blockquote>
368 <blockquote>
367 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
369 <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p>
368 </blockquote>
370 </blockquote>
369 <p>Proin a tellus. Nam vel neque.</p>
371 <p>Proin a tellus. Nam vel neque.</p>
370 </blockquote>
372 </blockquote>
371 <p>He's right.</p>
373 <p>He's right.</p>
372 EXPECTED
374 EXPECTED
373
375
374 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
376 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
375 end
377 end
376
378
377 def test_table
379 def test_table
378 raw = <<-RAW
380 raw = <<-RAW
379 This is a table with empty cells:
381 This is a table with empty cells:
380
382
381 |cell11|cell12||
383 |cell11|cell12||
382 |cell21||cell23|
384 |cell21||cell23|
383 |cell31|cell32|cell33|
385 |cell31|cell32|cell33|
384 RAW
386 RAW
385
387
386 expected = <<-EXPECTED
388 expected = <<-EXPECTED
387 <p>This is a table with empty cells:</p>
389 <p>This is a table with empty cells:</p>
388
390
389 <table>
391 <table>
390 <tr><td>cell11</td><td>cell12</td><td></td></tr>
392 <tr><td>cell11</td><td>cell12</td><td></td></tr>
391 <tr><td>cell21</td><td></td><td>cell23</td></tr>
393 <tr><td>cell21</td><td></td><td>cell23</td></tr>
392 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
394 <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr>
393 </table>
395 </table>
394 EXPECTED
396 EXPECTED
395
397
396 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
398 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
397 end
399 end
398
400
399 def test_table_with_line_breaks
401 def test_table_with_line_breaks
400 raw = <<-RAW
402 raw = <<-RAW
401 This is a table with line breaks:
403 This is a table with line breaks:
402
404
403 |cell11
405 |cell11
404 continued|cell12||
406 continued|cell12||
405 |-cell21-||cell23
407 |-cell21-||cell23
406 cell23 line2
408 cell23 line2
407 cell23 *line3*|
409 cell23 *line3*|
408 |cell31|cell32
410 |cell31|cell32
409 cell32 line2|cell33|
411 cell32 line2|cell33|
410
412
411 RAW
413 RAW
412
414
413 expected = <<-EXPECTED
415 expected = <<-EXPECTED
414 <p>This is a table with line breaks:</p>
416 <p>This is a table with line breaks:</p>
415
417
416 <table>
418 <table>
417 <tr>
419 <tr>
418 <td>cell11<br />continued</td>
420 <td>cell11<br />continued</td>
419 <td>cell12</td>
421 <td>cell12</td>
420 <td></td>
422 <td></td>
421 </tr>
423 </tr>
422 <tr>
424 <tr>
423 <td><del>cell21</del></td>
425 <td><del>cell21</del></td>
424 <td></td>
426 <td></td>
425 <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
427 <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td>
426 </tr>
428 </tr>
427 <tr>
429 <tr>
428 <td>cell31</td>
430 <td>cell31</td>
429 <td>cell32<br/>cell32 line2</td>
431 <td>cell32<br/>cell32 line2</td>
430 <td>cell33</td>
432 <td>cell33</td>
431 </tr>
433 </tr>
432 </table>
434 </table>
433 EXPECTED
435 EXPECTED
434
436
435 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
437 assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '')
436 end
438 end
437
439
438 def test_default_formatter
440 def test_default_formatter
439 Setting.text_formatting = 'unknown'
441 Setting.text_formatting = 'unknown'
440 text = 'a *link*: http://www.example.net/'
442 text = 'a *link*: http://www.example.net/'
441 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
443 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
442 Setting.text_formatting = 'textile'
444 Setting.text_formatting = 'textile'
443 end
445 end
444
446
445 def test_due_date_distance_in_words
447 def test_due_date_distance_in_words
446 to_test = { Date.today => 'Due in 0 days',
448 to_test = { Date.today => 'Due in 0 days',
447 Date.today + 1 => 'Due in 1 day',
449 Date.today + 1 => 'Due in 1 day',
448 Date.today + 100 => 'Due in about 3 months',
450 Date.today + 100 => 'Due in about 3 months',
449 Date.today + 20000 => 'Due in over 55 years',
451 Date.today + 20000 => 'Due in over 55 years',
450 Date.today - 1 => '1 day late',
452 Date.today - 1 => '1 day late',
451 Date.today - 100 => 'about 3 months late',
453 Date.today - 100 => 'about 3 months late',
452 Date.today - 20000 => 'over 55 years late',
454 Date.today - 20000 => 'over 55 years late',
453 }
455 }
454 to_test.each do |date, expected|
456 to_test.each do |date, expected|
455 assert_equal expected, due_date_distance_in_words(date)
457 assert_equal expected, due_date_distance_in_words(date)
456 end
458 end
457 end
459 end
458
460
459 def test_avatar
461 def test_avatar
460 # turn on avatars
462 # turn on avatars
461 Setting.gravatar_enabled = '1'
463 Setting.gravatar_enabled = '1'
462 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
464 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
463 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
465 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
464 assert_nil avatar('jsmith')
466 assert_nil avatar('jsmith')
465 assert_nil avatar(nil)
467 assert_nil avatar(nil)
466
468
467 # turn off avatars
469 # turn off avatars
468 Setting.gravatar_enabled = '0'
470 Setting.gravatar_enabled = '0'
469 assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
471 assert_nil avatar(User.find_by_mail('jsmith@somenet.foo'))
470 end
472 end
471 end
473 end
General Comments 0
You need to be logged in to leave comments. Login now