Révision 01dfd3b5
Ajouté par Assos Assos il y a plus de 3 ans
drupal7/modules/simpletest/tests/mail.test | ||
---|---|---|
59 | 59 |
$this->assertNull(self::$sent_message, 'Message was canceled.'); |
60 | 60 |
} |
61 | 61 |
|
62 |
/** |
|
63 |
* Checks for the site name in an auto-generated From: header. |
|
64 |
*/ |
|
65 |
function testFromHeader() { |
|
66 |
global $language; |
|
67 |
$default_from = variable_get('site_mail', ini_get('sendmail_from')); |
|
68 |
$site_name = variable_get('site_name', 'Drupal'); |
|
69 |
|
|
70 |
// Reset the class variable holding a copy of the last sent message. |
|
71 |
self::$sent_message = NULL; |
|
72 |
// Send an e-mail with a sender address specified. |
|
73 |
$from_email = 'someone_else@example.com'; |
|
74 |
$message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language, array(), $from_email); |
|
75 |
// Test that the from e-mail is just the e-mail and not the site name and |
|
76 |
// default sender e-mail. |
|
77 |
$this->assertEqual($from_email, self::$sent_message['headers']['From']); |
|
78 |
|
|
79 |
// Check default behavior is only email in FROM header. |
|
80 |
self::$sent_message = NULL; |
|
81 |
// Send an e-mail and check that the From-header contains only default mail address. |
|
82 |
variable_del('mail_display_name_site_name'); |
|
83 |
$message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language); |
|
84 |
$this->assertEqual($default_from, self::$sent_message['headers']['From']); |
|
85 |
|
|
86 |
self::$sent_message = NULL; |
|
87 |
// Send an e-mail and check that the From-header contains the site name. |
|
88 |
variable_set('mail_display_name_site_name', TRUE); |
|
89 |
$message = drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language); |
|
90 |
$this->assertEqual($site_name . ' <' . $default_from . '>', self::$sent_message['headers']['From']); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Checks for the site name in an auto-generated From: header. |
|
95 |
*/ |
|
96 |
function testFromHeaderRfc2822Compliant() { |
|
97 |
global $language; |
|
98 |
$default_from = variable_get('site_mail', ini_get('sendmail_from')); |
|
99 |
|
|
100 |
// Enable adding a site name to From. |
|
101 |
variable_set('mail_display_name_site_name', TRUE); |
|
102 |
|
|
103 |
$site_names = array( |
|
104 |
// Simple ASCII characters. |
|
105 |
'Test site' => 'Test site', |
|
106 |
// ASCII with html entity. |
|
107 |
'Test & site' => 'Test & site', |
|
108 |
// Non-ASCII characters. |
|
109 |
'Tést site' => '=?UTF-8?B?VMOpc3Qgc2l0ZQ==?=', |
|
110 |
// Non-ASCII with special characters. |
|
111 |
'Tést; site' => '=?UTF-8?B?VMOpc3Q7IHNpdGU=?=', |
|
112 |
// Non-ASCII with html entity. |
|
113 |
'Tést; site' => '=?UTF-8?B?VMOpc3Q7IHNpdGU=?=', |
|
114 |
// ASCII with special characters. |
|
115 |
'Test; site' => '"Test; site"', |
|
116 |
// ASCII with special characters as html entity. |
|
117 |
'Test < site' => '"Test < site"', |
|
118 |
// ASCII with special characters and '\'. |
|
119 |
'Test; \ "site"' => '"Test; \\\\ \"site\""', |
|
120 |
// String already RFC-2822 compliant. |
|
121 |
'"Test; site"' => '"Test; site"', |
|
122 |
// String already RFC-2822 compliant. |
|
123 |
'"Test; \\\\ \"site\""' => '"Test; \\\\ \"site\""', |
|
124 |
); |
|
125 |
|
|
126 |
foreach ($site_names as $original_name => $safe_string) { |
|
127 |
variable_set('site_name', $original_name); |
|
128 |
|
|
129 |
// Reset the class variable holding a copy of the last sent message. |
|
130 |
self::$sent_message = NULL; |
|
131 |
// Send an e-mail and check that the From-header contains is RFC-2822 compliant. |
|
132 |
drupal_mail('simpletest', 'from_test', 'from_test@example.com', $language); |
|
133 |
$this->assertEqual($safe_string . ' <' . $default_from . '>', self::$sent_message['headers']['From']); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
62 | 137 |
/** |
63 | 138 |
* Concatenate and wrap the e-mail body for plain-text mails. |
64 | 139 |
* |
Formats disponibles : Unified diff
Udpate to 7.77