[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/messages/ -> notifications.php (source)

   1  <?php
   2  
   3  /**
   4   * @group notifications
   5   * @group messages
   6   */
   7  class BP_Tests_Messages_Notifications extends BP_UnitTestCase {
   8  
   9      protected $filter_fired;
  10  
  11  	public function setUp() {
  12          parent::setUp();
  13  
  14          $this->filter_fired = '';
  15      }
  16  
  17      /**
  18       * @group messages_format_notifications
  19       */
  20      public function test_friends_format_notifications_bp_messages_multiple_new_message_notification_nonstring_filter() {
  21          // Dummy thread ID
  22          $t = 12;
  23          $u = self::factory()->user->create();
  24          $this->set_current_user( $u );
  25  
  26          // Admin
  27          $n = self::factory()->notification->create( array(
  28              'component_name' => 'messages',
  29              'user_id' => $u,
  30              'item_id' => $t,
  31              'component_action' => 'new_message',
  32          ) );
  33  
  34          add_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
  35          $n = messages_format_notifications( 'new_message', $n, '', 2, 'array' );
  36          remove_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
  37  
  38          $this->assertSame( 'bp_messages_multiple_new_message_notification', $this->filter_fired );
  39      }
  40  
  41      /**
  42       * @group messages_format_notifications
  43       */
  44      public function test_friends_format_notifications_bp_messages_single_new_message_notification_nonstring_filter() {
  45          // Dummy thread ID
  46          $t = 12;
  47          $u = self::factory()->user->create();
  48          $this->set_current_user( $u );
  49  
  50          // Admin
  51          $n = self::factory()->notification->create( array(
  52              'component_name' => 'messages',
  53              'user_id' => $u,
  54              'item_id' => $t,
  55              'component_action' => 'new_message',
  56          ) );
  57  
  58          add_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
  59          $n = messages_format_notifications( 'new_message', $n, '', 1, 'array' );
  60          remove_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
  61  
  62          $this->assertSame( 'bp_messages_single_new_message_notification', $this->filter_fired );
  63      }
  64  
  65      /**
  66       * @group messages_format_notifications
  67       */
  68      public function test_friends_format_notifications_bp_messages_multiple_new_message_notification_string_filter() {
  69          // Dummy thread ID
  70          $t = 12;
  71          $u = self::factory()->user->create();
  72          $this->set_current_user( $u );
  73  
  74          // Admin
  75          $n = self::factory()->notification->create( array(
  76              'component_name' => 'messages',
  77              'user_id' => $u,
  78              'item_id' => $t,
  79              'component_action' => 'new_message',
  80          ) );
  81  
  82          add_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
  83          $n = messages_format_notifications( 'new_message', $n, '', 2 );
  84          remove_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
  85  
  86          $this->assertSame( 'bp_messages_multiple_new_message_notification', $this->filter_fired );
  87      }
  88  
  89      /**
  90       * @group messages_format_notifications
  91       */
  92      public function test_friends_format_notifications_bp_messages_single_new_message_notification_string_filter() {
  93          // Dummy thread ID
  94          $t = 12;
  95          $u = self::factory()->user->create();
  96          $this->set_current_user( $u );
  97  
  98          // Admin
  99          $n = self::factory()->notification->create( array(
 100              'component_name' => 'messages',
 101              'user_id' => $u,
 102              'item_id' => $t,
 103              'component_action' => 'new_message',
 104          ) );
 105  
 106          add_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
 107          $n = messages_format_notifications( 'new_message', $n, '', 1 );
 108          remove_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
 109  
 110          $this->assertSame( 'bp_messages_single_new_message_notification', $this->filter_fired );
 111      }
 112  
 113      /**
 114       * @ticket BP6329
 115       */
 116      public function test_messages_notifications_should_be_deleted_when_corresponding_message_is_deleted() {
 117          if ( ! bp_is_active( 'messages' ) ) {
 118              $this->markTestSkipped( __METHOD__ . ' requires the Messages component.' );
 119          }
 120  
 121          $u1 = self::factory()->user->create();
 122          $u2 = self::factory()->user->create();
 123  
 124          $t1 = messages_new_message( array(
 125              'sender_id'  => $u1,
 126              'recipients' => array( $u2 ),
 127              'subject'    => 'A new message',
 128              'content'    => 'Hey there!',
 129          ) );
 130  
 131          // Verify that a notification has been created for the message.
 132          $n1 = BP_Notifications_Notification::get( array(
 133              'component' => 'messages',
 134              'user_id' => $u2,
 135          ) );
 136          $this->assertNotEmpty( $n1 );
 137  
 138          $this->assertTrue( messages_delete_thread( $t1 ) );
 139  
 140          $n2 = BP_Notifications_Notification::get( array(
 141              'component' => 'messages',
 142              'user_id' => $u2,
 143          ) );
 144          $this->assertSame( array(), $n2 );
 145      }
 146  
 147  	public function notification_filter_callback( $value ) {
 148          $this->filter_fired = current_filter();
 149          return $value;
 150      }
 151  }


Generated: Mon Jul 22 01:01:43 2019 Cross-referenced by PHPXref 0.7.1