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