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 4.0KB

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