##// END OF EJS Templates
Test that account activation email contains the appropriate link (#2825)....
Jean-Philippe Lang -
r2493:e67fbdc315a9
parent child
Show More
@@ -1,225 +1,231
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class MailerTest < Test::Unit::TestCase
21 21 include Redmine::I18n
22 22 fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories
23 23
24 24 def test_generated_links_in_emails
25 25 ActionMailer::Base.deliveries.clear
26 26 Setting.host_name = 'mydomain.foo'
27 27 Setting.protocol = 'https'
28 28
29 29 journal = Journal.find(2)
30 30 assert Mailer.deliver_issue_edit(journal)
31 31
32 32 mail = ActionMailer::Base.deliveries.last
33 33 assert_kind_of TMail::Mail, mail
34 34 # link to the main ticket
35 35 assert mail.body.include?('<a href="https://mydomain.foo/issues/1">Bug #1: Can\'t print recipes</a>')
36 36
37 37 # link to a referenced ticket
38 38 assert mail.body.include?('<a href="https://mydomain.foo/issues/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
39 39 # link to a changeset
40 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 &amp; #3">r2</a>')
41 41 end
42 42
43 43 def test_generated_links_with_prefix
44 44 relative_url_root = Redmine::Utils.relative_url_root
45 45 ActionMailer::Base.deliveries.clear
46 46 Setting.host_name = 'mydomain.foo/rdm'
47 47 Setting.protocol = 'http'
48 48 Redmine::Utils.relative_url_root = '/rdm'
49 49
50 50 journal = Journal.find(2)
51 51 assert Mailer.deliver_issue_edit(journal)
52 52
53 53 mail = ActionMailer::Base.deliveries.last
54 54 assert_kind_of TMail::Mail, mail
55 55 # link to the main ticket
56 56 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/1">Bug #1: Can\'t print recipes</a>')
57 57
58 58 # link to a referenced ticket
59 59 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
60 60 # link to a changeset
61 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 &amp; #3">r2</a>')
62 62 ensure
63 63 # restore it
64 64 Redmine::Utils.relative_url_root = relative_url_root
65 65 end
66 66
67 67 def test_generated_links_with_prefix_and_no_relative_url_root
68 68 relative_url_root = Redmine::Utils.relative_url_root
69 69 ActionMailer::Base.deliveries.clear
70 70 Setting.host_name = 'mydomain.foo/rdm'
71 71 Setting.protocol = 'http'
72 72 Redmine::Utils.relative_url_root = nil
73 73
74 74 journal = Journal.find(2)
75 75 assert Mailer.deliver_issue_edit(journal)
76 76
77 77 mail = ActionMailer::Base.deliveries.last
78 78 assert_kind_of TMail::Mail, mail
79 79 # link to the main ticket
80 80 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/1">Bug #1: Can\'t print recipes</a>')
81 81
82 82 # link to a referenced ticket
83 83 assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
84 84 # link to a changeset
85 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 &amp; #3">r2</a>')
86 86 ensure
87 87 # restore it
88 88 Redmine::Utils.relative_url_root = relative_url_root
89 89 end
90 90
91 91 def test_plain_text_mail
92 92 Setting.plain_text_mail = 1
93 93 journal = Journal.find(2)
94 94 Mailer.deliver_issue_edit(journal)
95 95 mail = ActionMailer::Base.deliveries.last
96 96 assert !mail.body.include?('<a href="https://mydomain.foo/issues/1">Bug #1: Can\'t print recipes</a>')
97 97 end
98 98
99 99 def test_issue_add_message_id
100 100 ActionMailer::Base.deliveries.clear
101 101 issue = Issue.find(1)
102 102 Mailer.deliver_issue_add(issue)
103 103 mail = ActionMailer::Base.deliveries.last
104 104 assert_not_nil mail
105 105 assert_equal Mailer.message_id_for(issue), mail.message_id
106 106 assert_nil mail.references
107 107 end
108 108
109 109 def test_issue_edit_message_id
110 110 ActionMailer::Base.deliveries.clear
111 111 journal = Journal.find(1)
112 112 Mailer.deliver_issue_edit(journal)
113 113 mail = ActionMailer::Base.deliveries.last
114 114 assert_not_nil mail
115 115 assert_equal Mailer.message_id_for(journal), mail.message_id
116 116 assert_equal Mailer.message_id_for(journal.issue), mail.references.to_s
117 117 end
118 118
119 119 def test_message_posted_message_id
120 120 ActionMailer::Base.deliveries.clear
121 121 message = Message.find(1)
122 122 Mailer.deliver_message_posted(message, message.author.mail)
123 123 mail = ActionMailer::Base.deliveries.last
124 124 assert_not_nil mail
125 125 assert_equal Mailer.message_id_for(message), mail.message_id
126 126 assert_nil mail.references
127 127 end
128 128
129 129 def test_reply_posted_message_id
130 130 ActionMailer::Base.deliveries.clear
131 131 message = Message.find(3)
132 132 Mailer.deliver_message_posted(message, message.author.mail)
133 133 mail = ActionMailer::Base.deliveries.last
134 134 assert_not_nil mail
135 135 assert_equal Mailer.message_id_for(message), mail.message_id
136 136 assert_equal Mailer.message_id_for(message.parent), mail.references.to_s
137 137 end
138 138
139 139 # test mailer methods for each language
140 140 def test_issue_add
141 141 issue = Issue.find(1)
142 142 valid_languages.each do |lang|
143 143 Setting.default_language = lang.to_s
144 144 assert Mailer.deliver_issue_add(issue)
145 145 end
146 146 end
147 147
148 148 def test_issue_edit
149 149 journal = Journal.find(1)
150 150 valid_languages.each do |lang|
151 151 Setting.default_language = lang.to_s
152 152 assert Mailer.deliver_issue_edit(journal)
153 153 end
154 154 end
155 155
156 156 def test_document_added
157 157 document = Document.find(1)
158 158 valid_languages.each do |lang|
159 159 Setting.default_language = lang.to_s
160 160 assert Mailer.deliver_document_added(document)
161 161 end
162 162 end
163 163
164 164 def test_attachments_added
165 165 attachements = [ Attachment.find_by_container_type('Document') ]
166 166 valid_languages.each do |lang|
167 167 Setting.default_language = lang.to_s
168 168 assert Mailer.deliver_attachments_added(attachements)
169 169 end
170 170 end
171 171
172 172 def test_news_added
173 173 news = News.find(:first)
174 174 valid_languages.each do |lang|
175 175 Setting.default_language = lang.to_s
176 176 assert Mailer.deliver_news_added(news)
177 177 end
178 178 end
179 179
180 180 def test_message_posted
181 181 message = Message.find(:first)
182 182 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
183 183 recipients = recipients.compact.uniq
184 184 valid_languages.each do |lang|
185 185 Setting.default_language = lang.to_s
186 186 assert Mailer.deliver_message_posted(message, recipients)
187 187 end
188 188 end
189 189
190 190 def test_account_information
191 191 user = User.find(:first)
192 192 valid_languages.each do |lang|
193 193 user.update_attribute :language, lang.to_s
194 194 user.reload
195 195 assert Mailer.deliver_account_information(user, 'pAsswORd')
196 196 end
197 197 end
198 198
199 199 def test_lost_password
200 200 token = Token.find(2)
201 201 valid_languages.each do |lang|
202 202 token.user.update_attribute :language, lang.to_s
203 203 token.reload
204 204 assert Mailer.deliver_lost_password(token)
205 205 end
206 206 end
207 207
208 208 def test_register
209 209 token = Token.find(1)
210 Setting.host_name = 'redmine.foo'
211 Setting.protocol = 'https'
212
210 213 valid_languages.each do |lang|
211 214 token.user.update_attribute :language, lang.to_s
212 215 token.reload
216 ActionMailer::Base.deliveries.clear
213 217 assert Mailer.deliver_register(token)
218 mail = ActionMailer::Base.deliveries.last
219 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}")
214 220 end
215 221 end
216 222
217 223 def test_reminders
218 224 ActionMailer::Base.deliveries.clear
219 225 Mailer.reminders(:days => 42)
220 226 assert_equal 1, ActionMailer::Base.deliveries.size
221 227 mail = ActionMailer::Base.deliveries.last
222 228 assert mail.bcc.include?('dlopper@somenet.foo')
223 229 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
224 230 end
225 231 end
General Comments 0
You need to be logged in to leave comments. Login now