wp-mail-real-test.php 2.4 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. require __DIR__ . '/wp-testlib/getopt.php';
  13. $opts = getoptParser::getopt( $options );
  14. }
  15. define( 'DIR_TESTROOT', realpath( __DIR__ ) );
  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. } elseif ( ! empty( $opts['v'] ) ) {
  21. define( 'DIR_WP', DIR_TESTROOT . '/wordpress-' . $opts['v'] );
  22. } else {
  23. define( 'DIR_WP', DIR_TESTROOT . '/wordpress' );
  24. }
  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. // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase
  46. define( 'PHPUnit_MAIN_METHOD', false );
  47. $original_wpdb = $GLOBALS['wpdb'];
  48. // Hide warnings during testing, since that's the normal WP behaviour.
  49. if ( ! WP_DEBUG ) {
  50. error_reporting( E_ALL ^ E_NOTICE );
  51. }
  52. $to = 'To <wp.mail.testing@gmail.com>';
  53. $from = 'From <wp.mail.testing+from@gmail.com>';
  54. $cc = 'CC <wp.mail.testing+cc@gmail.com>';
  55. $bcc = 'BCC <wp.mail.testing+bcc@gmail.com>';
  56. $subject = 'RFC2822 Testing';
  57. $message = 'My RFC822 Test Message';
  58. $headers[] = "From: {$from}";
  59. $headers[] = "CC: {$cc}";
  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";