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