Ticket #28909: 28909.unit-test-vars.diff
File 28909.unit-test-vars.diff, 3.5 KB (added by , 9 years ago) |
---|
-
tests/phpunit/tests/mail.php
1 1 <?php 2 2 /** 3 3 * @group pluggable 4 4 * @group mail 5 5 */ 6 6 class Tests_Mail extends WP_UnitTestCase { 7 7 function setUp() { 8 8 parent::setUp(); 9 9 unset( $GLOBALS['phpmailer']->mock_sent ); 10 10 } 11 11 12 function test_wp_mail_break_it() { 13 $content = str_repeat( 'A', 1000 ); 14 wp_mail( "admin@example.org", 'Looong line testing', $content); 15 } 16 12 17 function test_wp_mail_custom_boundaries() { 13 18 $to = 'user@example.com'; 14 19 $subject = 'Test email with custom boundaries'; 15 20 $headers = '' . "\n"; 16 21 $headers .= 'MIME-Version: 1.0' . "\n"; 17 22 $headers .= 'Content-Type: multipart/mixed; boundary="----=_Part_4892_25692638.1192452070893"' . "\n"; 18 23 $headers .= "\n"; 19 24 $body = "\n"; 20 25 $body .= '------=_Part_4892_25692638.1192452070893' . "\n"; 21 26 $body .= 'Content-Type: text/plain; charset=ISO-8859-1' . "\n"; 22 27 $body .= 'Content-Transfer-Encoding: 7bit' . "\n"; 23 28 $body .= 'Content-Disposition: inline' . "\n"; 24 29 $body .= "\n"; 25 30 $body .= 'Here is a message with an attachment of a binary file.' . "\n"; 26 31 $body .= "\n"; -
tests/phpunit/includes/mock-mailer.php
1 1 <?php 2 2 require_once( ABSPATH . '/wp-includes/class-phpmailer.php' ); 3 3 4 4 class MockPHPMailer extends PHPMailer { 5 5 var $mock_sent = array(); 6 6 7 function preSend() { 8 $this->Encoding = '8bit'; 9 parent::preSend(); 10 } 11 7 12 /** 8 * Override send() so mail isn't actually sent.13 * Override postSend() so mail isn't actually sent. 9 14 */ 10 function send() { 11 try { 12 if ( ! $this->preSend() ) 13 return false; 14 15 $this->mock_sent[] = array( 16 'to' => $this->to, 17 'cc' => $this->cc, 18 'bcc' => $this->bcc, 19 'header' => $this->MIMEHeader, 20 'body' => $this->MIMEBody, 21 ); 15 function postSend() { 16 $this->mock_sent[] = array( 17 'to' => $this->to, 18 'cc' => $this->cc, 19 'bcc' => $this->bcc, 20 'header' => $this->MIMEHeader, 21 'body' => $this->MIMEBody, 22 ); 22 23 23 return true; 24 } catch ( phpmailerException $e ) { 25 return false; 26 } 24 return true; 27 25 } 28 26 } -
tests/phpunit/includes/testcase.php
class WP_UnitTestCase extends PHPUnit_Fr 569 569 */ 570 570 protected function _microtime_to_float($microtime ){ 571 571 $time_array = explode( ' ', $microtime ); 572 572 return array_sum( $time_array ); 573 573 } 574 574 575 575 /** 576 576 * When `wp_mail()` is called, make sure `$_SERVER['SERVER_NAME']` is faked. 577 577 * 578 578 * @since 4.3.0 579 579 * 580 580 * @param array $args `wp_mail()` arguments. 581 581 * @return array $args 582 582 */ 583 583 public function set_wp_mail_globals( $args ) { 584 global $phpmailer; 585 // Reset the MockMailer on each new wp_mail() call 586 //$phpmailer = new MockPHPMailer(); 587 584 588 if ( ! isset( $_SERVER['SERVER_NAME'] ) ) { 585 589 $_SERVER['SERVER_NAME'] = 'example.com'; 586 590 add_action( 'phpmailer_init', array( $this, 'tear_down_wp_mail_globals' ) ); 587 591 } 588 592 589 593 return $args; 590 594 } 591 595 592 596 /** 593 597 * Tear down the faked `$_SERVER['SERVER_NAME']` global used in `wp_mail()`. 594 598 * 595 599 * @since 4.3.0 596 600 */ 597 601 public function tear_down_wp_mail_globals() { 598 602 unset( $_SERVER['SERVER_NAME'] );