@@ -1,528 +1,528 | |||||
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&t=z&s=">http://foo.bar/page?p=1&t=z&s=</a>', |
|
53 | '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>', | |
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 "title"" alt="This is a double-quoted "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 "title"" alt="This is a double-quoted "title"" />', | |
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_inline_images_inside_tags |
|
84 | def test_inline_images_inside_tags | |
85 | raw = <<-RAW |
|
85 | raw = <<-RAW | |
86 | h1. !foo.png! Heading |
|
86 | h1. !foo.png! Heading | |
87 |
|
87 | |||
88 | Centered image: |
|
88 | Centered image: | |
89 |
|
89 | |||
90 | p=. !bar.gif! |
|
90 | p=. !bar.gif! | |
91 | RAW |
|
91 | RAW | |
92 |
|
92 | |||
93 | assert textilizable(raw).include?('<img src="foo.png" alt="" />') |
|
93 | assert textilizable(raw).include?('<img src="foo.png" alt="" />') | |
94 | assert textilizable(raw).include?('<img src="bar.gif" alt="" />') |
|
94 | assert textilizable(raw).include?('<img src="bar.gif" alt="" />') | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_acronyms |
|
97 | def test_acronyms | |
98 | to_test = { |
|
98 | to_test = { | |
99 | 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>', |
|
99 | 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>', | |
100 | 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted "title"">GPL</acronym>', |
|
100 | 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted "title"">GPL</acronym>', | |
101 | } |
|
101 | } | |
102 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
102 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
103 |
|
103 | |||
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | def test_attached_images |
|
106 | def test_attached_images | |
107 | to_test = { |
|
107 | to_test = { | |
108 | 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', |
|
108 | 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', | |
109 | 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', |
|
109 | 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', | |
110 | 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />', |
|
110 | 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />', | |
111 | 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />', |
|
111 | 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />', | |
112 | # link image |
|
112 | # link image | |
113 | '!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>', |
|
113 | '!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>', | |
114 | } |
|
114 | } | |
115 | attachments = Attachment.find(:all) |
|
115 | attachments = Attachment.find(:all) | |
116 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } |
|
116 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_textile_external_links |
|
119 | def test_textile_external_links | |
120 | to_test = { |
|
120 | to_test = { | |
121 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
121 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', | |
122 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', |
|
122 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', | |
123 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>', |
|
123 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>', | |
124 | '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with "double-quotes"" class="external">link</a>', |
|
124 | '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with "double-quotes"" class="external">link</a>', | |
125 | "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph", |
|
125 | "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph", | |
126 | # no multiline link text |
|
126 | # no multiline link text | |
127 | "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", |
|
127 | "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", | |
128 | # mailto link |
|
128 | # mailto link | |
129 | "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>", |
|
129 | "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>", | |
130 | # two exclamation marks |
|
130 | # two exclamation marks | |
131 | '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>', |
|
131 | '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>', | |
132 | } |
|
132 | } | |
133 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
133 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def test_redmine_links |
|
136 | def test_redmine_links | |
137 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
|
137 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, | |
138 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') |
|
138 | :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') | |
139 |
|
139 | |||
140 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, |
|
140 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, | |
141 | :class => 'changeset', :title => 'My very first commit') |
|
141 | :class => 'changeset', :title => 'My very first commit') | |
142 | changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, |
|
142 | changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, | |
143 | :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') |
|
143 | :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') | |
144 |
|
144 | |||
145 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, |
|
145 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, | |
146 | :class => 'document') |
|
146 | :class => 'document') | |
147 |
|
147 | |||
148 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, |
|
148 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, | |
149 | :class => 'version') |
|
149 | :class => 'version') | |
150 |
|
150 | |||
151 | message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} |
|
151 | message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} | |
152 |
|
152 | |||
153 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} |
|
153 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} | |
154 | source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} |
|
154 | source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} | |
155 |
|
155 | |||
156 | to_test = { |
|
156 | to_test = { | |
157 | # tickets |
|
157 | # tickets | |
158 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", |
|
158 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", | |
159 | # changesets |
|
159 | # changesets | |
160 | 'r1' => changeset_link, |
|
160 | 'r1' => changeset_link, | |
161 | 'r1.' => "#{changeset_link}.", |
|
161 | 'r1.' => "#{changeset_link}.", | |
162 | 'r1, r2' => "#{changeset_link}, #{changeset_link2}", |
|
162 | 'r1, r2' => "#{changeset_link}, #{changeset_link2}", | |
163 | 'r1,r2' => "#{changeset_link},#{changeset_link2}", |
|
163 | 'r1,r2' => "#{changeset_link},#{changeset_link2}", | |
164 | # documents |
|
164 | # documents | |
165 | 'document#1' => document_link, |
|
165 | 'document#1' => document_link, | |
166 | 'document:"Test document"' => document_link, |
|
166 | 'document:"Test document"' => document_link, | |
167 | # versions |
|
167 | # versions | |
168 | 'version#2' => version_link, |
|
168 | 'version#2' => version_link, | |
169 | 'version:1.0' => version_link, |
|
169 | 'version:1.0' => version_link, | |
170 | 'version:"1.0"' => version_link, |
|
170 | 'version:"1.0"' => version_link, | |
171 | # source |
|
171 | # source | |
172 | 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), |
|
172 | 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), | |
173 | 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
173 | 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", | |
174 | 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
174 | 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", | |
175 | 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
175 | 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", | |
176 | 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
176 | 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", | |
177 | 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", |
|
177 | 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", | |
178 | 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), |
|
178 | 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), | |
179 | 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), |
|
179 | 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), | |
180 | 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), |
|
180 | 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), | |
181 | 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), |
|
181 | 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), | |
182 | 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), |
|
182 | 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), | |
183 | 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), |
|
183 | 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), | |
184 | # message |
|
184 | # message | |
185 | 'message#4' => link_to('Post 2', message_url, :class => 'message'), |
|
185 | 'message#4' => link_to('Post 2', message_url, :class => 'message'), | |
186 | 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'), |
|
186 | 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'), | |
187 | # escaping |
|
187 | # escaping | |
188 | '!#3.' => '#3.', |
|
188 | '!#3.' => '#3.', | |
189 | '!r1' => 'r1', |
|
189 | '!r1' => 'r1', | |
190 | '!document#1' => 'document#1', |
|
190 | '!document#1' => 'document#1', | |
191 | '!document:"Test document"' => 'document:"Test document"', |
|
191 | '!document:"Test document"' => 'document:"Test document"', | |
192 | '!version#2' => 'version#2', |
|
192 | '!version#2' => 'version#2', | |
193 | '!version:1.0' => 'version:1.0', |
|
193 | '!version:1.0' => 'version:1.0', | |
194 | '!version:"1.0"' => 'version:"1.0"', |
|
194 | '!version:"1.0"' => 'version:"1.0"', | |
195 | '!source:/some/file' => 'source:/some/file', |
|
195 | '!source:/some/file' => 'source:/some/file', | |
196 | # invalid expressions |
|
196 | # invalid expressions | |
197 | 'source:' => 'source:', |
|
197 | 'source:' => 'source:', | |
198 | # url hash |
|
198 | # url hash | |
199 | "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', |
|
199 | "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', | |
200 | } |
|
200 | } | |
201 | @project = Project.find(1) |
|
201 | @project = Project.find(1) | |
202 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
202 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | def test_wiki_links |
|
205 | def test_wiki_links | |
206 | to_test = { |
|
206 | to_test = { | |
207 | '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
|
207 | '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', | |
208 | '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', |
|
208 | '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>', | |
209 | # link with anchor |
|
209 | # link with anchor | |
210 | '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', |
|
210 | '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', | |
211 | '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>', |
|
211 | '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>', | |
212 | # page that doesn't exist |
|
212 | # page that doesn't exist | |
213 | '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
213 | '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', | |
214 | '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', |
|
214 | '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>', | |
215 | # link to another project wiki |
|
215 | # link to another project wiki | |
216 | '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>', |
|
216 | '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>', | |
217 | '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>', |
|
217 | '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>', | |
218 | '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>', |
|
218 | '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>', | |
219 | '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>', |
|
219 | '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>', | |
220 | '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
220 | '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>', | |
221 | # striked through link |
|
221 | # striked through link | |
222 | '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>', |
|
222 | '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>', | |
223 | '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>', |
|
223 | '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>', | |
224 | # escaping |
|
224 | # escaping | |
225 | '![[Another page|Page]]' => '[[Another page|Page]]', |
|
225 | '![[Another page|Page]]' => '[[Another page|Page]]', | |
226 | # project does not exist |
|
226 | # project does not exist | |
227 | '[[unknowproject:Start]]' => '[[unknowproject:Start]]', |
|
227 | '[[unknowproject:Start]]' => '[[unknowproject:Start]]', | |
228 | '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]', |
|
228 | '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]', | |
229 | } |
|
229 | } | |
230 | @project = Project.find(1) |
|
230 | @project = Project.find(1) | |
231 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
231 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
232 | end |
|
232 | end | |
233 |
|
233 | |||
234 | def test_html_tags |
|
234 | def test_html_tags | |
235 | to_test = { |
|
235 | to_test = { | |
236 | "<div>content</div>" => "<p><div>content</div></p>", |
|
236 | "<div>content</div>" => "<p><div>content</div></p>", | |
237 | "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>", |
|
237 | "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>", | |
238 | "<script>some script;</script>" => "<p><script>some script;</script></p>", |
|
238 | "<script>some script;</script>" => "<p><script>some script;</script></p>", | |
239 | # do not escape pre/code tags |
|
239 | # do not escape pre/code tags | |
240 | "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>", |
|
240 | "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>", | |
241 | "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>", |
|
241 | "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>", | |
242 | "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", |
|
242 | "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", | |
243 | "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", |
|
243 | "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", | |
244 | "<!-- opening comment" => "<p><!-- opening comment</p>", |
|
244 | "<!-- opening comment" => "<p><!-- opening comment</p>", | |
245 | # remove attributes except class |
|
245 | # remove attributes except class | |
246 | "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>", |
|
246 | "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>", | |
247 | "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>", |
|
247 | "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>", | |
248 | } |
|
248 | } | |
249 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
249 | to_test.each { |text, result| assert_equal result, textilizable(text) } | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | def test_allowed_html_tags |
|
252 | def test_allowed_html_tags | |
253 | to_test = { |
|
253 | to_test = { | |
254 | "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", |
|
254 | "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", | |
255 | "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting", |
|
255 | "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting", | |
256 | "<notextile>this is <tag>a tag</tag></notextile>" => "this is <tag>a tag</tag>" |
|
256 | "<notextile>this is <tag>a tag</tag></notextile>" => "this is <tag>a tag</tag>" | |
257 | } |
|
257 | } | |
258 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
258 | to_test.each { |text, result| assert_equal result, textilizable(text) } | |
259 | end |
|
259 | end | |
260 |
|
260 | |||
261 | def test_pre_tags |
|
261 | def test_pre_tags | |
262 | raw = <<-RAW |
|
262 | raw = <<-RAW | |
263 | Before |
|
263 | Before | |
264 |
|
264 | |||
265 | <pre> |
|
265 | <pre> | |
266 | <prepared-statement-cache-size>32</prepared-statement-cache-size> |
|
266 | <prepared-statement-cache-size>32</prepared-statement-cache-size> | |
267 | </pre> |
|
267 | </pre> | |
268 |
|
268 | |||
269 | After |
|
269 | After | |
270 | RAW |
|
270 | RAW | |
271 |
|
271 | |||
272 | expected = <<-EXPECTED |
|
272 | expected = <<-EXPECTED | |
273 | <p>Before</p> |
|
273 | <p>Before</p> | |
274 | <pre> |
|
274 | <pre> | |
275 | <prepared-statement-cache-size>32</prepared-statement-cache-size> |
|
275 | <prepared-statement-cache-size>32</prepared-statement-cache-size> | |
276 | </pre> |
|
276 | </pre> | |
277 | <p>After</p> |
|
277 | <p>After</p> | |
278 | EXPECTED |
|
278 | EXPECTED | |
279 |
|
279 | |||
280 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') |
|
280 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') | |
281 | end |
|
281 | end | |
282 |
|
282 | |||
283 | def test_syntax_highlight |
|
283 | def test_syntax_highlight | |
284 | raw = <<-RAW |
|
284 | raw = <<-RAW | |
285 | <pre><code class="ruby"> |
|
285 | <pre><code class="ruby"> | |
286 | # Some ruby code here |
|
286 | # Some ruby code here | |
287 | </pre></code> |
|
287 | </pre></code> | |
288 | RAW |
|
288 | RAW | |
289 |
|
289 | |||
290 | expected = <<-EXPECTED |
|
290 | expected = <<-EXPECTED | |
291 | <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span> |
|
291 | <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span> | |
292 | </pre></code> |
|
292 | </pre></code> | |
293 | EXPECTED |
|
293 | EXPECTED | |
294 |
|
294 | |||
295 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') |
|
295 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') | |
296 | end |
|
296 | end | |
297 |
|
297 | |||
298 | def test_wiki_links_in_tables |
|
298 | def test_wiki_links_in_tables | |
299 | to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => |
|
299 | to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => | |
300 | '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' + |
|
300 | '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' + | |
301 | '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' + |
|
301 | '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' + | |
302 | '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>' |
|
302 | '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>' | |
303 | } |
|
303 | } | |
304 | @project = Project.find(1) |
|
304 | @project = Project.find(1) | |
305 | to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } |
|
305 | to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | def test_text_formatting |
|
308 | def test_text_formatting | |
309 | to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', |
|
309 | to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', | |
310 | '(_text within parentheses_)' => '(<em>text within parentheses</em>)', |
|
310 | '(_text within parentheses_)' => '(<em>text within parentheses</em>)', | |
311 | 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator', |
|
311 | 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator', | |
312 | '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>', |
|
312 | '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>', | |
313 | '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', |
|
313 | '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', | |
314 | } |
|
314 | } | |
315 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
315 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
316 | end |
|
316 | end | |
317 |
|
317 | |||
318 | def test_wiki_horizontal_rule |
|
318 | def test_wiki_horizontal_rule | |
319 | assert_equal '<hr />', textilizable('---') |
|
319 | assert_equal '<hr />', textilizable('---') | |
320 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') |
|
320 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') | |
321 | end |
|
321 | end | |
322 |
|
322 | |||
323 | def test_acronym |
|
323 | def test_acronym | |
324 | assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>', |
|
324 | assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>', | |
325 | textilizable('This is an acronym: ACLU(American Civil Liberties Union).') |
|
325 | textilizable('This is an acronym: ACLU(American Civil Liberties Union).') | |
326 | end |
|
326 | end | |
327 |
|
327 | |||
328 | def test_footnotes |
|
328 | def test_footnotes | |
329 | raw = <<-RAW |
|
329 | raw = <<-RAW | |
330 | This is some text[1]. |
|
330 | This is some text[1]. | |
331 |
|
331 | |||
332 | fn1. This is the foot note |
|
332 | fn1. This is the foot note | |
333 | RAW |
|
333 | RAW | |
334 |
|
334 | |||
335 | expected = <<-EXPECTED |
|
335 | expected = <<-EXPECTED | |
336 | <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p> |
|
336 | <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p> | |
337 | <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p> |
|
337 | <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p> | |
338 | EXPECTED |
|
338 | EXPECTED | |
339 |
|
339 | |||
340 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') |
|
340 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') | |
341 | end |
|
341 | end | |
342 |
|
342 | |||
343 | def test_table_of_content |
|
343 | def test_table_of_content | |
344 | raw = <<-RAW |
|
344 | raw = <<-RAW | |
345 | {{toc}} |
|
345 | {{toc}} | |
346 |
|
346 | |||
347 | h1. Title |
|
347 | h1. Title | |
348 |
|
348 | |||
349 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
349 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
350 |
|
350 | |||
351 | h2. Subtitle with a [[Wiki]] link |
|
351 | h2. Subtitle with a [[Wiki]] link | |
352 |
|
352 | |||
353 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
353 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
354 |
|
354 | |||
355 | h2. Subtitle with [[Wiki|another Wiki]] link |
|
355 | h2. Subtitle with [[Wiki|another Wiki]] link | |
356 |
|
356 | |||
357 | h2. Subtitle with %{color:red}red text% |
|
357 | h2. Subtitle with %{color:red}red text% | |
358 |
|
358 | |||
359 | h1. Another title |
|
359 | h1. Another title | |
360 |
|
360 | |||
361 | RAW |
|
361 | RAW | |
362 |
|
362 | |||
363 | expected = '<ul class="toc">' + |
|
363 | expected = '<ul class="toc">' + | |
364 | '<li class="heading1"><a href="#Title">Title</a></li>' + |
|
364 | '<li class="heading1"><a href="#Title">Title</a></li>' + | |
365 | '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' + |
|
365 | '<li class="heading2"><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' + | |
366 | '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' + |
|
366 | '<li class="heading2"><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' + | |
367 | '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' + |
|
367 | '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' + | |
368 | '<li class="heading1"><a href="#Another-title">Another title</a></li>' + |
|
368 | '<li class="heading1"><a href="#Another-title">Another title</a></li>' + | |
369 | '</ul>' |
|
369 | '</ul>' | |
370 |
|
370 | |||
371 | assert textilizable(raw).gsub("\n", "").include?(expected) |
|
371 | assert textilizable(raw).gsub("\n", "").include?(expected) | |
372 | end |
|
372 | end | |
373 |
|
373 | |||
374 | def test_blockquote |
|
374 | def test_blockquote | |
375 | # orig raw text |
|
375 | # orig raw text | |
376 | raw = <<-RAW |
|
376 | raw = <<-RAW | |
377 | John said: |
|
377 | John said: | |
378 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
378 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
379 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
379 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
380 | > * Donec odio lorem, |
|
380 | > * Donec odio lorem, | |
381 | > * sagittis ac, |
|
381 | > * sagittis ac, | |
382 | > * malesuada in, |
|
382 | > * malesuada in, | |
383 | > * adipiscing eu, dolor. |
|
383 | > * adipiscing eu, dolor. | |
384 | > |
|
384 | > | |
385 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. |
|
385 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. | |
386 | > Proin a tellus. Nam vel neque. |
|
386 | > Proin a tellus. Nam vel neque. | |
387 |
|
387 | |||
388 | He's right. |
|
388 | He's right. | |
389 | RAW |
|
389 | RAW | |
390 |
|
390 | |||
391 | # expected html |
|
391 | # expected html | |
392 | expected = <<-EXPECTED |
|
392 | expected = <<-EXPECTED | |
393 | <p>John said:</p> |
|
393 | <p>John said:</p> | |
394 | <blockquote> |
|
394 | <blockquote> | |
395 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
395 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |
396 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
396 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |
397 | <ul> |
|
397 | <ul> | |
398 | <li>Donec odio lorem,</li> |
|
398 | <li>Donec odio lorem,</li> | |
399 | <li>sagittis ac,</li> |
|
399 | <li>sagittis ac,</li> | |
400 | <li>malesuada in,</li> |
|
400 | <li>malesuada in,</li> | |
401 | <li>adipiscing eu, dolor.</li> |
|
401 | <li>adipiscing eu, dolor.</li> | |
402 | </ul> |
|
402 | </ul> | |
403 | <blockquote> |
|
403 | <blockquote> | |
404 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> |
|
404 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> | |
405 | </blockquote> |
|
405 | </blockquote> | |
406 | <p>Proin a tellus. Nam vel neque.</p> |
|
406 | <p>Proin a tellus. Nam vel neque.</p> | |
407 | </blockquote> |
|
407 | </blockquote> | |
408 | <p>He's right.</p> |
|
408 | <p>He's right.</p> | |
409 | EXPECTED |
|
409 | EXPECTED | |
410 |
|
410 | |||
411 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
411 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') | |
412 | end |
|
412 | end | |
413 |
|
413 | |||
414 | def test_table |
|
414 | def test_table | |
415 | raw = <<-RAW |
|
415 | raw = <<-RAW | |
416 | This is a table with empty cells: |
|
416 | This is a table with empty cells: | |
417 |
|
417 | |||
418 | |cell11|cell12|| |
|
418 | |cell11|cell12|| | |
419 | |cell21||cell23| |
|
419 | |cell21||cell23| | |
420 | |cell31|cell32|cell33| |
|
420 | |cell31|cell32|cell33| | |
421 | RAW |
|
421 | RAW | |
422 |
|
422 | |||
423 | expected = <<-EXPECTED |
|
423 | expected = <<-EXPECTED | |
424 | <p>This is a table with empty cells:</p> |
|
424 | <p>This is a table with empty cells:</p> | |
425 |
|
425 | |||
426 | <table> |
|
426 | <table> | |
427 | <tr><td>cell11</td><td>cell12</td><td></td></tr> |
|
427 | <tr><td>cell11</td><td>cell12</td><td></td></tr> | |
428 | <tr><td>cell21</td><td></td><td>cell23</td></tr> |
|
428 | <tr><td>cell21</td><td></td><td>cell23</td></tr> | |
429 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> |
|
429 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> | |
430 | </table> |
|
430 | </table> | |
431 | EXPECTED |
|
431 | EXPECTED | |
432 |
|
432 | |||
433 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
433 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') | |
434 | end |
|
434 | end | |
435 |
|
435 | |||
436 | def test_table_with_line_breaks |
|
436 | def test_table_with_line_breaks | |
437 | raw = <<-RAW |
|
437 | raw = <<-RAW | |
438 | This is a table with line breaks: |
|
438 | This is a table with line breaks: | |
439 |
|
439 | |||
440 | |cell11 |
|
440 | |cell11 | |
441 | continued|cell12|| |
|
441 | continued|cell12|| | |
442 | |-cell21-||cell23 |
|
442 | |-cell21-||cell23 | |
443 | cell23 line2 |
|
443 | cell23 line2 | |
444 | cell23 *line3*| |
|
444 | cell23 *line3*| | |
445 | |cell31|cell32 |
|
445 | |cell31|cell32 | |
446 | cell32 line2|cell33| |
|
446 | cell32 line2|cell33| | |
447 |
|
447 | |||
448 | RAW |
|
448 | RAW | |
449 |
|
449 | |||
450 | expected = <<-EXPECTED |
|
450 | expected = <<-EXPECTED | |
451 | <p>This is a table with line breaks:</p> |
|
451 | <p>This is a table with line breaks:</p> | |
452 |
|
452 | |||
453 | <table> |
|
453 | <table> | |
454 | <tr> |
|
454 | <tr> | |
455 | <td>cell11<br />continued</td> |
|
455 | <td>cell11<br />continued</td> | |
456 | <td>cell12</td> |
|
456 | <td>cell12</td> | |
457 | <td></td> |
|
457 | <td></td> | |
458 | </tr> |
|
458 | </tr> | |
459 | <tr> |
|
459 | <tr> | |
460 | <td><del>cell21</del></td> |
|
460 | <td><del>cell21</del></td> | |
461 | <td></td> |
|
461 | <td></td> | |
462 | <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td> |
|
462 | <td>cell23<br/>cell23 line2<br/>cell23 <strong>line3</strong></td> | |
463 | </tr> |
|
463 | </tr> | |
464 | <tr> |
|
464 | <tr> | |
465 | <td>cell31</td> |
|
465 | <td>cell31</td> | |
466 | <td>cell32<br/>cell32 line2</td> |
|
466 | <td>cell32<br/>cell32 line2</td> | |
467 | <td>cell33</td> |
|
467 | <td>cell33</td> | |
468 | </tr> |
|
468 | </tr> | |
469 | </table> |
|
469 | </table> | |
470 | EXPECTED |
|
470 | EXPECTED | |
471 |
|
471 | |||
472 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
472 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') | |
473 | end |
|
473 | end | |
474 |
|
474 | |||
475 | def test_default_formatter |
|
475 | def test_default_formatter | |
476 | Setting.text_formatting = 'unknown' |
|
476 | Setting.text_formatting = 'unknown' | |
477 | text = 'a *link*: http://www.example.net/' |
|
477 | text = 'a *link*: http://www.example.net/' | |
478 | assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text) |
|
478 | assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text) | |
479 | Setting.text_formatting = 'textile' |
|
479 | Setting.text_formatting = 'textile' | |
480 | end |
|
480 | end | |
481 |
|
481 | |||
482 | def test_due_date_distance_in_words |
|
482 | def test_due_date_distance_in_words | |
483 | to_test = { Date.today => 'Due in 0 days', |
|
483 | to_test = { Date.today => 'Due in 0 days', | |
484 | Date.today + 1 => 'Due in 1 day', |
|
484 | Date.today + 1 => 'Due in 1 day', | |
485 | Date.today + 100 => 'Due in about 3 months', |
|
485 | Date.today + 100 => 'Due in about 3 months', | |
486 | Date.today + 20000 => 'Due in over 54 years', |
|
486 | Date.today + 20000 => 'Due in over 54 years', | |
487 | Date.today - 1 => '1 day late', |
|
487 | Date.today - 1 => '1 day late', | |
488 | Date.today - 100 => 'about 3 months late', |
|
488 | Date.today - 100 => 'about 3 months late', | |
489 | Date.today - 20000 => 'over 54 years late', |
|
489 | Date.today - 20000 => 'over 54 years late', | |
490 | } |
|
490 | } | |
491 | to_test.each do |date, expected| |
|
491 | to_test.each do |date, expected| | |
492 | assert_equal expected, due_date_distance_in_words(date) |
|
492 | assert_equal expected, due_date_distance_in_words(date) | |
493 | end |
|
493 | end | |
494 | end |
|
494 | end | |
495 |
|
495 | |||
496 | def test_avatar |
|
496 | def test_avatar | |
497 | # turn on avatars |
|
497 | # turn on avatars | |
498 | Setting.gravatar_enabled = '1' |
|
498 | Setting.gravatar_enabled = '1' | |
499 | assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) |
|
499 | assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) | |
500 | assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) |
|
500 | assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) | |
501 | assert_nil avatar('jsmith') |
|
501 | assert_nil avatar('jsmith') | |
502 | assert_nil avatar(nil) |
|
502 | assert_nil avatar(nil) | |
503 |
|
503 | |||
504 | # turn off avatars |
|
504 | # turn off avatars | |
505 | Setting.gravatar_enabled = '0' |
|
505 | Setting.gravatar_enabled = '0' | |
506 | assert_nil avatar(User.find_by_mail('jsmith@somenet.foo')) |
|
506 | assert_nil avatar(User.find_by_mail('jsmith@somenet.foo')) | |
507 | end |
|
507 | end | |
508 |
|
508 | |||
509 | def test_link_to_user |
|
509 | def test_link_to_user | |
510 | user = User.find(2) |
|
510 | user = User.find(2) | |
511 | t = link_to_user(user) |
|
511 | t = link_to_user(user) | |
512 | assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t |
|
512 | assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t | |
513 | end |
|
513 | end | |
514 |
|
514 | |||
515 | def test_link_to_user_should_not_link_to_locked_user |
|
515 | def test_link_to_user_should_not_link_to_locked_user | |
516 | user = User.find(5) |
|
516 | user = User.find(5) | |
517 | assert user.locked? |
|
517 | assert user.locked? | |
518 | t = link_to_user(user) |
|
518 | t = link_to_user(user) | |
519 | assert_equal user.name, t |
|
519 | assert_equal user.name, t | |
520 | end |
|
520 | end | |
521 |
|
521 | |||
522 | def test_link_to_user_should_not_link_to_anonymous |
|
522 | def test_link_to_user_should_not_link_to_anonymous | |
523 | user = User.anonymous |
|
523 | user = User.anonymous | |
524 | assert user.anonymous? |
|
524 | assert user.anonymous? | |
525 | t = link_to_user(user) |
|
525 | t = link_to_user(user) | |
526 | assert_equal ::I18n.t(:label_user_anonymous), t |
|
526 | assert_equal ::I18n.t(:label_user_anonymous), t | |
527 | end |
|
527 | end | |
528 | end |
|
528 | end |
@@ -1,252 +1,259 | |||||
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 MailerTest < ActiveSupport::TestCase |
|
20 | class MailerTest < ActiveSupport::TestCase | |
21 | include Redmine::I18n |
|
21 | include Redmine::I18n | |
|
22 | include ActionController::Assertions::SelectorAssertions | |||
22 | fixtures :projects, :issues, :users, :members, :member_roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories |
|
23 | fixtures :projects, :issues, :users, :members, :member_roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories | |
23 |
|
24 | |||
24 | def test_generated_links_in_emails |
|
25 | def test_generated_links_in_emails | |
25 | ActionMailer::Base.deliveries.clear |
|
26 | ActionMailer::Base.deliveries.clear | |
26 | Setting.host_name = 'mydomain.foo' |
|
27 | Setting.host_name = 'mydomain.foo' | |
27 | Setting.protocol = 'https' |
|
28 | Setting.protocol = 'https' | |
28 |
|
29 | |||
29 | journal = Journal.find(2) |
|
30 | journal = Journal.find(2) | |
30 | assert Mailer.deliver_issue_edit(journal) |
|
31 | assert Mailer.deliver_issue_edit(journal) | |
31 |
|
32 | |||
32 | mail = ActionMailer::Base.deliveries.last |
|
33 | mail = ActionMailer::Base.deliveries.last | |
33 | assert_kind_of TMail::Mail, mail |
|
34 | assert_kind_of TMail::Mail, mail | |
34 | # link to the main ticket |
|
|||
35 | assert mail.body.include?('<a href="https://mydomain.foo/issues/1">Bug #1: Can\'t print recipes</a>') |
|
|||
36 |
|
35 | |||
37 | # link to a referenced ticket |
|
36 | assert_select_email do | |
38 | assert mail.body.include?('<a href="https://mydomain.foo/issues/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
37 | # link to the main ticket | |
39 | # link to a changeset |
|
38 | assert_select "a[href=?]", "https://mydomain.foo/issues/1", :text => "Bug #1: Can't print recipes" | |
40 | assert mail.body.include?('<a href="https://mydomain.foo/projects/ecookbook/repository/revisions/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
39 | # link to a referenced ticket | |
|
40 | assert_select "a[href=?][title=?]", "https://mydomain.foo/issues/2", "Add ingredients categories (Assigned)", :text => "#2" | |||
|
41 | # link to a changeset | |||
|
42 | assert_select "a[href=?][title=?]", "https://mydomain.foo/projects/ecookbook/repository/revisions/2", "This commit fixes #1, #2 and references #1 & #3", :text => "r2" | |||
|
43 | end | |||
41 | end |
|
44 | end | |
42 |
|
45 | |||
43 | def test_generated_links_with_prefix |
|
46 | def test_generated_links_with_prefix | |
44 | relative_url_root = Redmine::Utils.relative_url_root |
|
47 | relative_url_root = Redmine::Utils.relative_url_root | |
45 | ActionMailer::Base.deliveries.clear |
|
48 | ActionMailer::Base.deliveries.clear | |
46 | Setting.host_name = 'mydomain.foo/rdm' |
|
49 | Setting.host_name = 'mydomain.foo/rdm' | |
47 | Setting.protocol = 'http' |
|
50 | Setting.protocol = 'http' | |
48 | Redmine::Utils.relative_url_root = '/rdm' |
|
51 | Redmine::Utils.relative_url_root = '/rdm' | |
49 |
|
52 | |||
50 | journal = Journal.find(2) |
|
53 | journal = Journal.find(2) | |
51 | assert Mailer.deliver_issue_edit(journal) |
|
54 | assert Mailer.deliver_issue_edit(journal) | |
52 |
|
55 | |||
53 | mail = ActionMailer::Base.deliveries.last |
|
56 | mail = ActionMailer::Base.deliveries.last | |
54 | assert_kind_of TMail::Mail, mail |
|
57 | assert_kind_of TMail::Mail, mail | |
55 | # link to the main ticket |
|
58 | ||
56 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/1">Bug #1: Can\'t print recipes</a>') |
|
59 | assert_select_email do | |
57 |
|
60 | # link to the main ticket | ||
58 | # link to a referenced ticket |
|
61 | assert_select "a[href=?]", "http://mydomain.foo/rdm/issues/1", :text => "Bug #1: Can't print recipes" | |
59 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
62 | # link to a referenced ticket | |
60 | # link to a changeset |
|
63 | assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/issues/2", "Add ingredients categories (Assigned)", :text => "#2" | |
61 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
64 | # link to a changeset | |
|
65 | assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", "This commit fixes #1, #2 and references #1 & #3", :text => "r2" | |||
|
66 | end | |||
62 | ensure |
|
67 | ensure | |
63 | # restore it |
|
68 | # restore it | |
64 | Redmine::Utils.relative_url_root = relative_url_root |
|
69 | Redmine::Utils.relative_url_root = relative_url_root | |
65 | end |
|
70 | end | |
66 |
|
71 | |||
67 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
72 | def test_generated_links_with_prefix_and_no_relative_url_root | |
68 | relative_url_root = Redmine::Utils.relative_url_root |
|
73 | relative_url_root = Redmine::Utils.relative_url_root | |
69 | ActionMailer::Base.deliveries.clear |
|
74 | ActionMailer::Base.deliveries.clear | |
70 | Setting.host_name = 'mydomain.foo/rdm' |
|
75 | Setting.host_name = 'mydomain.foo/rdm' | |
71 | Setting.protocol = 'http' |
|
76 | Setting.protocol = 'http' | |
72 | Redmine::Utils.relative_url_root = nil |
|
77 | Redmine::Utils.relative_url_root = nil | |
73 |
|
78 | |||
74 | journal = Journal.find(2) |
|
79 | journal = Journal.find(2) | |
75 | assert Mailer.deliver_issue_edit(journal) |
|
80 | assert Mailer.deliver_issue_edit(journal) | |
76 |
|
81 | |||
77 | mail = ActionMailer::Base.deliveries.last |
|
82 | mail = ActionMailer::Base.deliveries.last | |
78 | assert_kind_of TMail::Mail, mail |
|
83 | assert_kind_of TMail::Mail, mail | |
79 | # link to the main ticket |
|
84 | ||
80 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/1">Bug #1: Can\'t print recipes</a>') |
|
85 | assert_select_email do | |
81 |
|
86 | # link to the main ticket | ||
82 | # link to a referenced ticket |
|
87 | assert_select "a[href=?]", "http://mydomain.foo/rdm/issues/1", :text => "Bug #1: Can't print recipes" | |
83 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
88 | # link to a referenced ticket | |
84 | # link to a changeset |
|
89 | assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/issues/2", "Add ingredients categories (Assigned)", :text => "#2" | |
85 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
90 | # link to a changeset | |
|
91 | assert_select "a[href=?][title=?]", "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", "This commit fixes #1, #2 and references #1 & #3", :text => "r2" | |||
|
92 | end | |||
86 | ensure |
|
93 | ensure | |
87 | # restore it |
|
94 | # restore it | |
88 | Redmine::Utils.relative_url_root = relative_url_root |
|
95 | Redmine::Utils.relative_url_root = relative_url_root | |
89 | end |
|
96 | end | |
90 |
|
97 | |||
91 | def test_email_headers |
|
98 | def test_email_headers | |
92 | ActionMailer::Base.deliveries.clear |
|
99 | ActionMailer::Base.deliveries.clear | |
93 | issue = Issue.find(1) |
|
100 | issue = Issue.find(1) | |
94 | Mailer.deliver_issue_add(issue) |
|
101 | Mailer.deliver_issue_add(issue) | |
95 | mail = ActionMailer::Base.deliveries.last |
|
102 | mail = ActionMailer::Base.deliveries.last | |
96 | assert_not_nil mail |
|
103 | assert_not_nil mail | |
97 | assert_equal 'bulk', mail.header_string('Precedence') |
|
104 | assert_equal 'bulk', mail.header_string('Precedence') | |
98 | assert_equal 'auto-generated', mail.header_string('Auto-Submitted') |
|
105 | assert_equal 'auto-generated', mail.header_string('Auto-Submitted') | |
99 | end |
|
106 | end | |
100 |
|
107 | |||
101 | def test_plain_text_mail |
|
108 | def test_plain_text_mail | |
102 | Setting.plain_text_mail = 1 |
|
109 | Setting.plain_text_mail = 1 | |
103 | journal = Journal.find(2) |
|
110 | journal = Journal.find(2) | |
104 | Mailer.deliver_issue_edit(journal) |
|
111 | Mailer.deliver_issue_edit(journal) | |
105 | mail = ActionMailer::Base.deliveries.last |
|
112 | mail = ActionMailer::Base.deliveries.last | |
106 | assert_equal "text/plain", mail.content_type |
|
113 | assert_equal "text/plain", mail.content_type | |
107 | assert_equal 0, mail.parts.size |
|
114 | assert_equal 0, mail.parts.size | |
108 | assert !mail.encoded.include?('href') |
|
115 | assert !mail.encoded.include?('href') | |
109 | end |
|
116 | end | |
110 |
|
117 | |||
111 | def test_html_mail |
|
118 | def test_html_mail | |
112 | Setting.plain_text_mail = 0 |
|
119 | Setting.plain_text_mail = 0 | |
113 | journal = Journal.find(2) |
|
120 | journal = Journal.find(2) | |
114 | Mailer.deliver_issue_edit(journal) |
|
121 | Mailer.deliver_issue_edit(journal) | |
115 | mail = ActionMailer::Base.deliveries.last |
|
122 | mail = ActionMailer::Base.deliveries.last | |
116 | assert_equal 2, mail.parts.size |
|
123 | assert_equal 2, mail.parts.size | |
117 | assert mail.encoded.include?('href') |
|
124 | assert mail.encoded.include?('href') | |
118 | end |
|
125 | end | |
119 |
|
126 | |||
120 | def test_issue_add_message_id |
|
127 | def test_issue_add_message_id | |
121 | ActionMailer::Base.deliveries.clear |
|
128 | ActionMailer::Base.deliveries.clear | |
122 | issue = Issue.find(1) |
|
129 | issue = Issue.find(1) | |
123 | Mailer.deliver_issue_add(issue) |
|
130 | Mailer.deliver_issue_add(issue) | |
124 | mail = ActionMailer::Base.deliveries.last |
|
131 | mail = ActionMailer::Base.deliveries.last | |
125 | assert_not_nil mail |
|
132 | assert_not_nil mail | |
126 | assert_equal Mailer.message_id_for(issue), mail.message_id |
|
133 | assert_equal Mailer.message_id_for(issue), mail.message_id | |
127 | assert_nil mail.references |
|
134 | assert_nil mail.references | |
128 | end |
|
135 | end | |
129 |
|
136 | |||
130 | def test_issue_edit_message_id |
|
137 | def test_issue_edit_message_id | |
131 | ActionMailer::Base.deliveries.clear |
|
138 | ActionMailer::Base.deliveries.clear | |
132 | journal = Journal.find(1) |
|
139 | journal = Journal.find(1) | |
133 | Mailer.deliver_issue_edit(journal) |
|
140 | Mailer.deliver_issue_edit(journal) | |
134 | mail = ActionMailer::Base.deliveries.last |
|
141 | mail = ActionMailer::Base.deliveries.last | |
135 | assert_not_nil mail |
|
142 | assert_not_nil mail | |
136 | assert_equal Mailer.message_id_for(journal), mail.message_id |
|
143 | assert_equal Mailer.message_id_for(journal), mail.message_id | |
137 | assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s |
|
144 | assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s | |
138 | end |
|
145 | end | |
139 |
|
146 | |||
140 | def test_message_posted_message_id |
|
147 | def test_message_posted_message_id | |
141 | ActionMailer::Base.deliveries.clear |
|
148 | ActionMailer::Base.deliveries.clear | |
142 | message = Message.find(1) |
|
149 | message = Message.find(1) | |
143 | Mailer.deliver_message_posted(message, message.author.mail) |
|
150 | Mailer.deliver_message_posted(message, message.author.mail) | |
144 | mail = ActionMailer::Base.deliveries.last |
|
151 | mail = ActionMailer::Base.deliveries.last | |
145 | assert_not_nil mail |
|
152 | assert_not_nil mail | |
146 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
153 | assert_equal Mailer.message_id_for(message), mail.message_id | |
147 | assert_nil mail.references |
|
154 | assert_nil mail.references | |
148 | end |
|
155 | end | |
149 |
|
156 | |||
150 | def test_reply_posted_message_id |
|
157 | def test_reply_posted_message_id | |
151 | ActionMailer::Base.deliveries.clear |
|
158 | ActionMailer::Base.deliveries.clear | |
152 | message = Message.find(3) |
|
159 | message = Message.find(3) | |
153 | Mailer.deliver_message_posted(message, message.author.mail) |
|
160 | Mailer.deliver_message_posted(message, message.author.mail) | |
154 | mail = ActionMailer::Base.deliveries.last |
|
161 | mail = ActionMailer::Base.deliveries.last | |
155 | assert_not_nil mail |
|
162 | assert_not_nil mail | |
156 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
163 | assert_equal Mailer.message_id_for(message), mail.message_id | |
157 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s |
|
164 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s | |
158 | end |
|
165 | end | |
159 |
|
166 | |||
160 | # test mailer methods for each language |
|
167 | # test mailer methods for each language | |
161 | def test_issue_add |
|
168 | def test_issue_add | |
162 | issue = Issue.find(1) |
|
169 | issue = Issue.find(1) | |
163 | valid_languages.each do |lang| |
|
170 | valid_languages.each do |lang| | |
164 | Setting.default_language = lang.to_s |
|
171 | Setting.default_language = lang.to_s | |
165 | assert Mailer.deliver_issue_add(issue) |
|
172 | assert Mailer.deliver_issue_add(issue) | |
166 | end |
|
173 | end | |
167 | end |
|
174 | end | |
168 |
|
175 | |||
169 | def test_issue_edit |
|
176 | def test_issue_edit | |
170 | journal = Journal.find(1) |
|
177 | journal = Journal.find(1) | |
171 | valid_languages.each do |lang| |
|
178 | valid_languages.each do |lang| | |
172 | Setting.default_language = lang.to_s |
|
179 | Setting.default_language = lang.to_s | |
173 | assert Mailer.deliver_issue_edit(journal) |
|
180 | assert Mailer.deliver_issue_edit(journal) | |
174 | end |
|
181 | end | |
175 | end |
|
182 | end | |
176 |
|
183 | |||
177 | def test_document_added |
|
184 | def test_document_added | |
178 | document = Document.find(1) |
|
185 | document = Document.find(1) | |
179 | valid_languages.each do |lang| |
|
186 | valid_languages.each do |lang| | |
180 | Setting.default_language = lang.to_s |
|
187 | Setting.default_language = lang.to_s | |
181 | assert Mailer.deliver_document_added(document) |
|
188 | assert Mailer.deliver_document_added(document) | |
182 | end |
|
189 | end | |
183 | end |
|
190 | end | |
184 |
|
191 | |||
185 | def test_attachments_added |
|
192 | def test_attachments_added | |
186 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
193 | attachements = [ Attachment.find_by_container_type('Document') ] | |
187 | valid_languages.each do |lang| |
|
194 | valid_languages.each do |lang| | |
188 | Setting.default_language = lang.to_s |
|
195 | Setting.default_language = lang.to_s | |
189 | assert Mailer.deliver_attachments_added(attachements) |
|
196 | assert Mailer.deliver_attachments_added(attachements) | |
190 | end |
|
197 | end | |
191 | end |
|
198 | end | |
192 |
|
199 | |||
193 | def test_news_added |
|
200 | def test_news_added | |
194 | news = News.find(:first) |
|
201 | news = News.find(:first) | |
195 | valid_languages.each do |lang| |
|
202 | valid_languages.each do |lang| | |
196 | Setting.default_language = lang.to_s |
|
203 | Setting.default_language = lang.to_s | |
197 | assert Mailer.deliver_news_added(news) |
|
204 | assert Mailer.deliver_news_added(news) | |
198 | end |
|
205 | end | |
199 | end |
|
206 | end | |
200 |
|
207 | |||
201 | def test_message_posted |
|
208 | def test_message_posted | |
202 | message = Message.find(:first) |
|
209 | message = Message.find(:first) | |
203 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
210 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} | |
204 | recipients = recipients.compact.uniq |
|
211 | recipients = recipients.compact.uniq | |
205 | valid_languages.each do |lang| |
|
212 | valid_languages.each do |lang| | |
206 | Setting.default_language = lang.to_s |
|
213 | Setting.default_language = lang.to_s | |
207 | assert Mailer.deliver_message_posted(message, recipients) |
|
214 | assert Mailer.deliver_message_posted(message, recipients) | |
208 | end |
|
215 | end | |
209 | end |
|
216 | end | |
210 |
|
217 | |||
211 | def test_account_information |
|
218 | def test_account_information | |
212 | user = User.find(:first) |
|
219 | user = User.find(:first) | |
213 | valid_languages.each do |lang| |
|
220 | valid_languages.each do |lang| | |
214 | user.update_attribute :language, lang.to_s |
|
221 | user.update_attribute :language, lang.to_s | |
215 | user.reload |
|
222 | user.reload | |
216 | assert Mailer.deliver_account_information(user, 'pAsswORd') |
|
223 | assert Mailer.deliver_account_information(user, 'pAsswORd') | |
217 | end |
|
224 | end | |
218 | end |
|
225 | end | |
219 |
|
226 | |||
220 | def test_lost_password |
|
227 | def test_lost_password | |
221 | token = Token.find(2) |
|
228 | token = Token.find(2) | |
222 | valid_languages.each do |lang| |
|
229 | valid_languages.each do |lang| | |
223 | token.user.update_attribute :language, lang.to_s |
|
230 | token.user.update_attribute :language, lang.to_s | |
224 | token.reload |
|
231 | token.reload | |
225 | assert Mailer.deliver_lost_password(token) |
|
232 | assert Mailer.deliver_lost_password(token) | |
226 | end |
|
233 | end | |
227 | end |
|
234 | end | |
228 |
|
235 | |||
229 | def test_register |
|
236 | def test_register | |
230 | token = Token.find(1) |
|
237 | token = Token.find(1) | |
231 | Setting.host_name = 'redmine.foo' |
|
238 | Setting.host_name = 'redmine.foo' | |
232 | Setting.protocol = 'https' |
|
239 | Setting.protocol = 'https' | |
233 |
|
240 | |||
234 | valid_languages.each do |lang| |
|
241 | valid_languages.each do |lang| | |
235 | token.user.update_attribute :language, lang.to_s |
|
242 | token.user.update_attribute :language, lang.to_s | |
236 | token.reload |
|
243 | token.reload | |
237 | ActionMailer::Base.deliveries.clear |
|
244 | ActionMailer::Base.deliveries.clear | |
238 | assert Mailer.deliver_register(token) |
|
245 | assert Mailer.deliver_register(token) | |
239 | mail = ActionMailer::Base.deliveries.last |
|
246 | mail = ActionMailer::Base.deliveries.last | |
240 | assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}") |
|
247 | assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}") | |
241 | end |
|
248 | end | |
242 | end |
|
249 | end | |
243 |
|
250 | |||
244 | def test_reminders |
|
251 | def test_reminders | |
245 | ActionMailer::Base.deliveries.clear |
|
252 | ActionMailer::Base.deliveries.clear | |
246 | Mailer.reminders(:days => 42) |
|
253 | Mailer.reminders(:days => 42) | |
247 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
254 | assert_equal 1, ActionMailer::Base.deliveries.size | |
248 | mail = ActionMailer::Base.deliveries.last |
|
255 | mail = ActionMailer::Base.deliveries.last | |
249 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
256 | assert mail.bcc.include?('dlopper@somenet.foo') | |
250 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
257 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | |
251 | end |
|
258 | end | |
252 | end |
|
259 | end |
General Comments 0
You need to be logged in to leave comments.
Login now