@@ -1,518 +1,522 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
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 | include ActionController::Assertions::SelectorAssertions | |
23 | fixtures :projects, :enabled_modules, :issues, :users, :members, |
|
23 | fixtures :projects, :enabled_modules, :issues, :users, :members, | |
24 | :member_roles, :roles, :documents, :attachments, :news, |
|
24 | :member_roles, :roles, :documents, :attachments, :news, | |
25 | :tokens, :journals, :journal_details, :changesets, :trackers, |
|
25 | :tokens, :journals, :journal_details, :changesets, :trackers, | |
26 | :issue_statuses, :enumerations, :messages, :boards, :repositories, |
|
26 | :issue_statuses, :enumerations, :messages, :boards, :repositories, | |
27 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, |
|
27 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, | |
28 | :versions, |
|
28 | :versions, | |
29 | :comments |
|
29 | :comments | |
30 |
|
30 | |||
31 | def setup |
|
31 | def setup | |
32 | ActionMailer::Base.deliveries.clear |
|
32 | ActionMailer::Base.deliveries.clear | |
33 | Setting.host_name = 'mydomain.foo' |
|
33 | Setting.host_name = 'mydomain.foo' | |
34 | Setting.protocol = 'http' |
|
34 | Setting.protocol = 'http' | |
35 | Setting.plain_text_mail = '0' |
|
35 | Setting.plain_text_mail = '0' | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_generated_links_in_emails |
|
38 | def test_generated_links_in_emails | |
39 | Setting.host_name = 'mydomain.foo' |
|
39 | Setting.host_name = 'mydomain.foo' | |
40 | Setting.protocol = 'https' |
|
40 | Setting.protocol = 'https' | |
41 |
|
41 | |||
42 | journal = Journal.find(2) |
|
42 | journal = Journal.find(2) | |
43 | assert Mailer.deliver_issue_edit(journal) |
|
43 | assert Mailer.deliver_issue_edit(journal) | |
44 |
|
44 | |||
45 | mail = ActionMailer::Base.deliveries.last |
|
45 | mail = ActionMailer::Base.deliveries.last | |
46 | assert_kind_of TMail::Mail, mail |
|
46 | assert_kind_of TMail::Mail, mail | |
47 |
|
47 | |||
48 | assert_select_email do |
|
48 | assert_select_email do | |
49 | # link to the main ticket |
|
49 | # link to the main ticket | |
50 | assert_select "a[href=?]", |
|
50 | assert_select "a[href=?]", | |
51 | "https://mydomain.foo/issues/1#change-2", |
|
51 | "https://mydomain.foo/issues/1#change-2", | |
52 | :text => "Bug #1: Can't print recipes" |
|
52 | :text => "Bug #1: Can't print recipes" | |
53 | # link to a referenced ticket |
|
53 | # link to a referenced ticket | |
54 | assert_select "a[href=?][title=?]", |
|
54 | assert_select "a[href=?][title=?]", | |
55 | "https://mydomain.foo/issues/2", |
|
55 | "https://mydomain.foo/issues/2", | |
56 | "Add ingredients categories (Assigned)", |
|
56 | "Add ingredients categories (Assigned)", | |
57 | :text => "#2" |
|
57 | :text => "#2" | |
58 | # link to a changeset |
|
58 | # link to a changeset | |
59 | assert_select "a[href=?][title=?]", |
|
59 | assert_select "a[href=?][title=?]", | |
60 | "https://mydomain.foo/projects/ecookbook/repository/revisions/2", |
|
60 | "https://mydomain.foo/projects/ecookbook/repository/revisions/2", | |
61 | "This commit fixes #1, #2 and references #1 & #3", |
|
61 | "This commit fixes #1, #2 and references #1 & #3", | |
62 | :text => "r2" |
|
62 | :text => "r2" | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_generated_links_with_prefix |
|
66 | def test_generated_links_with_prefix | |
67 | relative_url_root = Redmine::Utils.relative_url_root |
|
67 | relative_url_root = Redmine::Utils.relative_url_root | |
68 | Setting.host_name = 'mydomain.foo/rdm' |
|
68 | Setting.host_name = 'mydomain.foo/rdm' | |
69 | Setting.protocol = 'http' |
|
69 | Setting.protocol = 'http' | |
70 | Redmine::Utils.relative_url_root = '/rdm' |
|
70 | Redmine::Utils.relative_url_root = '/rdm' | |
71 |
|
71 | |||
72 | journal = Journal.find(2) |
|
72 | journal = Journal.find(2) | |
73 | assert Mailer.deliver_issue_edit(journal) |
|
73 | assert Mailer.deliver_issue_edit(journal) | |
74 |
|
74 | |||
75 | mail = ActionMailer::Base.deliveries.last |
|
75 | mail = ActionMailer::Base.deliveries.last | |
76 | assert_kind_of TMail::Mail, mail |
|
76 | assert_kind_of TMail::Mail, mail | |
77 |
|
77 | |||
78 | assert_select_email do |
|
78 | assert_select_email do | |
79 | # link to the main ticket |
|
79 | # link to the main ticket | |
80 | assert_select "a[href=?]", |
|
80 | assert_select "a[href=?]", | |
81 | "http://mydomain.foo/rdm/issues/1#change-2", |
|
81 | "http://mydomain.foo/rdm/issues/1#change-2", | |
82 | :text => "Bug #1: Can't print recipes" |
|
82 | :text => "Bug #1: Can't print recipes" | |
83 | # link to a referenced ticket |
|
83 | # link to a referenced ticket | |
84 | assert_select "a[href=?][title=?]", |
|
84 | assert_select "a[href=?][title=?]", | |
85 | "http://mydomain.foo/rdm/issues/2", |
|
85 | "http://mydomain.foo/rdm/issues/2", | |
86 | "Add ingredients categories (Assigned)", |
|
86 | "Add ingredients categories (Assigned)", | |
87 | :text => "#2" |
|
87 | :text => "#2" | |
88 | # link to a changeset |
|
88 | # link to a changeset | |
89 | assert_select "a[href=?][title=?]", |
|
89 | assert_select "a[href=?][title=?]", | |
90 | "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", |
|
90 | "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", | |
91 | "This commit fixes #1, #2 and references #1 & #3", |
|
91 | "This commit fixes #1, #2 and references #1 & #3", | |
92 | :text => "r2" |
|
92 | :text => "r2" | |
93 | end |
|
93 | end | |
94 | ensure |
|
94 | ensure | |
95 | # restore it |
|
95 | # restore it | |
96 | Redmine::Utils.relative_url_root = relative_url_root |
|
96 | Redmine::Utils.relative_url_root = relative_url_root | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
99 | def test_generated_links_with_prefix_and_no_relative_url_root | |
100 | relative_url_root = Redmine::Utils.relative_url_root |
|
100 | relative_url_root = Redmine::Utils.relative_url_root | |
101 | Setting.host_name = 'mydomain.foo/rdm' |
|
101 | Setting.host_name = 'mydomain.foo/rdm' | |
102 | Setting.protocol = 'http' |
|
102 | Setting.protocol = 'http' | |
103 | Redmine::Utils.relative_url_root = nil |
|
103 | Redmine::Utils.relative_url_root = nil | |
104 |
|
104 | |||
105 | journal = Journal.find(2) |
|
105 | journal = Journal.find(2) | |
106 | assert Mailer.deliver_issue_edit(journal) |
|
106 | assert Mailer.deliver_issue_edit(journal) | |
107 |
|
107 | |||
108 | mail = ActionMailer::Base.deliveries.last |
|
108 | mail = ActionMailer::Base.deliveries.last | |
109 | assert_kind_of TMail::Mail, mail |
|
109 | assert_kind_of TMail::Mail, mail | |
110 |
|
110 | |||
111 | assert_select_email do |
|
111 | assert_select_email do | |
112 | # link to the main ticket |
|
112 | # link to the main ticket | |
113 | assert_select "a[href=?]", |
|
113 | assert_select "a[href=?]", | |
114 | "http://mydomain.foo/rdm/issues/1#change-2", |
|
114 | "http://mydomain.foo/rdm/issues/1#change-2", | |
115 | :text => "Bug #1: Can't print recipes" |
|
115 | :text => "Bug #1: Can't print recipes" | |
116 | # link to a referenced ticket |
|
116 | # link to a referenced ticket | |
117 | assert_select "a[href=?][title=?]", |
|
117 | assert_select "a[href=?][title=?]", | |
118 | "http://mydomain.foo/rdm/issues/2", |
|
118 | "http://mydomain.foo/rdm/issues/2", | |
119 | "Add ingredients categories (Assigned)", |
|
119 | "Add ingredients categories (Assigned)", | |
120 | :text => "#2" |
|
120 | :text => "#2" | |
121 | # link to a changeset |
|
121 | # link to a changeset | |
122 | assert_select "a[href=?][title=?]", |
|
122 | assert_select "a[href=?][title=?]", | |
123 | "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", |
|
123 | "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2", | |
124 | "This commit fixes #1, #2 and references #1 & #3", |
|
124 | "This commit fixes #1, #2 and references #1 & #3", | |
125 | :text => "r2" |
|
125 | :text => "r2" | |
126 | end |
|
126 | end | |
127 | ensure |
|
127 | ensure | |
128 | # restore it |
|
128 | # restore it | |
129 | Redmine::Utils.relative_url_root = relative_url_root |
|
129 | Redmine::Utils.relative_url_root = relative_url_root | |
130 | end |
|
130 | end | |
131 |
|
131 | |||
132 | def test_email_headers |
|
132 | def test_email_headers | |
133 | issue = Issue.find(1) |
|
133 | issue = Issue.find(1) | |
134 | Mailer.deliver_issue_add(issue) |
|
134 | Mailer.deliver_issue_add(issue) | |
135 | mail = ActionMailer::Base.deliveries.last |
|
135 | mail = ActionMailer::Base.deliveries.last | |
136 | assert_not_nil mail |
|
136 | assert_not_nil mail | |
137 | assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress') |
|
137 | assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress') | |
138 | assert_equal 'auto-generated', mail.header_string('Auto-Submitted') |
|
138 | assert_equal 'auto-generated', mail.header_string('Auto-Submitted') | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_email_headers_should_include_sender |
|
141 | def test_email_headers_should_include_sender | |
142 | issue = Issue.find(1) |
|
142 | issue = Issue.find(1) | |
143 | Mailer.deliver_issue_add(issue) |
|
143 | Mailer.deliver_issue_add(issue) | |
144 | mail = ActionMailer::Base.deliveries.last |
|
144 | mail = ActionMailer::Base.deliveries.last | |
145 | assert_not_nil mail |
|
145 | assert_not_nil mail | |
146 | assert_equal issue.author.login, mail.header_string('X-Redmine-Sender') |
|
146 | assert_equal issue.author.login, mail.header_string('X-Redmine-Sender') | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def test_plain_text_mail |
|
149 | def test_plain_text_mail | |
150 | Setting.plain_text_mail = 1 |
|
150 | Setting.plain_text_mail = 1 | |
151 | journal = Journal.find(2) |
|
151 | journal = Journal.find(2) | |
152 | Mailer.deliver_issue_edit(journal) |
|
152 | Mailer.deliver_issue_edit(journal) | |
153 | mail = ActionMailer::Base.deliveries.last |
|
153 | mail = ActionMailer::Base.deliveries.last | |
154 | assert_equal "text/plain", mail.content_type |
|
154 | assert_equal "text/plain", mail.content_type | |
155 | assert_equal 0, mail.parts.size |
|
155 | assert_equal 0, mail.parts.size | |
156 | assert !mail.encoded.include?('href') |
|
156 | assert !mail.encoded.include?('href') | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def test_html_mail |
|
159 | def test_html_mail | |
160 | Setting.plain_text_mail = 0 |
|
160 | Setting.plain_text_mail = 0 | |
161 | journal = Journal.find(2) |
|
161 | journal = Journal.find(2) | |
162 | Mailer.deliver_issue_edit(journal) |
|
162 | Mailer.deliver_issue_edit(journal) | |
163 | mail = ActionMailer::Base.deliveries.last |
|
163 | mail = ActionMailer::Base.deliveries.last | |
164 | assert_equal 2, mail.parts.size |
|
164 | assert_equal 2, mail.parts.size | |
165 | assert mail.encoded.include?('href') |
|
165 | assert mail.encoded.include?('href') | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | def test_from_header |
|
168 | def test_from_header | |
169 | with_settings :mail_from => 'redmine@example.net' do |
|
169 | with_settings :mail_from => 'redmine@example.net' do | |
170 | Mailer.deliver_test(User.find(1)) |
|
170 | Mailer.deliver_test(User.find(1)) | |
171 | end |
|
171 | end | |
172 | mail = ActionMailer::Base.deliveries.last |
|
172 | mail = ActionMailer::Base.deliveries.last | |
173 | assert_not_nil mail |
|
173 | assert_not_nil mail | |
174 | assert_equal 'redmine@example.net', mail.from_addrs.first.address |
|
174 | assert_equal 'redmine@example.net', mail.from_addrs.first.address | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def test_from_header_with_phrase |
|
177 | def test_from_header_with_phrase | |
178 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do |
|
178 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do | |
179 | Mailer.deliver_test(User.find(1)) |
|
179 | Mailer.deliver_test(User.find(1)) | |
180 | end |
|
180 | end | |
181 | mail = ActionMailer::Base.deliveries.last |
|
181 | mail = ActionMailer::Base.deliveries.last | |
182 | assert_not_nil mail |
|
182 | assert_not_nil mail | |
183 | assert_equal 'redmine@example.net', mail.from_addrs.first.address |
|
183 | assert_equal 'redmine@example.net', mail.from_addrs.first.address | |
184 | assert_equal 'Redmine app', mail.from_addrs.first.name |
|
184 | assert_equal 'Redmine app', mail.from_addrs.first.name | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def test_should_not_send_email_without_recipient |
|
187 | def test_should_not_send_email_without_recipient | |
188 | news = News.find(:first) |
|
188 | news = News.find(:first) | |
189 | user = news.author |
|
189 | user = news.author | |
190 | # Remove members except news author |
|
190 | # Remove members except news author | |
191 | news.project.memberships.each {|m| m.destroy unless m.user == user} |
|
191 | news.project.memberships.each {|m| m.destroy unless m.user == user} | |
192 |
|
192 | |||
193 | user.pref[:no_self_notified] = false |
|
193 | user.pref[:no_self_notified] = false | |
194 | user.pref.save |
|
194 | user.pref.save | |
195 | User.current = user |
|
195 | User.current = user | |
196 | Mailer.deliver_news_added(news.reload) |
|
196 | Mailer.deliver_news_added(news.reload) | |
197 | assert_equal 1, last_email.bcc.size |
|
197 | assert_equal 1, last_email.bcc.size | |
198 |
|
198 | |||
199 | # nobody to notify |
|
199 | # nobody to notify | |
200 | user.pref[:no_self_notified] = true |
|
200 | user.pref[:no_self_notified] = true | |
201 | user.pref.save |
|
201 | user.pref.save | |
202 | User.current = user |
|
202 | User.current = user | |
203 | ActionMailer::Base.deliveries.clear |
|
203 | ActionMailer::Base.deliveries.clear | |
204 | Mailer.deliver_news_added(news.reload) |
|
204 | Mailer.deliver_news_added(news.reload) | |
205 | assert ActionMailer::Base.deliveries.empty? |
|
205 | assert ActionMailer::Base.deliveries.empty? | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def test_issue_add_message_id |
|
208 | def test_issue_add_message_id | |
209 | issue = Issue.find(1) |
|
209 | issue = Issue.find(1) | |
210 | Mailer.deliver_issue_add(issue) |
|
210 | Mailer.deliver_issue_add(issue) | |
211 | mail = ActionMailer::Base.deliveries.last |
|
211 | mail = ActionMailer::Base.deliveries.last | |
212 | assert_not_nil mail |
|
212 | assert_not_nil mail | |
213 | assert_equal Mailer.message_id_for(issue), mail.message_id |
|
213 | assert_equal Mailer.message_id_for(issue), mail.message_id | |
214 | assert_nil mail.references |
|
214 | assert_nil mail.references | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | def test_issue_edit_message_id |
|
217 | def test_issue_edit_message_id | |
218 | journal = Journal.find(1) |
|
218 | journal = Journal.find(1) | |
219 | Mailer.deliver_issue_edit(journal) |
|
219 | Mailer.deliver_issue_edit(journal) | |
220 | mail = ActionMailer::Base.deliveries.last |
|
220 | mail = ActionMailer::Base.deliveries.last | |
221 | assert_not_nil mail |
|
221 | assert_not_nil mail | |
222 | assert_equal Mailer.message_id_for(journal), mail.message_id |
|
222 | assert_equal Mailer.message_id_for(journal), mail.message_id | |
223 | assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s |
|
223 | assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s | |
224 | assert_select_email do |
|
224 | assert_select_email do | |
225 | # link to the update |
|
225 | # link to the update | |
226 | assert_select "a[href=?]", |
|
226 | assert_select "a[href=?]", | |
227 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" |
|
227 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" | |
228 | end |
|
228 | end | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | def test_message_posted_message_id |
|
231 | def test_message_posted_message_id | |
232 | message = Message.find(1) |
|
232 | message = Message.find(1) | |
233 | Mailer.deliver_message_posted(message) |
|
233 | Mailer.deliver_message_posted(message) | |
234 | mail = ActionMailer::Base.deliveries.last |
|
234 | mail = ActionMailer::Base.deliveries.last | |
235 | assert_not_nil mail |
|
235 | assert_not_nil mail | |
236 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
236 | assert_equal Mailer.message_id_for(message), mail.message_id | |
237 | assert_nil mail.references |
|
237 | assert_nil mail.references | |
238 | assert_select_email do |
|
238 | assert_select_email do | |
239 | # link to the message |
|
239 | # link to the message | |
240 | assert_select "a[href=?]", |
|
240 | assert_select "a[href=?]", | |
241 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", |
|
241 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", | |
242 | :text => message.subject |
|
242 | :text => message.subject | |
243 | end |
|
243 | end | |
244 | end |
|
244 | end | |
245 |
|
245 | |||
246 | def test_reply_posted_message_id |
|
246 | def test_reply_posted_message_id | |
247 | message = Message.find(3) |
|
247 | message = Message.find(3) | |
248 | Mailer.deliver_message_posted(message) |
|
248 | Mailer.deliver_message_posted(message) | |
249 | mail = ActionMailer::Base.deliveries.last |
|
249 | mail = ActionMailer::Base.deliveries.last | |
250 | assert_not_nil mail |
|
250 | assert_not_nil mail | |
251 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
251 | assert_equal Mailer.message_id_for(message), mail.message_id | |
252 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s |
|
252 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s | |
253 | assert_select_email do |
|
253 | assert_select_email do | |
254 | # link to the reply |
|
254 | # link to the reply | |
255 | assert_select "a[href=?]", |
|
255 | assert_select "a[href=?]", | |
256 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
|
256 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", | |
257 | :text => message.subject |
|
257 | :text => message.subject | |
258 | end |
|
258 | end | |
259 | end |
|
259 | end | |
260 |
|
260 | |||
261 | context("#issue_add") do |
|
261 | context("#issue_add") do | |
262 | setup do |
|
262 | setup do | |
263 | ActionMailer::Base.deliveries.clear |
|
263 | ActionMailer::Base.deliveries.clear | |
264 | Setting.bcc_recipients = '1' |
|
264 | Setting.bcc_recipients = '1' | |
265 | @issue = Issue.find(1) |
|
265 | @issue = Issue.find(1) | |
266 | end |
|
266 | end | |
267 |
|
267 | |||
268 | should "notify project members" do |
|
268 | should "notify project members" do | |
269 | assert Mailer.deliver_issue_add(@issue) |
|
269 | assert Mailer.deliver_issue_add(@issue) | |
270 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
270 | assert last_email.bcc.include?('dlopper@somenet.foo') | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | should "not notify project members that are not allow to view the issue" do |
|
273 | should "not notify project members that are not allow to view the issue" do | |
274 | Role.find(2).remove_permission!(:view_issues) |
|
274 | Role.find(2).remove_permission!(:view_issues) | |
275 | assert Mailer.deliver_issue_add(@issue) |
|
275 | assert Mailer.deliver_issue_add(@issue) | |
276 | assert !last_email.bcc.include?('dlopper@somenet.foo') |
|
276 | assert !last_email.bcc.include?('dlopper@somenet.foo') | |
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | should "notify issue watchers" do |
|
279 | should "notify issue watchers" do | |
280 | user = User.find(9) |
|
280 | user = User.find(9) | |
281 | # minimal email notification options |
|
281 | # minimal email notification options | |
282 | user.pref[:no_self_notified] = '1' |
|
282 | user.pref[:no_self_notified] = '1' | |
283 | user.pref.save |
|
283 | user.pref.save | |
284 | user.mail_notification = false |
|
284 | user.mail_notification = false | |
285 | user.save |
|
285 | user.save | |
286 |
|
286 | |||
287 | Watcher.create!(:watchable => @issue, :user => user) |
|
287 | Watcher.create!(:watchable => @issue, :user => user) | |
288 | assert Mailer.deliver_issue_add(@issue) |
|
288 | assert Mailer.deliver_issue_add(@issue) | |
289 | assert last_email.bcc.include?(user.mail) |
|
289 | assert last_email.bcc.include?(user.mail) | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | should "not notify watchers not allowed to view the issue" do |
|
292 | should "not notify watchers not allowed to view the issue" do | |
293 | user = User.find(9) |
|
293 | user = User.find(9) | |
294 | Watcher.create!(:watchable => @issue, :user => user) |
|
294 | Watcher.create!(:watchable => @issue, :user => user) | |
295 | Role.non_member.remove_permission!(:view_issues) |
|
295 | Role.non_member.remove_permission!(:view_issues) | |
296 | assert Mailer.deliver_issue_add(@issue) |
|
296 | assert Mailer.deliver_issue_add(@issue) | |
297 | assert !last_email.bcc.include?(user.mail) |
|
297 | assert !last_email.bcc.include?(user.mail) | |
298 | end |
|
298 | end | |
299 | end |
|
299 | end | |
300 |
|
300 | |||
301 | # test mailer methods for each language |
|
301 | # test mailer methods for each language | |
302 | def test_issue_add |
|
302 | def test_issue_add | |
303 | issue = Issue.find(1) |
|
303 | issue = Issue.find(1) | |
304 | valid_languages.each do |lang| |
|
304 | valid_languages.each do |lang| | |
305 | Setting.default_language = lang.to_s |
|
305 | Setting.default_language = lang.to_s | |
306 | assert Mailer.deliver_issue_add(issue) |
|
306 | assert Mailer.deliver_issue_add(issue) | |
307 | end |
|
307 | end | |
308 | end |
|
308 | end | |
309 |
|
309 | |||
310 | def test_issue_edit |
|
310 | def test_issue_edit | |
311 | journal = Journal.find(1) |
|
311 | journal = Journal.find(1) | |
312 | valid_languages.each do |lang| |
|
312 | valid_languages.each do |lang| | |
313 | Setting.default_language = lang.to_s |
|
313 | Setting.default_language = lang.to_s | |
314 | assert Mailer.deliver_issue_edit(journal) |
|
314 | assert Mailer.deliver_issue_edit(journal) | |
315 | end |
|
315 | end | |
316 | end |
|
316 | end | |
317 |
|
317 | |||
318 | def test_document_added |
|
318 | def test_document_added | |
319 | document = Document.find(1) |
|
319 | document = Document.find(1) | |
320 | valid_languages.each do |lang| |
|
320 | valid_languages.each do |lang| | |
321 | Setting.default_language = lang.to_s |
|
321 | Setting.default_language = lang.to_s | |
322 | assert Mailer.deliver_document_added(document) |
|
322 | assert Mailer.deliver_document_added(document) | |
323 | end |
|
323 | end | |
324 | end |
|
324 | end | |
325 |
|
325 | |||
326 | def test_attachments_added |
|
326 | def test_attachments_added | |
327 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
327 | attachements = [ Attachment.find_by_container_type('Document') ] | |
328 | valid_languages.each do |lang| |
|
328 | valid_languages.each do |lang| | |
329 | Setting.default_language = lang.to_s |
|
329 | Setting.default_language = lang.to_s | |
330 | assert Mailer.deliver_attachments_added(attachements) |
|
330 | assert Mailer.deliver_attachments_added(attachements) | |
331 | end |
|
331 | end | |
332 | end |
|
332 | end | |
333 |
|
333 | |||
334 | def test_version_file_added |
|
334 | def test_version_file_added | |
335 | attachements = [ Attachment.find_by_container_type('Version') ] |
|
335 | attachements = [ Attachment.find_by_container_type('Version') ] | |
336 | assert Mailer.deliver_attachments_added(attachements) |
|
336 | assert Mailer.deliver_attachments_added(attachements) | |
337 | assert_not_nil last_email.bcc |
|
337 | assert_not_nil last_email.bcc | |
338 | assert last_email.bcc.any? |
|
338 | assert last_email.bcc.any? | |
339 | assert_select_email do |
|
339 | assert_select_email do | |
340 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
340 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | |
341 | end |
|
341 | end | |
342 | end |
|
342 | end | |
343 |
|
343 | |||
344 | def test_project_file_added |
|
344 | def test_project_file_added | |
345 | attachements = [ Attachment.find_by_container_type('Project') ] |
|
345 | attachements = [ Attachment.find_by_container_type('Project') ] | |
346 | assert Mailer.deliver_attachments_added(attachements) |
|
346 | assert Mailer.deliver_attachments_added(attachements) | |
347 | assert_not_nil last_email.bcc |
|
347 | assert_not_nil last_email.bcc | |
348 | assert last_email.bcc.any? |
|
348 | assert last_email.bcc.any? | |
349 | assert_select_email do |
|
349 | assert_select_email do | |
350 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
350 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | |
351 | end |
|
351 | end | |
352 | end |
|
352 | end | |
353 |
|
353 | |||
354 | def test_news_added |
|
354 | def test_news_added | |
355 | news = News.find(:first) |
|
355 | news = News.find(:first) | |
356 | valid_languages.each do |lang| |
|
356 | valid_languages.each do |lang| | |
357 | Setting.default_language = lang.to_s |
|
357 | Setting.default_language = lang.to_s | |
358 | assert Mailer.deliver_news_added(news) |
|
358 | assert Mailer.deliver_news_added(news) | |
359 | end |
|
359 | end | |
360 | end |
|
360 | end | |
361 |
|
361 | |||
362 | def test_news_comment_added |
|
362 | def test_news_comment_added | |
363 | comment = Comment.find(2) |
|
363 | comment = Comment.find(2) | |
364 | valid_languages.each do |lang| |
|
364 | valid_languages.each do |lang| | |
365 | Setting.default_language = lang.to_s |
|
365 | Setting.default_language = lang.to_s | |
366 | assert Mailer.deliver_news_comment_added(comment) |
|
366 | assert Mailer.deliver_news_comment_added(comment) | |
367 | end |
|
367 | end | |
368 | end |
|
368 | end | |
369 |
|
369 | |||
370 | def test_message_posted |
|
370 | def test_message_posted | |
371 | message = Message.find(:first) |
|
371 | message = Message.find(:first) | |
372 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
372 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} | |
373 | recipients = recipients.compact.uniq |
|
373 | recipients = recipients.compact.uniq | |
374 | valid_languages.each do |lang| |
|
374 | valid_languages.each do |lang| | |
375 | Setting.default_language = lang.to_s |
|
375 | Setting.default_language = lang.to_s | |
376 | assert Mailer.deliver_message_posted(message) |
|
376 | assert Mailer.deliver_message_posted(message) | |
377 | end |
|
377 | end | |
378 | end |
|
378 | end | |
379 |
|
379 | |||
380 | def test_wiki_content_added |
|
380 | def test_wiki_content_added | |
381 | content = WikiContent.find(:first) |
|
381 | content = WikiContent.find(:first) | |
382 | valid_languages.each do |lang| |
|
382 | valid_languages.each do |lang| | |
383 | Setting.default_language = lang.to_s |
|
383 | Setting.default_language = lang.to_s | |
384 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
384 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
385 | assert Mailer.deliver_wiki_content_added(content) |
|
385 | assert Mailer.deliver_wiki_content_added(content) | |
386 | end |
|
386 | end | |
387 | end |
|
387 | end | |
388 | end |
|
388 | end | |
389 |
|
389 | |||
390 | def test_wiki_content_updated |
|
390 | def test_wiki_content_updated | |
391 | content = WikiContent.find(:first) |
|
391 | content = WikiContent.find(:first) | |
392 | valid_languages.each do |lang| |
|
392 | valid_languages.each do |lang| | |
393 | Setting.default_language = lang.to_s |
|
393 | Setting.default_language = lang.to_s | |
394 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
394 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
395 | assert Mailer.deliver_wiki_content_updated(content) |
|
395 | assert Mailer.deliver_wiki_content_updated(content) | |
396 | end |
|
396 | end | |
397 | end |
|
397 | end | |
398 | end |
|
398 | end | |
399 |
|
399 | |||
400 | def test_account_information |
|
400 | def test_account_information | |
401 | user = User.find(2) |
|
401 | user = User.find(2) | |
402 | valid_languages.each do |lang| |
|
402 | valid_languages.each do |lang| | |
403 | user.update_attribute :language, lang.to_s |
|
403 | user.update_attribute :language, lang.to_s | |
404 | user.reload |
|
404 | user.reload | |
405 | assert Mailer.deliver_account_information(user, 'pAsswORd') |
|
405 | assert Mailer.deliver_account_information(user, 'pAsswORd') | |
406 | end |
|
406 | end | |
407 | end |
|
407 | end | |
408 |
|
408 | |||
409 | def test_lost_password |
|
409 | def test_lost_password | |
410 | token = Token.find(2) |
|
410 | token = Token.find(2) | |
411 | valid_languages.each do |lang| |
|
411 | valid_languages.each do |lang| | |
412 | token.user.update_attribute :language, lang.to_s |
|
412 | token.user.update_attribute :language, lang.to_s | |
413 | token.reload |
|
413 | token.reload | |
414 | assert Mailer.deliver_lost_password(token) |
|
414 | assert Mailer.deliver_lost_password(token) | |
415 | end |
|
415 | end | |
416 | end |
|
416 | end | |
417 |
|
417 | |||
418 | def test_register |
|
418 | def test_register | |
419 | token = Token.find(1) |
|
419 | token = Token.find(1) | |
420 | Setting.host_name = 'redmine.foo' |
|
420 | Setting.host_name = 'redmine.foo' | |
421 | Setting.protocol = 'https' |
|
421 | Setting.protocol = 'https' | |
422 |
|
422 | |||
423 | valid_languages.each do |lang| |
|
423 | valid_languages.each do |lang| | |
424 | token.user.update_attribute :language, lang.to_s |
|
424 | token.user.update_attribute :language, lang.to_s | |
425 | token.reload |
|
425 | token.reload | |
426 | ActionMailer::Base.deliveries.clear |
|
426 | ActionMailer::Base.deliveries.clear | |
427 | assert Mailer.deliver_register(token) |
|
427 | assert Mailer.deliver_register(token) | |
428 | mail = ActionMailer::Base.deliveries.last |
|
428 | mail = ActionMailer::Base.deliveries.last | |
429 | assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}") |
|
429 | assert_select_email do | |
|
430 | assert_select "a[href=?]", | |||
|
431 | "https://redmine.foo/account/activate?token=#{token.value}", | |||
|
432 | :text => "https://redmine.foo/account/activate?token=#{token.value}" | |||
|
433 | end | |||
430 | end |
|
434 | end | |
431 | end |
|
435 | end | |
432 |
|
436 | |||
433 | def test_test |
|
437 | def test_test | |
434 | user = User.find(1) |
|
438 | user = User.find(1) | |
435 | valid_languages.each do |lang| |
|
439 | valid_languages.each do |lang| | |
436 | user.update_attribute :language, lang.to_s |
|
440 | user.update_attribute :language, lang.to_s | |
437 | assert Mailer.deliver_test(user) |
|
441 | assert Mailer.deliver_test(user) | |
438 | end |
|
442 | end | |
439 | end |
|
443 | end | |
440 |
|
444 | |||
441 | def test_reminders |
|
445 | def test_reminders | |
442 | Mailer.reminders(:days => 42) |
|
446 | Mailer.reminders(:days => 42) | |
443 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
447 | assert_equal 1, ActionMailer::Base.deliveries.size | |
444 | mail = ActionMailer::Base.deliveries.last |
|
448 | mail = ActionMailer::Base.deliveries.last | |
445 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
449 | assert mail.bcc.include?('dlopper@somenet.foo') | |
446 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
450 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | |
447 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
451 | assert_equal '1 issue(s) due in the next 42 days', mail.subject | |
448 | end |
|
452 | end | |
449 |
|
453 | |||
450 | def test_reminders_should_not_include_closed_issues |
|
454 | def test_reminders_should_not_include_closed_issues | |
451 | Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 5, :subject => 'Closed issue', :assigned_to_id => 3, :due_date => 5.days.from_now) |
|
455 | Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 5, :subject => 'Closed issue', :assigned_to_id => 3, :due_date => 5.days.from_now) | |
452 | ActionMailer::Base.deliveries.clear |
|
456 | ActionMailer::Base.deliveries.clear | |
453 |
|
457 | |||
454 | Mailer.reminders(:days => 42) |
|
458 | Mailer.reminders(:days => 42) | |
455 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
459 | assert_equal 1, ActionMailer::Base.deliveries.size | |
456 | mail = ActionMailer::Base.deliveries.last |
|
460 | mail = ActionMailer::Base.deliveries.last | |
457 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
461 | assert mail.bcc.include?('dlopper@somenet.foo') | |
458 | assert !mail.body.include?('Closed issue') |
|
462 | assert !mail.body.include?('Closed issue') | |
459 | end |
|
463 | end | |
460 |
|
464 | |||
461 | def test_reminders_for_users |
|
465 | def test_reminders_for_users | |
462 | Mailer.reminders(:days => 42, :users => ['5']) |
|
466 | Mailer.reminders(:days => 42, :users => ['5']) | |
463 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
467 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper | |
464 | Mailer.reminders(:days => 42, :users => ['3']) |
|
468 | Mailer.reminders(:days => 42, :users => ['3']) | |
465 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
469 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper | |
466 | mail = ActionMailer::Base.deliveries.last |
|
470 | mail = ActionMailer::Base.deliveries.last | |
467 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
471 | assert mail.bcc.include?('dlopper@somenet.foo') | |
468 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
472 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | |
469 | end |
|
473 | end | |
470 |
|
474 | |||
471 | def last_email |
|
475 | def last_email | |
472 | mail = ActionMailer::Base.deliveries.last |
|
476 | mail = ActionMailer::Base.deliveries.last | |
473 | assert_not_nil mail |
|
477 | assert_not_nil mail | |
474 |
|
478 | |||
475 | end |
|
479 | end | |
476 |
|
480 | |||
477 | def test_mailer_should_not_change_locale |
|
481 | def test_mailer_should_not_change_locale | |
478 | Setting.default_language = 'en' |
|
482 | Setting.default_language = 'en' | |
479 | # Set current language to italian |
|
483 | # Set current language to italian | |
480 | set_language_if_valid 'it' |
|
484 | set_language_if_valid 'it' | |
481 | # Send an email to a french user |
|
485 | # Send an email to a french user | |
482 | user = User.find(1) |
|
486 | user = User.find(1) | |
483 | user.language = 'fr' |
|
487 | user.language = 'fr' | |
484 | Mailer.deliver_account_activated(user) |
|
488 | Mailer.deliver_account_activated(user) | |
485 | mail = ActionMailer::Base.deliveries.last |
|
489 | mail = ActionMailer::Base.deliveries.last | |
486 | assert mail.body.include?('Votre compte') |
|
490 | assert mail.body.include?('Votre compte') | |
487 |
|
491 | |||
488 | assert_equal :it, current_language |
|
492 | assert_equal :it, current_language | |
489 | end |
|
493 | end | |
490 |
|
494 | |||
491 | def test_with_deliveries_off |
|
495 | def test_with_deliveries_off | |
492 | Mailer.with_deliveries false do |
|
496 | Mailer.with_deliveries false do | |
493 | Mailer.deliver_test(User.find(1)) |
|
497 | Mailer.deliver_test(User.find(1)) | |
494 | end |
|
498 | end | |
495 | assert ActionMailer::Base.deliveries.empty? |
|
499 | assert ActionMailer::Base.deliveries.empty? | |
496 | # should restore perform_deliveries |
|
500 | # should restore perform_deliveries | |
497 | assert ActionMailer::Base.perform_deliveries |
|
501 | assert ActionMailer::Base.perform_deliveries | |
498 | end |
|
502 | end | |
499 |
|
503 | |||
500 | def test_tmail_to_header_field_should_not_include_blank_lines |
|
504 | def test_tmail_to_header_field_should_not_include_blank_lines | |
501 | mail = TMail::Mail.new |
|
505 | mail = TMail::Mail.new | |
502 | mail.to = ["a.user@example.com", "v.user2@example.com", "e.smith@example.com", "info@example.com", "v.pupkin@example.com", |
|
506 | mail.to = ["a.user@example.com", "v.user2@example.com", "e.smith@example.com", "info@example.com", "v.pupkin@example.com", | |
503 | "b.user@example.com", "w.user2@example.com", "f.smith@example.com", "info2@example.com", "w.pupkin@example.com"] |
|
507 | "b.user@example.com", "w.user2@example.com", "f.smith@example.com", "info2@example.com", "w.pupkin@example.com"] | |
504 |
|
508 | |||
505 | assert !mail.encoded.strip.split("\r\n").detect(&:blank?), "#{mail.encoded} malformed" |
|
509 | assert !mail.encoded.strip.split("\r\n").detect(&:blank?), "#{mail.encoded} malformed" | |
506 | end |
|
510 | end | |
507 |
|
511 | |||
508 | def test_layout_should_include_the_emails_header |
|
512 | def test_layout_should_include_the_emails_header | |
509 | with_settings :emails_header => "*Header content*" do |
|
513 | with_settings :emails_header => "*Header content*" do | |
510 | assert Mailer.deliver_test(User.find(1)) |
|
514 | assert Mailer.deliver_test(User.find(1)) | |
511 | assert_select_email do |
|
515 | assert_select_email do | |
512 | assert_select ".header" do |
|
516 | assert_select ".header" do | |
513 | assert_select "strong", :text => "Header content" |
|
517 | assert_select "strong", :text => "Header content" | |
514 | end |
|
518 | end | |
515 | end |
|
519 | end | |
516 | end |
|
520 | end | |
517 | end |
|
521 | end | |
518 | end |
|
522 | end |
General Comments 0
You need to be logged in to leave comments.
Login now