mimemail.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $permissions = array(
  62. 'access administration pages',
  63. 'administer site configuration',
  64. );
  65. // Check to make sure that the array of permissions are valid.
  66. $this->checkPermissions($permissions, TRUE);
  67. // Create and login user.
  68. $this->adminUser = $this->drupalCreateUser($permissions);
  69. $this->drupalLogin($this->adminUser);
  70. }
  71. public function testUrl() {
  72. $this->drupalPost('admin/config/system/mimemail',
  73. array('mimemail_linkonly' => TRUE),
  74. t('Save configuration'));
  75. $url = 'public://' . $this->randomName() . ' ' . $this->randomName() . '.jpg';
  76. $result = _mimemail_url($url, TRUE);
  77. $expected = str_replace(' ', '%20', file_create_url($url));
  78. $message = 'Stream wrapper converted to web accessible URL for linked image.';
  79. $this->assertIdentical($result, $expected, $message);
  80. }
  81. }