wp-mail-real-test.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * wp-mail-real-test.php
  4. *
  5. * Test script for wp_mail with real addresses.
  6. */
  7. // parse options
  8. $options = 'v:r:d';
  9. if (is_callable('getopt')) {
  10. $opts = getopt($options);
  11. } else {
  12. include( dirname(__FILE__) . '/wp-testlib/getopt.php' );
  13. $opts = getoptParser::getopt($options);
  14. }
  15. define('DIR_TESTROOT', realpath(dirname(__FILE__)));
  16. define('TEST_WP', true);
  17. define('WP_DEBUG', array_key_exists('d', $opts) );
  18. if (!empty($opts['r']))
  19. define('DIR_WP', realpath($opts['r']));
  20. else
  21. if (!empty($opts['v']))
  22. define('DIR_WP', DIR_TESTROOT.'/wordpress-'.$opts['v']);
  23. else
  24. define('DIR_WP', DIR_TESTROOT.'/wordpress');
  25. // make sure all useful errors are displayed during setup
  26. error_reporting(E_ALL & ~E_DEPRECATED);
  27. ini_set('display_errors', true);
  28. require_once(DIR_TESTROOT.'/wp-testlib/utils.php');
  29. // configure wp
  30. require_once(DIR_TESTROOT.'/wp-config.php');
  31. define('ABSPATH', realpath(DIR_WP).'/');
  32. // install wp
  33. define('WP_BLOG_TITLE', rand_str());
  34. define('WP_USER_NAME', rand_str());
  35. define('WP_USER_EMAIL', rand_str().'@example.com');
  36. // initialize wp
  37. define('WP_INSTALLING', 1);
  38. $_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME']; // prevent a warning from some sloppy code in wp-settings.php
  39. require_once(ABSPATH.'wp-settings.php');
  40. drop_tables();
  41. require_once(ABSPATH.'wp-admin/includes/upgrade.php');
  42. wp_install(WP_BLOG_TITLE, WP_USER_NAME, WP_USER_EMAIL, true);
  43. // make sure we're installed
  44. assert(true == is_blog_installed());
  45. define('PHPUnit_MAIN_METHOD', false);
  46. $original_wpdb = $GLOBALS['wpdb'];
  47. // hide warnings during testing, since that's the normal WP behaviour
  48. if ( !WP_DEBUG ) {
  49. error_reporting(E_ALL ^ E_NOTICE);
  50. }
  51. $to = "To <wp.mail.testing@gmail.com>";
  52. $from = "From <wp.mail.testing+from@gmail.com>";
  53. $cc = "CC <wp.mail.testing+cc@gmail.com>";
  54. $bcc = "BCC <wp.mail.testing+bcc@gmail.com>";
  55. $subject = "RFC2822 Testing";
  56. $message = "My RFC822 Test Message";
  57. $headers[] = "From: {$from}";
  58. $headers[] = "CC: {$cc}";
  59. $_SERVER['SERVER_NAME'] = 'example.com';
  60. wp_mail( $to, $subject, $message, $headers );
  61. $headers = array();
  62. $subject = "RFC2822 Testing 2";
  63. $message = "My RFC822 Test Message 2";
  64. $to = "To <wp.mail.testing+to@gmail.com>";
  65. $headers[] = "BCC: {$bcc}";
  66. wp_mail( '', $subject, $message, $headers );
  67. echo "Test emails sent!\n"
  68. ?>