@@ -1,342 +1,342 | |||||
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, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules |
|
23 | fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules | |
24 |
|
24 | |||
25 | def setup |
|
25 | def setup | |
26 | super |
|
26 | super | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def test_auto_links |
|
29 | def test_auto_links | |
30 | to_test = { |
|
30 | to_test = { | |
31 | 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', |
|
31 | 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', | |
32 | 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>', |
|
32 | 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>', | |
33 | 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
33 | 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.', | |
34 | 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
34 | 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.', | |
35 | 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).', |
|
35 | 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).', | |
36 | '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>.', |
|
36 | '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>.', | |
37 | 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>', |
|
37 | 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>', | |
38 | '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>', |
|
38 | '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>', | |
39 | 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>', |
|
39 | 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>', | |
40 | 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>', |
|
40 | 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>', | |
41 | 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>', |
|
41 | 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>', | |
42 | } |
|
42 | } | |
43 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
43 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_auto_mailto |
|
46 | def test_auto_mailto | |
47 | assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>', |
|
47 | assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>', | |
48 | textilizable('test@foo.bar') |
|
48 | textilizable('test@foo.bar') | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def test_inline_images |
|
51 | def test_inline_images | |
52 | to_test = { |
|
52 | to_test = { | |
53 | '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', |
|
53 | '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', | |
54 | 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', |
|
54 | 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', | |
55 | 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />', |
|
55 | 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />', | |
56 | 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />', |
|
56 | 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />', | |
57 | } |
|
57 | } | |
58 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
58 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_textile_external_links |
|
61 | def test_textile_external_links | |
62 | to_test = { |
|
62 | to_test = { | |
63 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
63 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', | |
64 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', |
|
64 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', | |
65 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>', |
|
65 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>', | |
66 | "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph", |
|
66 | "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph", | |
67 | # no multiline link text |
|
67 | # no multiline link text | |
68 | "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" |
|
68 | "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" | |
69 | } |
|
69 | } | |
70 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
70 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_redmine_links |
|
73 | def test_redmine_links | |
74 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
|
74 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, | |
75 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') |
|
75 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') | |
76 |
|
76 | |||
77 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, |
|
77 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, | |
78 | :class => 'changeset', :title => 'My very first commit') |
|
78 | :class => 'changeset', :title => 'My very first commit') | |
79 |
|
79 | |||
80 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, |
|
80 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, | |
81 | :class => 'document') |
|
81 | :class => 'document') | |
82 |
|
82 | |||
83 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, |
|
83 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, | |
84 | :class => 'version') |
|
84 | :class => 'version') | |
85 |
|
85 | |||
86 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} |
|
86 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} | |
87 | source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} |
|
87 | source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} | |
88 |
|
88 | |||
89 | to_test = { |
|
89 | to_test = { | |
90 | # tickets |
|
90 | # tickets | |
91 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", |
|
91 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", | |
92 | # changesets |
|
92 | # changesets | |
93 | 'r1' => changeset_link, |
|
93 | 'r1' => changeset_link, | |
94 | # documents |
|
94 | # documents | |
95 | 'document#1' => document_link, |
|
95 | 'document#1' => document_link, | |
96 | 'document:"Test document"' => document_link, |
|
96 | 'document:"Test document"' => document_link, | |
97 | # versions |
|
97 | # versions | |
98 | 'version#2' => version_link, |
|
98 | 'version#2' => version_link, | |
99 | 'version:1.0' => version_link, |
|
99 | 'version:1.0' => version_link, | |
100 | 'version:"1.0"' => version_link, |
|
100 | 'version:"1.0"' => version_link, | |
101 | # source |
|
101 | # source | |
102 | 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), |
|
102 | 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), | |
103 | 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
103 | 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", | |
104 | 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
104 | 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", | |
105 | 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
105 | 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", | |
106 | 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
106 | 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", | |
107 | 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", |
|
107 | 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", | |
108 | 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), |
|
108 | 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), | |
109 | 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), |
|
109 | 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), | |
110 | 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), |
|
110 | 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), | |
111 | 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), |
|
111 | 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), | |
112 | 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), |
|
112 | 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), | |
113 | 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), |
|
113 | 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), | |
114 | # escaping |
|
114 | # escaping | |
115 | '!#3.' => '#3.', |
|
115 | '!#3.' => '#3.', | |
116 | '!r1' => 'r1', |
|
116 | '!r1' => 'r1', | |
117 | '!document#1' => 'document#1', |
|
117 | '!document#1' => 'document#1', | |
118 | '!document:"Test document"' => 'document:"Test document"', |
|
118 | '!document:"Test document"' => 'document:"Test document"', | |
119 | '!version#2' => 'version#2', |
|
119 | '!version#2' => 'version#2', | |
120 | '!version:1.0' => 'version:1.0', |
|
120 | '!version:1.0' => 'version:1.0', | |
121 | '!version:"1.0"' => 'version:"1.0"', |
|
121 | '!version:"1.0"' => 'version:"1.0"', | |
122 | '!source:/some/file' => 'source:/some/file', |
|
122 | '!source:/some/file' => 'source:/some/file', | |
123 | # invalid expressions |
|
123 | # invalid expressions | |
124 | 'source:' => 'source:', |
|
124 | 'source:' => 'source:', | |
125 | # url hash |
|
125 | # url hash | |
126 | "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', |
|
126 | "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', | |
127 | } |
|
127 | } | |
128 | @project = Project.find(1) |
|
128 | @project = Project.find(1) | |
129 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
129 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def test_wiki_links |
|
132 | def test_wiki_links | |
133 | to_test = { |
|
133 | to_test = { | |
134 | '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
|
134 | '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>', | |
135 | '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>', |
|
135 | '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>', | |
136 | # page that doesn't exist |
|
136 | # page that doesn't exist | |
137 | '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
137 | '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>', | |
138 | '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>', |
|
138 | '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>', | |
139 | # link to another project wiki |
|
139 | # link to another project wiki | |
140 | '[[onlinestore:]]' => '<a href="/wiki/onlinestore/" class="wiki-page">onlinestore</a>', |
|
140 | '[[onlinestore:]]' => '<a href="/wiki/onlinestore/" class="wiki-page">onlinestore</a>', | |
141 | '[[onlinestore:|Wiki]]' => '<a href="/wiki/onlinestore/" class="wiki-page">Wiki</a>', |
|
141 | '[[onlinestore:|Wiki]]' => '<a href="/wiki/onlinestore/" class="wiki-page">Wiki</a>', | |
142 | '[[onlinestore:Start page]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Start page</a>', |
|
142 | '[[onlinestore:Start page]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Start page</a>', | |
143 | '[[onlinestore:Start page|Text]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Text</a>', |
|
143 | '[[onlinestore:Start page|Text]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Text</a>', | |
144 | '[[onlinestore:Unknown page]]' => '<a href="/wiki/onlinestore/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
144 | '[[onlinestore:Unknown page]]' => '<a href="/wiki/onlinestore/Unknown_page" class="wiki-page new">Unknown page</a>', | |
145 | # striked through link |
|
145 | # striked through link | |
146 | '-[[Another page|Page]]-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a></del>', |
|
146 | '-[[Another page|Page]]-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a></del>', | |
147 | # escaping |
|
147 | # escaping | |
148 | '![[Another page|Page]]' => '[[Another page|Page]]', |
|
148 | '![[Another page|Page]]' => '[[Another page|Page]]', | |
149 | } |
|
149 | } | |
150 | @project = Project.find(1) |
|
150 | @project = Project.find(1) | |
151 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
151 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_html_tags |
|
154 | def test_html_tags | |
155 | to_test = { |
|
155 | to_test = { | |
156 | "<div>content</div>" => "<p><div>content</div></p>", |
|
156 | "<div>content</div>" => "<p><div>content</div></p>", | |
157 | "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>", |
|
157 | "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>", | |
158 | "<script>some script;</script>" => "<p><script>some script;</script></p>", |
|
158 | "<script>some script;</script>" => "<p><script>some script;</script></p>", | |
159 | # do not escape pre/code tags |
|
159 | # do not escape pre/code tags | |
160 | "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>", |
|
160 | "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>", | |
161 | "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>", |
|
161 | "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>", | |
162 | "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", |
|
162 | "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", | |
163 | "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", |
|
163 | "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", | |
164 | "<!-- opening comment" => "<p><!-- opening comment</p>" |
|
164 | "<!-- opening comment" => "<p><!-- opening comment</p>" | |
165 | } |
|
165 | } | |
166 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
166 | to_test.each { |text, result| assert_equal result, textilizable(text) } | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def test_allowed_html_tags |
|
169 | def test_allowed_html_tags | |
170 | to_test = { |
|
170 | to_test = { | |
171 | "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", |
|
171 | "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", | |
172 | "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting", |
|
172 | "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting", | |
173 | } |
|
173 | } | |
174 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
174 | to_test.each { |text, result| assert_equal result, textilizable(text) } | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def test_wiki_links_in_tables |
|
177 | def test_wiki_links_in_tables | |
178 | to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => |
|
178 | to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => | |
179 | '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' + |
|
179 | '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' + | |
180 | '<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' + |
|
180 | '<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' + | |
181 | '</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>' |
|
181 | '</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>' | |
182 | } |
|
182 | } | |
183 | @project = Project.find(1) |
|
183 | @project = Project.find(1) | |
184 | to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } |
|
184 | to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def test_text_formatting |
|
187 | def test_text_formatting | |
188 | to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', |
|
188 | to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', | |
189 | '(_text within parentheses_)' => '(<em>text within parentheses</em>)' |
|
189 | '(_text within parentheses_)' => '(<em>text within parentheses</em>)' | |
190 | } |
|
190 | } | |
191 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
191 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
194 | def test_wiki_horizontal_rule |
|
194 | def test_wiki_horizontal_rule | |
195 | assert_equal '<hr />', textilizable('---') |
|
195 | assert_equal '<hr />', textilizable('---') | |
196 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') |
|
196 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | def test_table_of_content |
|
199 | def test_table_of_content | |
200 | raw = <<-RAW |
|
200 | raw = <<-RAW | |
201 | {{toc}} |
|
201 | {{toc}} | |
202 |
|
202 | |||
203 | h1. Title |
|
203 | h1. Title | |
204 |
|
204 | |||
205 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
205 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
206 |
|
206 | |||
207 | h2. Subtitle |
|
207 | h2. Subtitle | |
208 |
|
208 | |||
209 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
209 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
210 |
|
210 | |||
211 | h2. Subtitle with %{color:red}red text% |
|
211 | h2. Subtitle with %{color:red}red text% | |
212 |
|
212 | |||
213 | h1. Another title |
|
213 | h1. Another title | |
214 |
|
214 | |||
215 | RAW |
|
215 | RAW | |
216 |
|
216 | |||
217 |
expected = '< |
|
217 | expected = '<ul class="toc">' + | |
218 |
'< |
|
218 | '<li class="heading1"><a href="#1">Title</a></li>' + | |
219 |
'< |
|
219 | '<li class="heading2"><a href="#2">Subtitle</a></li>' + | |
220 |
'< |
|
220 | '<li class="heading2"><a href="#3">Subtitle with red text</a></li>' + | |
221 |
'< |
|
221 | '<li class="heading1"><a href="#4">Another title</a></li>' + | |
222 |
'</ |
|
222 | '</ul>' | |
223 |
|
223 | |||
224 | assert textilizable(raw).include?(expected) |
|
224 | assert textilizable(raw).gsub("\n", "").include?(expected) | |
225 | end |
|
225 | end | |
226 |
|
226 | |||
227 | def test_blockquote |
|
227 | def test_blockquote | |
228 | # orig raw text |
|
228 | # orig raw text | |
229 | raw = <<-RAW |
|
229 | raw = <<-RAW | |
230 | John said: |
|
230 | John said: | |
231 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
231 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
232 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
232 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
233 | > * Donec odio lorem, |
|
233 | > * Donec odio lorem, | |
234 | > * sagittis ac, |
|
234 | > * sagittis ac, | |
235 | > * malesuada in, |
|
235 | > * malesuada in, | |
236 | > * adipiscing eu, dolor. |
|
236 | > * adipiscing eu, dolor. | |
237 | > |
|
237 | > | |
238 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. |
|
238 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. | |
239 | > Proin a tellus. Nam vel neque. |
|
239 | > Proin a tellus. Nam vel neque. | |
240 |
|
240 | |||
241 | He's right. |
|
241 | He's right. | |
242 | RAW |
|
242 | RAW | |
243 |
|
243 | |||
244 | # expected html |
|
244 | # expected html | |
245 | expected = <<-EXPECTED |
|
245 | expected = <<-EXPECTED | |
246 | <p>John said:</p> |
|
246 | <p>John said:</p> | |
247 | <blockquote> |
|
247 | <blockquote> | |
248 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
248 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
249 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
249 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
250 | <ul> |
|
250 | <ul> | |
251 | <li>Donec odio lorem,</li> |
|
251 | <li>Donec odio lorem,</li> | |
252 | <li>sagittis ac,</li> |
|
252 | <li>sagittis ac,</li> | |
253 | <li>malesuada in,</li> |
|
253 | <li>malesuada in,</li> | |
254 | <li>adipiscing eu, dolor.</li> |
|
254 | <li>adipiscing eu, dolor.</li> | |
255 | </ul> |
|
255 | </ul> | |
256 | <blockquote> |
|
256 | <blockquote> | |
257 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> |
|
257 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> | |
258 | </blockquote> |
|
258 | </blockquote> | |
259 | <p>Proin a tellus. Nam vel neque.</p> |
|
259 | <p>Proin a tellus. Nam vel neque.</p> | |
260 | </blockquote> |
|
260 | </blockquote> | |
261 | <p>He's right.</p> |
|
261 | <p>He's right.</p> | |
262 | EXPECTED |
|
262 | EXPECTED | |
263 |
|
263 | |||
264 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
264 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') | |
265 | end |
|
265 | end | |
266 |
|
266 | |||
267 | def test_table |
|
267 | def test_table | |
268 | raw = <<-RAW |
|
268 | raw = <<-RAW | |
269 | This is a table with empty cells: |
|
269 | This is a table with empty cells: | |
270 |
|
270 | |||
271 | |cell11|cell12|| |
|
271 | |cell11|cell12|| | |
272 | |cell21||cell23| |
|
272 | |cell21||cell23| | |
273 | |cell31|cell32|cell33| |
|
273 | |cell31|cell32|cell33| | |
274 | RAW |
|
274 | RAW | |
275 |
|
275 | |||
276 | expected = <<-EXPECTED |
|
276 | expected = <<-EXPECTED | |
277 | <p>This is a table with empty cells:</p> |
|
277 | <p>This is a table with empty cells:</p> | |
278 |
|
278 | |||
279 | <table> |
|
279 | <table> | |
280 | <tr><td>cell11</td><td>cell12</td><td></td></tr> |
|
280 | <tr><td>cell11</td><td>cell12</td><td></td></tr> | |
281 | <tr><td>cell21</td><td></td><td>cell23</td></tr> |
|
281 | <tr><td>cell21</td><td></td><td>cell23</td></tr> | |
282 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> |
|
282 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> | |
283 | </table> |
|
283 | </table> | |
284 | EXPECTED |
|
284 | EXPECTED | |
285 |
|
285 | |||
286 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
286 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') | |
287 | end |
|
287 | end | |
288 |
|
288 | |||
289 | def test_macro_hello_world |
|
289 | def test_macro_hello_world | |
290 | text = "{{hello_world}}" |
|
290 | text = "{{hello_world}}" | |
291 | assert textilizable(text).match(/Hello world!/) |
|
291 | assert textilizable(text).match(/Hello world!/) | |
292 | # escaping |
|
292 | # escaping | |
293 | text = "!{{hello_world}}" |
|
293 | text = "!{{hello_world}}" | |
294 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) |
|
294 | assert_equal '<p>{{hello_world}}</p>', textilizable(text) | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | def test_macro_include |
|
297 | def test_macro_include | |
298 | @project = Project.find(1) |
|
298 | @project = Project.find(1) | |
299 | # include a page of the current project wiki |
|
299 | # include a page of the current project wiki | |
300 | text = "{{include(Another page)}}" |
|
300 | text = "{{include(Another page)}}" | |
301 | assert textilizable(text).match(/This is a link to a ticket/) |
|
301 | assert textilizable(text).match(/This is a link to a ticket/) | |
302 |
|
302 | |||
303 | @project = nil |
|
303 | @project = nil | |
304 | # include a page of a specific project wiki |
|
304 | # include a page of a specific project wiki | |
305 | text = "{{include(ecookbook:Another page)}}" |
|
305 | text = "{{include(ecookbook:Another page)}}" | |
306 | assert textilizable(text).match(/This is a link to a ticket/) |
|
306 | assert textilizable(text).match(/This is a link to a ticket/) | |
307 |
|
307 | |||
308 | text = "{{include(ecookbook:)}}" |
|
308 | text = "{{include(ecookbook:)}}" | |
309 | assert textilizable(text).match(/CookBook documentation/) |
|
309 | assert textilizable(text).match(/CookBook documentation/) | |
310 |
|
310 | |||
311 | text = "{{include(unknowidentifier:somepage)}}" |
|
311 | text = "{{include(unknowidentifier:somepage)}}" | |
312 | assert textilizable(text).match(/Unknow project/) |
|
312 | assert textilizable(text).match(/Unknow project/) | |
313 | end |
|
313 | end | |
314 |
|
314 | |||
315 | def test_date_format_default |
|
315 | def test_date_format_default | |
316 | today = Date.today |
|
316 | today = Date.today | |
317 | Setting.date_format = '' |
|
317 | Setting.date_format = '' | |
318 | assert_equal l_date(today), format_date(today) |
|
318 | assert_equal l_date(today), format_date(today) | |
319 | end |
|
319 | end | |
320 |
|
320 | |||
321 | def test_date_format |
|
321 | def test_date_format | |
322 | today = Date.today |
|
322 | today = Date.today | |
323 | Setting.date_format = '%d %m %Y' |
|
323 | Setting.date_format = '%d %m %Y' | |
324 | assert_equal today.strftime('%d %m %Y'), format_date(today) |
|
324 | assert_equal today.strftime('%d %m %Y'), format_date(today) | |
325 | end |
|
325 | end | |
326 |
|
326 | |||
327 | def test_time_format_default |
|
327 | def test_time_format_default | |
328 | now = Time.now |
|
328 | now = Time.now | |
329 | Setting.date_format = '' |
|
329 | Setting.date_format = '' | |
330 | Setting.time_format = '' |
|
330 | Setting.time_format = '' | |
331 | assert_equal l_datetime(now), format_time(now) |
|
331 | assert_equal l_datetime(now), format_time(now) | |
332 | assert_equal l_time(now), format_time(now, false) |
|
332 | assert_equal l_time(now), format_time(now, false) | |
333 | end |
|
333 | end | |
334 |
|
334 | |||
335 | def test_time_format |
|
335 | def test_time_format | |
336 | now = Time.now |
|
336 | now = Time.now | |
337 | Setting.date_format = '%d %m %Y' |
|
337 | Setting.date_format = '%d %m %Y' | |
338 | Setting.time_format = '%H %M' |
|
338 | Setting.time_format = '%H %M' | |
339 | assert_equal now.strftime('%d %m %Y %H %M'), format_time(now) |
|
339 | assert_equal now.strftime('%d %m %Y %H %M'), format_time(now) | |
340 | assert_equal now.strftime('%H %M'), format_time(now, false) |
|
340 | assert_equal now.strftime('%H %M'), format_time(now, false) | |
341 | end |
|
341 | end | |
342 | end |
|
342 | end |
General Comments 0
You need to be logged in to leave comments.
Login now