You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mailer_localisation_test.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class MailerLocalisationTest < ActiveSupport::TestCase
  20. include Redmine::I18n
  21. include Rails::Dom::Testing::Assertions
  22. fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :user_preferences, :members,
  23. :member_roles, :roles, :documents, :attachments, :news,
  24. :tokens, :journals, :journal_details, :changesets,
  25. :trackers, :projects_trackers,
  26. :issue_statuses, :enumerations, :messages, :boards, :repositories,
  27. :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
  28. :versions,
  29. :comments
  30. def setup
  31. ActionMailer::Base.deliveries.clear
  32. Setting.plain_text_mail = '0'
  33. Setting.default_language = 'en'
  34. User.current = nil
  35. end
  36. # test mailer methods for each language
  37. def test_issue_add
  38. issue = Issue.find(1)
  39. with_each_user_language do |user|
  40. assert Mailer.issue_add(user, issue).deliver_now
  41. end
  42. end
  43. def test_issue_edit
  44. journal = Journal.find(1)
  45. with_each_user_language do |user|
  46. assert Mailer.issue_edit(user, journal).deliver_now
  47. end
  48. end
  49. def test_document_added
  50. document = Document.find(1)
  51. author = User.find(2)
  52. with_each_user_language do |user|
  53. assert Mailer.document_added(user, document, author).deliver_now
  54. end
  55. end
  56. def test_attachments_added
  57. attachements = [ Attachment.find_by_container_type('Document') ]
  58. with_each_user_language do |user|
  59. assert Mailer.attachments_added(user, attachements).deliver_now
  60. end
  61. end
  62. def test_news_added
  63. news = News.first
  64. with_each_user_language do |user|
  65. assert Mailer.news_added(user, news).deliver_now
  66. end
  67. end
  68. def test_news_comment_added
  69. comment = Comment.find(2)
  70. with_each_user_language do |user|
  71. assert Mailer.news_comment_added(user, comment).deliver_now
  72. end
  73. end
  74. def test_message_posted
  75. message = Message.first
  76. with_each_user_language do |user|
  77. assert Mailer.message_posted(user, message).deliver_now
  78. end
  79. end
  80. def test_wiki_content_added
  81. content = WikiContent.find(1)
  82. with_each_user_language do |user|
  83. assert Mailer.wiki_content_added(user, content).deliver_now
  84. end
  85. end
  86. def test_wiki_content_updated
  87. content = WikiContent.find(1)
  88. with_each_user_language do |user|
  89. assert Mailer.wiki_content_updated(user, content).deliver_now
  90. end
  91. end
  92. def test_account_information
  93. with_each_user_language do |user|
  94. assert Mailer.account_information(user, 'pAsswORd').deliver_now
  95. end
  96. end
  97. def test_lost_password
  98. token = Token.find(2)
  99. with_each_user_language do |user|
  100. assert Mailer.lost_password(user, token).deliver_now
  101. end
  102. end
  103. def test_register
  104. token = Token.find(1)
  105. with_each_user_language do |user|
  106. assert Mailer.register(user, token).deliver_now
  107. end
  108. end
  109. def test_test_email
  110. with_each_user_language do |user|
  111. assert Mailer.test_email(user).deliver_now
  112. end
  113. end
  114. private
  115. def with_each_user_language(&block)
  116. user = User.find(2)
  117. valid_languages.each do |lang|
  118. user.update_attribute :language, lang
  119. yield user
  120. end
  121. end
  122. end