Changeset 10482
- Timestamp:
- 01/30/2016 08:39:59 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/bp-core/classes/class-bp-email.php (modified) (9 diffs)
-
tests/phpunit/testcases/core/class-bp-email.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-email.php
r10481 r10482 522 522 * or an array containing any combination of the above. 523 523 * @param string $name Optional. If $bcc_address is a string, this is the recipient's name. 524 * @return BP_Email 525 */ 526 public function set_bcc( $bcc_address, $name = '' ) { 527 $bcc = array(); 524 * @param string $operation Optional. If "replace", $to_address replaces current setting (default). 525 * If "add", $to_address is added to the current setting. 526 * @return BP_Email 527 */ 528 public function set_bcc( $bcc_address, $name = '', $operation = 'replace' ) { 529 $bcc = ( $operation !== 'replace' ) ? $this->bcc : array(); 528 530 529 531 if ( is_array( $bcc_address ) ) { … … 533 535 534 536 } else { 535 $bcc = array( new BP_Email_Recipient( $bcc_address, $name ));537 $bcc[] = new BP_Email_Recipient( $bcc_address, $name ); 536 538 } 537 539 … … 545 547 * or an array containing any combination of the above. 546 548 * @param string $name Optional. If $bcc_address is a string, this is the recipient's name. 547 * @param BP_Email $this Current instance of the email type class. 548 */ 549 $this->bcc = apply_filters( 'bp_email_set_bcc', $bcc, $bcc_address, $name, $this ); 549 * @param string $operation If "replace", $to_address replaced previous recipients. If "add", 550 * $to_address was added to the array of recipients. 551 * @param BP_Email $this Current instance of the email type class. 552 */ 553 $this->bcc = apply_filters( 'bp_email_set_bcc', $bcc, $bcc_address, $name, $operation, $this ); 550 554 551 555 return $this; … … 566 570 * or an array containing any combination of the above. 567 571 * @param string $name Optional. If $cc_address is a string, this is the recipient's name. 568 * @return BP_Email 569 */ 570 public function set_cc( $cc_address, $name = '' ) { 571 $cc = array(); 572 * @param string $operation Optional. If "replace", $to_address replaces current setting (default). 573 * If "add", $to_address is added to the current setting. 574 * @return BP_Email 575 */ 576 public function set_cc( $cc_address, $name = '', $operation = 'replace' ) { 577 $cc = ( $operation !== 'replace' ) ? $this->cc : array(); 572 578 573 579 if ( is_array( $cc_address ) ) { … … 577 583 578 584 } else { 579 $cc = array( new BP_Email_Recipient( $cc_address, $name ));585 $cc[] = new BP_Email_Recipient( $cc_address, $name ); 580 586 } 581 587 … … 589 595 * or an array containing any combination of the above. 590 596 * @param string $name Optional. If $cc_address is a string, this is the recipient's name. 591 * @param BP_Email $this Current instance of the email type class. 592 */ 593 $this->cc = apply_filters( 'bp_email_set_cc', $cc, $cc_address, $name, $this ); 597 * @param string $operation If "replace", $to_address replaced previous recipients. If "add", 598 * $to_address was added to the array of recipients. 599 * @param BP_Email $this Current instance of the email type class. 600 */ 601 $this->cc = apply_filters( 'bp_email_set_cc', $cc, $cc_address, $name, $operation, $this ); 594 602 595 603 return $this; … … 834 842 * or an array containing any combination of the above. 835 843 * @param string $name Optional. If $to_address is a string, this is the recipient's name. 836 * @return BP_Email 837 */ 838 public function set_to( $to_address, $name = '' ) { 839 $to = array(); 844 * @param string $operation Optional. If "replace", $to_address replaces current setting (default). 845 * If "add", $to_address is added to the current setting. 846 * @return BP_Email 847 */ 848 public function set_to( $to_address, $name = '', $operation = 'replace' ) { 849 $to = ( $operation !== 'replace' ) ? $this->to : array(); 840 850 841 851 if ( is_array( $to_address ) ) { … … 845 855 846 856 } else { 847 $to = array( new BP_Email_Recipient( $to_address, $name ));857 $to[] = new BP_Email_Recipient( $to_address, $name ); 848 858 } 849 859 … … 856 866 * @param string $to_address "To" address. 857 867 * @param string $name "To" name. 858 * @param BP_Email $this Current instance of the email type class. 859 */ 860 $this->to = apply_filters( 'bp_email_set_to', $to, $to_address, $name, $this ); 868 * @param string $operation If "replace", $to_address replaced previous recipients. If "add", 869 * $to_address was added to the array of recipients. 870 * @param BP_Email $this Current instance of the email type class. 871 */ 872 $this->to = apply_filters( 'bp_email_set_to', $to, $to_address, $name, $operation, $this ); 861 873 862 874 return $this; -
trunk/tests/phpunit/testcases/core/class-bp-email.php
r10481 r10482 223 223 $this->assertSame( $user3, $addresses[2]->get_address() ); 224 224 } 225 226 public function test_replacing_existing_recipients_with_new_recipients() { 227 $email = new BP_Email( 'fake_type' ); 228 $original_recipient = 'test1@example.com'; 229 $new_recipient = 'test2@example.com'; 230 231 $email->set_to( $original_recipient ); 232 $addresses = $email->get_to(); 233 $this->assertSame( $original_recipient, $addresses[0]->get_address() ); 234 235 $email->set_to( $new_recipient ); 236 $addresses = $email->get_to(); 237 $this->assertSame( $new_recipient, $addresses[0]->get_address() ); 238 } 239 240 public function test_appending_new_recipients_to_existing_recipients() { 241 $email = new BP_Email( 'fake_type' ); 242 $original_recipient = 'test1@example.com'; 243 $new_recipient = 'test2@example.com'; 244 245 $email->set_to( $original_recipient ); 246 $addresses = $email->get_to(); 247 $this->assertSame( $original_recipient, $addresses[0]->get_address() ); 248 249 $email->set_to( $new_recipient, '', 'add' ); 250 $addresses = $email->get_to(); 251 $this->assertSame( $original_recipient, $addresses[0]->get_address() ); 252 $this->assertSame( $new_recipient, $addresses[1]->get_address() ); 253 } 225 254 }
Note: See TracChangeset
for help on using the changeset viewer.