##// END OF EJS Templates
add unit application helper test to use latest image file (#3261)...
Toshi MARUYAMA -
r7787:627dfd80b637
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -1,184 +1,210
1 1 ---
2 2 attachments_001:
3 3 created_on: 2006-07-19 21:07:27 +02:00
4 4 downloads: 0
5 5 content_type: text/plain
6 6 disk_filename: 060719210727_error281.txt
7 7 container_id: 3
8 8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 9 id: 1
10 10 container_type: Issue
11 11 filesize: 28
12 12 filename: error281.txt
13 13 author_id: 2
14 14 attachments_002:
15 15 created_on: 2007-01-27 15:08:27 +01:00
16 16 downloads: 0
17 17 content_type: text/plain
18 18 disk_filename: 060719210727_document.txt
19 19 container_id: 1
20 20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 21 id: 2
22 22 container_type: Document
23 23 filesize: 28
24 24 filename: document.txt
25 25 author_id: 2
26 26 attachments_003:
27 27 created_on: 2006-07-19 21:07:27 +02:00
28 28 downloads: 0
29 29 content_type: image/gif
30 30 disk_filename: 060719210727_logo.gif
31 31 container_id: 4
32 32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 33 id: 3
34 34 container_type: WikiPage
35 35 filesize: 280
36 36 filename: logo.gif
37 37 description: This is a logo
38 38 author_id: 2
39 39 attachments_004:
40 40 created_on: 2006-07-19 21:07:27 +02:00
41 41 container_type: Issue
42 42 container_id: 3
43 43 downloads: 0
44 44 disk_filename: 060719210727_source.rb
45 45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 46 id: 4
47 47 filesize: 153
48 48 filename: source.rb
49 49 author_id: 2
50 50 description: This is a Ruby source file
51 51 content_type: application/x-ruby
52 52 attachments_005:
53 53 created_on: 2006-07-19 21:07:27 +02:00
54 54 container_type: Issue
55 55 container_id: 3
56 56 downloads: 0
57 57 disk_filename: 060719210727_changeset_iso8859-1.diff
58 58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 59 id: 5
60 60 filesize: 687
61 61 filename: changeset_iso8859-1.diff
62 62 author_id: 2
63 63 content_type: text/x-diff
64 64 attachments_006:
65 65 created_on: 2006-07-19 21:07:27 +02:00
66 66 container_type: Issue
67 67 container_id: 3
68 68 downloads: 0
69 69 disk_filename: 060719210727_archive.zip
70 70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 71 id: 6
72 72 filesize: 157
73 73 filename: archive.zip
74 74 author_id: 2
75 75 content_type: application/octet-stream
76 76 attachments_007:
77 77 created_on: 2006-07-19 21:07:27 +02:00
78 78 container_type: Issue
79 79 container_id: 4
80 80 downloads: 0
81 81 disk_filename: 060719210727_archive.zip
82 82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
83 83 id: 7
84 84 filesize: 157
85 85 filename: archive.zip
86 86 author_id: 1
87 87 content_type: application/octet-stream
88 88 attachments_008:
89 89 created_on: 2006-07-19 21:07:27 +02:00
90 90 container_type: Project
91 91 container_id: 1
92 92 downloads: 0
93 93 disk_filename: 060719210727_project_file.zip
94 94 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
95 95 id: 8
96 96 filesize: 320
97 97 filename: project_file.zip
98 98 author_id: 2
99 99 content_type: application/octet-stream
100 100 attachments_009:
101 101 created_on: 2006-07-19 21:07:27 +02:00
102 102 container_type: Version
103 103 container_id: 1
104 104 downloads: 0
105 105 disk_filename: 060719210727_version_file.zip
106 106 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
107 107 id: 9
108 108 filesize: 452
109 109 filename: version_file.zip
110 110 author_id: 2
111 111 content_type: application/octet-stream
112 112 attachments_010:
113 113 created_on: 2006-07-19 21:07:27 +02:00
114 114 container_type: Issue
115 115 container_id: 2
116 116 downloads: 0
117 117 disk_filename: 060719210727_picture.jpg
118 118 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
119 119 id: 10
120 120 filesize: 452
121 121 filename: picture.jpg
122 122 author_id: 2
123 123 content_type: image/jpeg
124 124 attachments_011:
125 125 created_on: 2007-02-12 15:08:27 +01:00
126 126 container_type: Document
127 127 container_id: 1
128 128 downloads: 0
129 129 disk_filename: 060719210727_picture.jpg
130 130 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
131 131 id: 11
132 132 filesize: 452
133 133 filename: picture.jpg
134 134 author_id: 2
135 135 content_type: image/jpeg
136 136 attachments_012:
137 137 created_on: 2006-07-19 21:07:27 +02:00
138 138 container_type: Version
139 139 container_id: 1
140 140 downloads: 0
141 141 disk_filename: 060719210727_version_file.zip
142 142 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
143 143 id: 12
144 144 filesize: 452
145 145 filename: version_file.zip
146 146 author_id: 2
147 147 content_type: application/octet-stream
148 148 attachments_013:
149 149 created_on: 2006-07-19 21:07:27 +02:00
150 150 container_type: Message
151 151 container_id: 1
152 152 downloads: 0
153 153 disk_filename: 060719210727_foo.zip
154 154 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
155 155 id: 13
156 156 filesize: 452
157 157 filename: foo.zip
158 158 author_id: 2
159 159 content_type: application/octet-stream
160 160 attachments_014:
161 161 created_on: 2006-07-19 21:07:27 +02:00
162 162 container_type: Issue
163 163 container_id: 3
164 164 downloads: 0
165 165 disk_filename: 060719210727_changeset_utf8.diff
166 166 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
167 167 id: 14
168 168 filesize: 687
169 169 filename: changeset_utf8.diff
170 170 author_id: 2
171 171 content_type: text/x-diff
172 172 attachments_015:
173 173 id: 15
174 174 created_on: 2010-07-19 21:07:27 +02:00
175 175 container_type: Issue
176 176 container_id: 14
177 177 downloads: 0
178 178 disk_filename: 060719210727_changeset_utf8.diff
179 179 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
180 180 filesize: 687
181 181 filename: private.diff
182 182 author_id: 2
183 183 content_type: text/x-diff
184 184 description: attachement of a private issue
185 attachments_016:
186 content_type: image/png
187 downloads: 0
188 created_on: 2010-11-23 16:14:50 +09:00
189 disk_filename: 101123161450_testfile_1.png
190 container_id: 14
191 digest: 8e0294de2441577c529f170b6fb8f638
192 id: 16
193 container_type: Issue
194 description: ""
195 filename: testfile.png
196 filesize: 2654
197 author_id: 2
198 attachments_017:
199 content_type: image/png
200 downloads: 0
201 created_on: 2010-12-23 16:14:50 +09:00
202 disk_filename: 101223161450_testfile_2.png
203 container_id: 14
204 digest: 6bc2963e8d7ea0d3e68d12d1fba3d6ca
205 id: 17
206 container_type: Issue
207 description: ""
208 filename: testfile.PNG
209 filesize: 3582
210 author_id: 2
@@ -1,854 +1,879
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../../test_helper', __FILE__)
19 19
20 20 class ApplicationHelperTest < ActionView::TestCase
21 21
22 22 fixtures :projects, :roles, :enabled_modules, :users,
23 23 :repositories, :changesets,
24 24 :trackers, :issue_statuses, :issues, :versions, :documents,
25 25 :wikis, :wiki_pages, :wiki_contents,
26 26 :boards, :messages, :news,
27 27 :attachments,
28 28 :enumerations
29 29
30 30 def setup
31 31 super
32 set_tmp_attachments_directory
32 33 end
33 34
34 35 context "#link_to_if_authorized" do
35 36 context "authorized user" do
36 37 should "be tested"
37 38 end
38 39
39 40 context "unauthorized user" do
40 41 should "be tested"
41 42 end
42 43
43 44 should "allow using the :controller and :action for the target link" do
44 45 User.current = User.find_by_login('admin')
45 46
46 47 @project = Issue.first.project # Used by helper
47 48 response = link_to_if_authorized("By controller/action",
48 49 {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
49 50 assert_match /href/, response
50 51 end
51 52
52 53 end
53 54
54 55 def test_auto_links
55 56 to_test = {
56 57 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
57 58 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
58 59 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
59 60 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.',
60 61 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
61 62 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
62 63 '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>.',
63 64 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
64 65 '(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>)',
65 66 '(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>)',
66 67 '(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>).',
67 68 '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
68 69 '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)',
69 70 '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).',
70 71 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
71 72 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
72 73 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
73 74 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
74 75 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
75 76 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
76 77 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>',
77 78 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>',
78 79 # two exclamation marks
79 80 '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>',
80 81 # escaping
81 82 'http://foo"bar' => '<a class="external" href="http://foo&quot;bar">http://foo"bar</a>',
82 83 # wrap in angle brackets
83 84 '<http://foo.bar>' => '&lt;<a class="external" href="http://foo.bar">http://foo.bar</a>&gt;'
84 85 }
85 86 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
86 87 end
87 88
88 89 def test_auto_mailto
89 90 assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>',
90 91 textilizable('test@foo.bar')
91 92 end
92 93
93 94 def test_inline_images
94 95 to_test = {
95 96 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
96 97 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
97 98 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
98 99 # inline styles should be stripped
99 100 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />',
100 101 '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" />',
101 102 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted &quot;title&quot;" alt="This is a double-quoted &quot;title&quot;" />',
102 103 }
103 104 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
104 105 end
105 106
106 107 def test_inline_images_inside_tags
107 108 raw = <<-RAW
108 109 h1. !foo.png! Heading
109 110
110 111 Centered image:
111 112
112 113 p=. !bar.gif!
113 114 RAW
114 115
115 116 assert textilizable(raw).include?('<img src="foo.png" alt="" />')
116 117 assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
117 118 end
118 119
119 120 def test_attached_images
120 121 to_test = {
121 122 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
122 123 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
123 124 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />',
124 125 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />',
125 126 # link image
126 127 '!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>',
127 128 }
128 129 attachments = Attachment.find(:all)
129 130 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
130 131 end
131 132
132 133 def test_attached_images_filename_extension
133 134 set_tmp_attachments_directory
134 135 a1 = Attachment.new(
135 136 :container => Issue.find(1),
136 137 :file => mock_file_with_options({:original_filename => "testtest.JPG"}),
137 138 :author => User.find(1))
138 139 assert a1.save
139 140 assert_equal "testtest.JPG", a1.filename
140 141 assert_equal "image/jpeg", a1.content_type
141 142 assert a1.image?
142 143
143 144 a2 = Attachment.new(
144 145 :container => Issue.find(1),
145 146 :file => mock_file_with_options({:original_filename => "testtest.jpeg"}),
146 147 :author => User.find(1))
147 148 assert a2.save
148 149 assert_equal "testtest.jpeg", a2.filename
149 150 assert_equal "image/jpeg", a2.content_type
150 151 assert a2.image?
151 152
152 153 a3 = Attachment.new(
153 154 :container => Issue.find(1),
154 155 :file => mock_file_with_options({:original_filename => "testtest.JPE"}),
155 156 :author => User.find(1))
156 157 assert a3.save
157 158 assert_equal "testtest.JPE", a3.filename
158 159 assert_equal "image/jpeg", a3.content_type
159 160 assert a3.image?
160 161
161 162 a4 = Attachment.new(
162 163 :container => Issue.find(1),
163 164 :file => mock_file_with_options({:original_filename => "Testtest.BMP"}),
164 165 :author => User.find(1))
165 166 assert a4.save
166 167 assert_equal "Testtest.BMP", a4.filename
167 168 assert_equal "image/x-ms-bmp", a4.content_type
168 169 assert a4.image?
169 170
170 171 to_test = {
171 172 'Inline image: !testtest.jpg!' =>
172 173 'Inline image: <img src="/attachments/download/' + a1.id.to_s + '" alt="" />',
173 174 'Inline image: !testtest.jpeg!' =>
174 175 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
175 176 'Inline image: !testtest.jpe!' =>
176 177 'Inline image: <img src="/attachments/download/' + a3.id.to_s + '" alt="" />',
177 178 'Inline image: !testtest.bmp!' =>
178 179 'Inline image: <img src="/attachments/download/' + a4.id.to_s + '" alt="" />',
179 180 }
180 181
181 182 attachments = [a1, a2, a3, a4]
182 183 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
183 184 end
184 185
186 def test_attached_images_should_read_later
187 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
188 a1 = Attachment.find(16)
189 assert_equal "testfile.png", a1.filename
190 assert a1.readable?
191 assert (! a1.visible?(User.anonymous))
192 assert a1.visible?(User.find(2))
193 a2 = Attachment.find(17)
194 assert_equal "testfile.PNG", a2.filename
195 assert a2.readable?
196 assert (! a2.visible?(User.anonymous))
197 assert a2.visible?(User.find(2))
198 assert a1.created_on < a2.created_on
199
200 to_test = {
201 'Inline image: !testfile.png!' =>
202 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
203 'Inline image: !Testfile.PNG!' =>
204 'Inline image: <img src="/attachments/download/' + a2.id.to_s + '" alt="" />',
205 }
206 attachments = [a1, a2]
207 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
208 end
209
185 210 def test_textile_external_links
186 211 to_test = {
187 212 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
188 213 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
189 214 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
190 215 '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with &quot;double-quotes&quot;" class="external">link</a>',
191 216 "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph",
192 217 # no multiline link text
193 218 "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",
194 219 # mailto link
195 220 "\"system administrator\":mailto:sysadmin@example.com?subject=redmine%20permissions" => "<a href=\"mailto:sysadmin@example.com?subject=redmine%20permissions\">system administrator</a>",
196 221 # two exclamation marks
197 222 '"a link":http://example.net/path!602815048C7B5C20!302.html' => '<a href="http://example.net/path!602815048C7B5C20!302.html" class="external">a link</a>',
198 223 # escaping
199 224 '"test":http://foo"bar' => '<a href="http://foo&quot;bar" class="external">test</a>',
200 225 }
201 226 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
202 227 end
203 228
204 229 def test_redmine_links
205 230 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
206 231 :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
207 232
208 233 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
209 234 :class => 'changeset', :title => 'My very first commit')
210 235 changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
211 236 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
212 237
213 238 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
214 239 :class => 'document')
215 240
216 241 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
217 242 :class => 'version')
218 243
219 244 board_url = {:controller => 'boards', :action => 'show', :id => 2, :project_id => 'ecookbook'}
220 245
221 246 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
222 247
223 248 news_url = {:controller => 'news', :action => 'show', :id => 1}
224 249
225 250 project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
226 251
227 252 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
228 253 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
229 254
230 255 to_test = {
231 256 # tickets
232 257 '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
233 258 # changesets
234 259 'r1' => changeset_link,
235 260 'r1.' => "#{changeset_link}.",
236 261 'r1, r2' => "#{changeset_link}, #{changeset_link2}",
237 262 'r1,r2' => "#{changeset_link},#{changeset_link2}",
238 263 # documents
239 264 'document#1' => document_link,
240 265 'document:"Test document"' => document_link,
241 266 # versions
242 267 'version#2' => version_link,
243 268 'version:1.0' => version_link,
244 269 'version:"1.0"' => version_link,
245 270 # source
246 271 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
247 272 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".",
248 273 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
249 274 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".",
250 275 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".",
251 276 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",",
252 277 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
253 278 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'),
254 279 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
255 280 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
256 281 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
257 282 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
258 283 # forum
259 284 'forum#2' => link_to('Discussion', board_url, :class => 'board'),
260 285 'forum:Discussion' => link_to('Discussion', board_url, :class => 'board'),
261 286 # message
262 287 'message#4' => link_to('Post 2', message_url, :class => 'message'),
263 288 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5', :r => 5), :class => 'message'),
264 289 # news
265 290 'news#1' => link_to('eCookbook first release !', news_url, :class => 'news'),
266 291 'news:"eCookbook first release !"' => link_to('eCookbook first release !', news_url, :class => 'news'),
267 292 # project
268 293 'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
269 294 'project:subproject1' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
270 295 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
271 296 # escaping
272 297 '!#3.' => '#3.',
273 298 '!r1' => 'r1',
274 299 '!document#1' => 'document#1',
275 300 '!document:"Test document"' => 'document:"Test document"',
276 301 '!version#2' => 'version#2',
277 302 '!version:1.0' => 'version:1.0',
278 303 '!version:"1.0"' => 'version:"1.0"',
279 304 '!source:/some/file' => 'source:/some/file',
280 305 # not found
281 306 '#0123456789' => '#0123456789',
282 307 # invalid expressions
283 308 'source:' => 'source:',
284 309 # url hash
285 310 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
286 311 }
287 312 @project = Project.find(1)
288 313 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
289 314 end
290 315
291 316 def test_cross_project_redmine_links
292 317 source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
293 318 :class => 'source')
294 319
295 320 changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
296 321 :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
297 322
298 323 to_test = {
299 324 # documents
300 325 'document:"Test document"' => 'document:"Test document"',
301 326 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>',
302 327 'invalid:document:"Test document"' => 'invalid:document:"Test document"',
303 328 # versions
304 329 'version:"1.0"' => 'version:"1.0"',
305 330 'ecookbook:version:"1.0"' => '<a href="/versions/2" class="version">1.0</a>',
306 331 'invalid:version:"1.0"' => 'invalid:version:"1.0"',
307 332 # changeset
308 333 'r2' => 'r2',
309 334 'ecookbook:r2' => changeset_link,
310 335 'invalid:r2' => 'invalid:r2',
311 336 # source
312 337 'source:/some/file' => 'source:/some/file',
313 338 'ecookbook:source:/some/file' => source_link,
314 339 'invalid:source:/some/file' => 'invalid:source:/some/file',
315 340 }
316 341 @project = Project.find(3)
317 342 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
318 343 end
319 344
320 345 def test_redmine_links_git_commit
321 346 changeset_link = link_to('abcd',
322 347 {
323 348 :controller => 'repositories',
324 349 :action => 'revision',
325 350 :id => 'subproject1',
326 351 :rev => 'abcd',
327 352 },
328 353 :class => 'changeset', :title => 'test commit')
329 354 to_test = {
330 355 'commit:abcd' => changeset_link,
331 356 }
332 357 @project = Project.find(3)
333 358 r = Repository::Git.create!(:project => @project, :url => '/tmp/test/git')
334 359 assert r
335 360 c = Changeset.new(:repository => r,
336 361 :committed_on => Time.now,
337 362 :revision => 'abcd',
338 363 :scmid => 'abcd',
339 364 :comments => 'test commit')
340 365 assert( c.save )
341 366 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
342 367 end
343 368
344 369 # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
345 370 def test_redmine_links_darcs_commit
346 371 changeset_link = link_to('20080308225258-98289-abcd456efg.gz',
347 372 {
348 373 :controller => 'repositories',
349 374 :action => 'revision',
350 375 :id => 'subproject1',
351 376 :rev => '123',
352 377 },
353 378 :class => 'changeset', :title => 'test commit')
354 379 to_test = {
355 380 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
356 381 }
357 382 @project = Project.find(3)
358 383 r = Repository::Darcs.create!(
359 384 :project => @project, :url => '/tmp/test/darcs',
360 385 :log_encoding => 'UTF-8')
361 386 assert r
362 387 c = Changeset.new(:repository => r,
363 388 :committed_on => Time.now,
364 389 :revision => '123',
365 390 :scmid => '20080308225258-98289-abcd456efg.gz',
366 391 :comments => 'test commit')
367 392 assert( c.save )
368 393 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
369 394 end
370 395
371 396 def test_redmine_links_mercurial_commit
372 397 changeset_link_rev = link_to('r123',
373 398 {
374 399 :controller => 'repositories',
375 400 :action => 'revision',
376 401 :id => 'subproject1',
377 402 :rev => '123' ,
378 403 },
379 404 :class => 'changeset', :title => 'test commit')
380 405 changeset_link_commit = link_to('abcd',
381 406 {
382 407 :controller => 'repositories',
383 408 :action => 'revision',
384 409 :id => 'subproject1',
385 410 :rev => 'abcd' ,
386 411 },
387 412 :class => 'changeset', :title => 'test commit')
388 413 to_test = {
389 414 'r123' => changeset_link_rev,
390 415 'commit:abcd' => changeset_link_commit,
391 416 }
392 417 @project = Project.find(3)
393 418 r = Repository::Mercurial.create!(:project => @project, :url => '/tmp/test')
394 419 assert r
395 420 c = Changeset.new(:repository => r,
396 421 :committed_on => Time.now,
397 422 :revision => '123',
398 423 :scmid => 'abcd',
399 424 :comments => 'test commit')
400 425 assert( c.save )
401 426 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
402 427 end
403 428
404 429 def test_attachment_links
405 430 attachment_link = link_to('error281.txt', {:controller => 'attachments', :action => 'download', :id => '1'}, :class => 'attachment')
406 431 to_test = {
407 432 'attachment:error281.txt' => attachment_link
408 433 }
409 434 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
410 435 end
411 436
412 437 def test_wiki_links
413 438 to_test = {
414 439 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
415 440 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
416 441 # title content should be formatted
417 442 '[[Another page|With _styled_ *title*]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With <em>styled</em> <strong>title</strong></a>',
418 443 '[[Another page|With title containing <strong>HTML entities &amp; markups</strong>]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">With title containing &lt;strong&gt;HTML entities &amp; markups&lt;/strong&gt;</a>',
419 444 # link with anchor
420 445 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
421 446 '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
422 447 # page that doesn't exist
423 448 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
424 449 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
425 450 # link to another project wiki
426 451 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
427 452 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">Wiki</a>',
428 453 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
429 454 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
430 455 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
431 456 # striked through link
432 457 '-[[Another page|Page]]-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a></del>',
433 458 '-[[Another page|Page]] link-' => '<del><a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a> link</del>',
434 459 # escaping
435 460 '![[Another page|Page]]' => '[[Another page|Page]]',
436 461 # project does not exist
437 462 '[[unknowproject:Start]]' => '[[unknowproject:Start]]',
438 463 '[[unknowproject:Start|Page title]]' => '[[unknowproject:Start|Page title]]',
439 464 }
440 465
441 466 @project = Project.find(1)
442 467 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
443 468 end
444 469
445 470 def test_wiki_links_within_local_file_generation_context
446 471
447 472 to_test = {
448 473 # link to a page
449 474 '[[CookBook documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">CookBook documentation</a>',
450 475 '[[CookBook documentation|documentation]]' => '<a href="CookBook_documentation.html" class="wiki-page">documentation</a>',
451 476 '[[CookBook documentation#One-section]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">CookBook documentation</a>',
452 477 '[[CookBook documentation#One-section|documentation]]' => '<a href="CookBook_documentation.html#One-section" class="wiki-page">documentation</a>',
453 478 # page that doesn't exist
454 479 '[[Unknown page]]' => '<a href="Unknown_page.html" class="wiki-page new">Unknown page</a>',
455 480 '[[Unknown page|404]]' => '<a href="Unknown_page.html" class="wiki-page new">404</a>',
456 481 '[[Unknown page#anchor]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">Unknown page</a>',
457 482 '[[Unknown page#anchor|404]]' => '<a href="Unknown_page.html#anchor" class="wiki-page new">404</a>',
458 483 }
459 484
460 485 @project = Project.find(1)
461 486
462 487 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local) }
463 488 end
464 489
465 490 def test_html_tags
466 491 to_test = {
467 492 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
468 493 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
469 494 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
470 495 # do not escape pre/code tags
471 496 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
472 497 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
473 498 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
474 499 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
475 500 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>",
476 501 # remove attributes except class
477 502 "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>",
478 503 '<pre class="foo">some text</pre>' => '<pre class="foo">some text</pre>',
479 504 "<pre class='foo bar'>some text</pre>" => "<pre class='foo bar'>some text</pre>",
480 505 '<pre class="foo bar">some text</pre>' => '<pre class="foo bar">some text</pre>',
481 506 "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>",
482 507 # xss
483 508 '<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
484 509 '<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
485 510 }
486 511 to_test.each { |text, result| assert_equal result, textilizable(text) }
487 512 end
488 513
489 514 def test_allowed_html_tags
490 515 to_test = {
491 516 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
492 517 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
493 518 "<notextile>this is <tag>a tag</tag></notextile>" => "this is &lt;tag&gt;a tag&lt;/tag&gt;"
494 519 }
495 520 to_test.each { |text, result| assert_equal result, textilizable(text) }
496 521 end
497 522
498 523 def test_pre_tags
499 524 raw = <<-RAW
500 525 Before
501 526
502 527 <pre>
503 528 <prepared-statement-cache-size>32</prepared-statement-cache-size>
504 529 </pre>
505 530
506 531 After
507 532 RAW
508 533
509 534 expected = <<-EXPECTED
510 535 <p>Before</p>
511 536 <pre>
512 537 &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
513 538 </pre>
514 539 <p>After</p>
515 540 EXPECTED
516 541
517 542 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
518 543 end
519 544
520 545 def test_pre_content_should_not_parse_wiki_and_redmine_links
521 546 raw = <<-RAW
522 547 [[CookBook documentation]]
523 548
524 549 #1
525 550
526 551 <pre>
527 552 [[CookBook documentation]]
528 553
529 554 #1
530 555 </pre>
531 556 RAW
532 557
533 558 expected = <<-EXPECTED
534 559 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
535 560 <p><a href="/issues/1" class="issue status-1 priority-1" title="Can't print recipes (New)">#1</a></p>
536 561 <pre>
537 562 [[CookBook documentation]]
538 563
539 564 #1
540 565 </pre>
541 566 EXPECTED
542 567
543 568 @project = Project.find(1)
544 569 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
545 570 end
546 571
547 572 def test_non_closing_pre_blocks_should_be_closed
548 573 raw = <<-RAW
549 574 <pre><code>
550 575 RAW
551 576
552 577 expected = <<-EXPECTED
553 578 <pre><code>
554 579 </code></pre>
555 580 EXPECTED
556 581
557 582 @project = Project.find(1)
558 583 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
559 584 end
560 585
561 586 def test_syntax_highlight
562 587 raw = <<-RAW
563 588 <pre><code class="ruby">
564 589 # Some ruby code here
565 590 </code></pre>
566 591 RAW
567 592
568 593 expected = <<-EXPECTED
569 594 <pre><code class="ruby syntaxhl"><span class=\"CodeRay\"><span class="line-numbers">1</span><span class="comment"># Some ruby code here</span></span>
570 595 </code></pre>
571 596 EXPECTED
572 597
573 598 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
574 599 end
575 600
576 601 def test_wiki_links_in_tables
577 602 to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
578 603 '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
579 604 '<td><a href="/projects/ecookbook/wiki/Other_Page" class="wiki-page new">Other title</a></td>' +
580 605 '</tr><tr><td>Cell 21</td><td><a href="/projects/ecookbook/wiki/Last_page" class="wiki-page new">Last page</a></td></tr>'
581 606 }
582 607 @project = Project.find(1)
583 608 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
584 609 end
585 610
586 611 def test_text_formatting
587 612 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
588 613 '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
589 614 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator',
590 615 '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>',
591 616 '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',
592 617 }
593 618 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
594 619 end
595 620
596 621 def test_wiki_horizontal_rule
597 622 assert_equal '<hr />', textilizable('---')
598 623 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
599 624 end
600 625
601 626 def test_footnotes
602 627 raw = <<-RAW
603 628 This is some text[1].
604 629
605 630 fn1. This is the foot note
606 631 RAW
607 632
608 633 expected = <<-EXPECTED
609 634 <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
610 635 <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
611 636 EXPECTED
612 637
613 638 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
614 639 end
615 640
616 641 def test_headings
617 642 raw = 'h1. Some heading'
618 643 expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
619 644
620 645 assert_equal expected, textilizable(raw)
621 646 end
622 647
623 648 def test_headings_with_special_chars
624 649 # This test makes sure that the generated anchor names match the expected
625 650 # ones even if the heading text contains unconventional characters
626 651 raw = 'h1. Some heading related to version 0.5'
627 652 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
628 653 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
629 654
630 655 assert_equal expected, textilizable(raw)
631 656 end
632 657
633 658 def test_wiki_links_within_wiki_page_context
634 659
635 660 page = WikiPage.find_by_title('Another_page' )
636 661
637 662 to_test = {
638 663 # link to another page
639 664 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
640 665 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
641 666 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
642 667 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
643 668 # link to the current page
644 669 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
645 670 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
646 671 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
647 672 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
648 673 # page that doesn't exist
649 674 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
650 675 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
651 676 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>',
652 677 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>',
653 678 }
654 679
655 680 @project = Project.find(1)
656 681
657 682 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.generate!( :text => text, :page => page ), :text) }
658 683 end
659 684
660 685 def test_wiki_links_anchor_option_should_prepend_page_title_to_href
661 686
662 687 to_test = {
663 688 # link to a page
664 689 '[[CookBook documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">CookBook documentation</a>',
665 690 '[[CookBook documentation|documentation]]' => '<a href="#CookBook_documentation" class="wiki-page">documentation</a>',
666 691 '[[CookBook documentation#One-section]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">CookBook documentation</a>',
667 692 '[[CookBook documentation#One-section|documentation]]' => '<a href="#CookBook_documentation_One-section" class="wiki-page">documentation</a>',
668 693 # page that doesn't exist
669 694 '[[Unknown page]]' => '<a href="#Unknown_page" class="wiki-page new">Unknown page</a>',
670 695 '[[Unknown page|404]]' => '<a href="#Unknown_page" class="wiki-page new">404</a>',
671 696 '[[Unknown page#anchor]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">Unknown page</a>',
672 697 '[[Unknown page#anchor|404]]' => '<a href="#Unknown_page_anchor" class="wiki-page new">404</a>',
673 698 }
674 699
675 700 @project = Project.find(1)
676 701
677 702 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor) }
678 703 end
679 704
680 705 def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
681 706 page = WikiPage.generate!( :title => 'Page Title' )
682 707 content = WikiContent.generate!( :text => 'h1. Some heading', :page => page )
683 708
684 709 expected = %|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading<a href="#Page_Title_Some-heading" class="wiki-anchor">&para;</a></h1>|
685 710
686 711 assert_equal expected, textilizable(content, :text, :wiki_links => :anchor )
687 712 end
688 713
689 714 def test_table_of_content
690 715 raw = <<-RAW
691 716 {{toc}}
692 717
693 718 h1. Title
694 719
695 720 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
696 721
697 722 h2. Subtitle with a [[Wiki]] link
698 723
699 724 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
700 725
701 726 h2. Subtitle with [[Wiki|another Wiki]] link
702 727
703 728 h2. Subtitle with %{color:red}red text%
704 729
705 730 <pre>
706 731 some code
707 732 </pre>
708 733
709 734 h3. Subtitle with *some* _modifiers_
710 735
711 736 h1. Another title
712 737
713 738 h3. An "Internet link":http://www.redmine.org/ inside subtitle
714 739
715 740 h2. "Project Name !/attachments/1234/logo_small.gif! !/attachments/5678/logo_2.png!":/projects/projectname/issues
716 741
717 742 RAW
718 743
719 744 expected = '<ul class="toc">' +
720 745 '<li><a href="#Title">Title</a>' +
721 746 '<ul>' +
722 747 '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
723 748 '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
724 749 '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
725 750 '<ul>' +
726 751 '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
727 752 '</ul>' +
728 753 '</li>' +
729 754 '</ul>' +
730 755 '</li>' +
731 756 '<li><a href="#Another-title">Another title</a>' +
732 757 '<ul>' +
733 758 '<li>' +
734 759 '<ul>' +
735 760 '<li><a href="#An-Internet-link-inside-subtitle">An Internet link inside subtitle</a></li>' +
736 761 '</ul>' +
737 762 '</li>' +
738 763 '<li><a href="#Project-Name">Project Name</a></li>' +
739 764 '</ul>' +
740 765 '</li>' +
741 766 '</ul>'
742 767
743 768 @project = Project.find(1)
744 769 assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw)
745 770 end
746 771
747 772 def test_table_of_content_should_contain_included_page_headings
748 773 raw = <<-RAW
749 774 {{toc}}
750 775
751 776 h1. Included
752 777
753 778 {{include(Child_1)}}
754 779 RAW
755 780
756 781 expected = '<ul class="toc">' +
757 782 '<li><a href="#Included">Included</a></li>' +
758 783 '<li><a href="#Child-page-1">Child page 1</a></li>' +
759 784 '</ul>'
760 785
761 786 @project = Project.find(1)
762 787 assert textilizable(raw).gsub("\n", "").include?(expected)
763 788 end
764 789
765 790 def test_default_formatter
766 791 Setting.text_formatting = 'unknown'
767 792 text = 'a *link*: http://www.example.net/'
768 793 assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
769 794 Setting.text_formatting = 'textile'
770 795 end
771 796
772 797 def test_due_date_distance_in_words
773 798 to_test = { Date.today => 'Due in 0 days',
774 799 Date.today + 1 => 'Due in 1 day',
775 800 Date.today + 100 => 'Due in about 3 months',
776 801 Date.today + 20000 => 'Due in over 54 years',
777 802 Date.today - 1 => '1 day late',
778 803 Date.today - 100 => 'about 3 months late',
779 804 Date.today - 20000 => 'over 54 years late',
780 805 }
781 806 ::I18n.locale = :en
782 807 to_test.each do |date, expected|
783 808 assert_equal expected, due_date_distance_in_words(date)
784 809 end
785 810 end
786 811
787 812 def test_avatar
788 813 # turn on avatars
789 814 Setting.gravatar_enabled = '1'
790 815 assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
791 816 assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
792 817 assert_nil avatar('jsmith')
793 818 assert_nil avatar(nil)
794 819
795 820 # turn off avatars
796 821 Setting.gravatar_enabled = '0'
797 822 assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
798 823 end
799 824
800 825 def test_link_to_user
801 826 user = User.find(2)
802 827 t = link_to_user(user)
803 828 assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t
804 829 end
805 830
806 831 def test_link_to_user_should_not_link_to_locked_user
807 832 user = User.find(5)
808 833 assert user.locked?
809 834 t = link_to_user(user)
810 835 assert_equal user.name, t
811 836 end
812 837
813 838 def test_link_to_user_should_not_link_to_anonymous
814 839 user = User.anonymous
815 840 assert user.anonymous?
816 841 t = link_to_user(user)
817 842 assert_equal ::I18n.t(:label_user_anonymous), t
818 843 end
819 844
820 845 def test_link_to_project
821 846 project = Project.find(1)
822 847 assert_equal %(<a href="/projects/ecookbook">eCookbook</a>),
823 848 link_to_project(project)
824 849 assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>),
825 850 link_to_project(project, :action => 'settings')
826 851 assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>),
827 852 link_to_project(project, {:only_path => false, :jump => 'blah'})
828 853 assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
829 854 link_to_project(project, {:action => 'settings'}, :class => "project")
830 855 end
831 856
832 857 def test_principals_options_for_select_with_users
833 858 users = [User.find(2), User.find(4)]
834 859 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
835 860 principals_options_for_select(users)
836 861 end
837 862
838 863 def test_principals_options_for_select_with_selected
839 864 users = [User.find(2), User.find(4)]
840 865 assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
841 866 principals_options_for_select(users, User.find(4))
842 867 end
843 868
844 869 def test_principals_options_for_select_with_users_and_groups
845 870 users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
846 871 assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
847 872 %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
848 873 principals_options_for_select(users)
849 874 end
850 875
851 876 def test_principals_options_for_select_with_empty_collection
852 877 assert_equal '', principals_options_for_select([])
853 878 end
854 879 end
General Comments 0
You need to be logged in to leave comments. Login now