[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> class-bp-email-recipient.php (source)

   1  <?php
   2  /**
   3   * @group core
   4   * @group BP_Email_Recipient
   5   */
   6  class BP_Email_Recipient_Tests extends BP_UnitTestCase {
   7      protected $u1;
   8  
   9  	public function setUp() {
  10          parent::setUp();
  11  
  12          $this->u1 = self::factory()->user->create( array(
  13              'display_name' => 'Unit Test',
  14              'user_email'   => 'test@example.com',
  15          ) );
  16      }
  17  
  18  	public function test_return_with_address_and_name() {
  19          $email     = 'test@example.com';
  20          $name      = 'Unit Test';
  21          $recipient = new BP_Email_Recipient( $email, $name );
  22  
  23          $this->assertSame( $email, $recipient->get_address() );
  24          $this->assertSame( $name, $recipient->get_name() );
  25      }
  26  
  27  	public function test_return_with_array() {
  28          $email     = 'test@example.com';
  29          $name      = 'Unit Test';
  30          $recipient = new BP_Email_Recipient( array( $email => $name ) );
  31  
  32          $this->assertSame( $email, $recipient->get_address() );
  33          $this->assertSame( $name, $recipient->get_name() );
  34      }
  35  
  36  	public function test_return_with_user_id() {
  37          $recipient = new BP_Email_Recipient( $this->u1 );
  38  
  39          $this->assertSame( 'test@example.com', $recipient->get_address() );
  40          $this->assertSame( 'Unit Test', $recipient->get_name() );
  41      }
  42  
  43  	public function test_return_with_wp_user_object() {
  44          $recipient = new BP_Email_Recipient( get_user_by( 'id', $this->u1 ) );
  45  
  46          $this->assertSame( 'test@example.com', $recipient->get_address() );
  47          $this->assertSame( 'Unit Test', $recipient->get_name() );
  48      }
  49  
  50      public function test_return_with_known_address_and_optional_name() {
  51          $email     = 'test@example.com';
  52          $name      = 'Custom';
  53          $recipient = new BP_Email_Recipient( $email, $name );
  54  
  55          $this->assertSame( 'test@example.com', $recipient->get_address() );
  56          $this->assertSame( 'Custom', $recipient->get_name() );
  57      }
  58  
  59  	public function test_return_with_known_address_and_empty_name() {
  60          $email     = 'test@example.com';
  61          $recipient = new BP_Email_Recipient( $email );
  62  
  63          $this->assertSame( 'test@example.com', $recipient->get_address() );
  64  
  65          // Should fallback to WP user name.
  66          $this->assertSame( 'Unit Test', $recipient->get_name() );
  67      }
  68  
  69      public function test_return_with_unknown_address_and_optional_name() {
  70          $email     = 'unknown@example.com';
  71          $name      = 'Custom';
  72          $recipient = new BP_Email_Recipient( $email, $name );
  73  
  74          $this->assertSame( $email, $recipient->get_address() );
  75          $this->assertSame( $name, $recipient->get_name() );
  76      }
  77  
  78      public function test_return_with_unknown_address_and_empty_name() {
  79          $email     = 'unknown@example.com';
  80          $recipient = new BP_Email_Recipient( $email );
  81  
  82          $this->assertSame( $email, $recipient->get_address() );
  83          $this->assertEmpty( $recipient->get_name() );
  84      }
  85  
  86      public function test_return_with_unknown_array_and_optional_name() {
  87          $email     = 'unknown@example.com';
  88          $name      = 'Custom';
  89          $recipient = new BP_Email_Recipient( array( $email => $name ) );
  90  
  91          $this->assertSame( $email, $recipient->get_address() );
  92          $this->assertSame( $name, $recipient->get_name() );
  93      }
  94  
  95  	public function test_return_with_unknown_array_and_empty_name() {
  96          $email     = 'unknown@example.com';
  97          $recipient = new BP_Email_Recipient( array( $email ) );
  98  
  99          $this->assertSame( $email, $recipient->get_address() );
 100          $this->assertEmpty( $recipient->get_name() );
 101      }
 102  
 103      public function test_return_with_known_array_and_optional_name() {
 104          $email     = 'test@example.com';
 105          $name      = 'Custom';
 106          $recipient = new BP_Email_Recipient( array( $email => $name ) );
 107  
 108          $this->assertSame( $email, $recipient->get_address() );
 109          $this->assertSame( $name, $recipient->get_name() );
 110      }
 111  
 112  	public function test_return_with_known_array_and_empty_name() {
 113          $email     = 'test@example.com';
 114          $recipient = new BP_Email_Recipient( array( $email ) );
 115  
 116          $this->assertSame( $email, $recipient->get_address() );
 117  
 118          // Should fallback to WP user name.
 119          $this->assertSame( 'Unit Test', $recipient->get_name() );
 120      }
 121  
 122      public function test_should_return_empty_string_if_user_id_id_invalid() {
 123          $recipient = new BP_Email_Recipient( time() );
 124  
 125          $this->assertEmpty( $recipient->get_address() );
 126          $this->assertEmpty( $recipient->get_name() );
 127      }
 128  
 129  	public function test_get_wp_user_object_from_email_address() {
 130          $recipient = new BP_Email_Recipient( 'test@example.com' );
 131          $recipient = $recipient->get_user( 'search-email' );
 132  
 133          $this->assertSame( $this->u1, $recipient->ID );
 134          $this->assertSame( 'test@example.com', $recipient->user_email );
 135      }
 136  }


Generated: Fri Nov 22 01:00:56 2024 Cross-referenced by PHPXref 0.7.1