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