mimemail.test 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @file
  4. * Functionality tests for the Mime Mail module.
  5. *
  6. * @ingroup mimemail
  7. */
  8. require_once(dirname(__FILE__) . '/../mimemail.inc');
  9. /**
  10. * Tests helper functions from the Mime Mail module.
  11. */
  12. class MimeMailUnitTestCase extends DrupalUnitTestCase {
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Mime Mail unit tests',
  16. 'description' => 'Test that Mime Mail helper functions work properly.',
  17. 'group' => 'Mime Mail',
  18. );
  19. }
  20. function setUp() {
  21. drupal_load('module', 'mimemail');
  22. parent::setUp();
  23. }
  24. function testHeaders() {
  25. // Test the regular expression for extracting the mail address.
  26. $chars = array('-', '.', '+', '_');
  27. $name = $this->randomString();
  28. $local = $this->randomName() . $chars[array_rand($chars)] . $this->randomName();
  29. $domain = $this->randomName() . '-' . $this->randomName() . '.' . $this->randomName(rand(2,4));
  30. $headers = mimemail_headers(array(), "$name <$local@$domain>");
  31. $result = $headers['Return-Path'];
  32. $expected = "<$local@$domain>";
  33. $this->assertIdentical($result, $expected, 'Return-Path header field correctly set.');
  34. }
  35. function testUrl() {
  36. $result = _mimemail_url('#');
  37. $this->assertIdentical($result, '#', 'Hash mark URL without fragment left intact.');
  38. $url = '/sites/default/files/styles/thumbnail/public/image.jpg?itok=Wrl6Qi9U';
  39. $result = _mimemail_url($url, TRUE);
  40. $expected = 'sites/default/files/styles/thumbnail/public/image.jpg';
  41. $this->assertIdentical($result, $expected, 'Security token removed from styled image URL.');
  42. $expected = $url = 'public://' . $this->randomName() . ' '. $this->randomName() . '.' . $this->randomName(3);
  43. $result = _mimemail_url($url, TRUE);
  44. $this->assertIdentical($result, $expected, 'Space in the filename of the attachment left intact.');
  45. }
  46. }
  47. /**
  48. * Tests functions from the Mime Mail module.
  49. */
  50. class MimeMailWebTestCase extends DrupalWebTestCase {
  51. protected $adminUser;
  52. public static function getInfo() {
  53. return array(
  54. 'name' => 'Mime Mail web tests',
  55. 'description' => 'Test that Mime Mail works properly.',
  56. 'group' => 'Mime Mail',
  57. );
  58. }
  59. public function setUp() {
  60. parent::setUp('mailsystem', 'mimemail');
  61. // Create and login user.
  62. $this->adminUser = $this->drupalCreateUser(array(
  63. 'access administration pages',
  64. 'administer site configuration',
  65. ));
  66. $this->drupalLogin($this->adminUser);
  67. }
  68. public function testUrl() {
  69. $this->drupalPost('admin/config/system/mimemail',
  70. array('mimemail_linkonly' => TRUE),
  71. t('Save configuration'));
  72. $url = 'public://' . $this->randomName() . ' '. $this->randomName() . '.jpg';
  73. $result = _mimemail_url($url, TRUE);
  74. $expected = str_replace(' ', '%20', file_create_url($url));
  75. $message = 'Stream wrapper converted to web accessible URL for linked image.';
  76. $this->assertIdentical($result, $expected, $message);
  77. }
  78. }