Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/03/2014 03:27:09 PM (11 years ago)
Author:
boonebgorges
Message:

Assemble message notification filters dynamically.

This allows us to centralize the documentation.

Props tw2113.
See #5970.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/messages/notifications.php

    r9139 r9208  
    66 */
    77class 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    }
    816    /**
    917     * @group bp_messages_message_delete_notifications
     
    4351        $this->set_current_user( $current_user );
    4452    }
     53
     54    /**
     55     * @group messages_format_notifications
     56     */
     57    public function test_friends_format_notifications_bp_messages_multiple_new_message_notification_nonstring_filter() {
     58        // Dummy thread ID
     59        $t = 12;
     60        $u = $this->factory->user->create();
     61        $this->set_current_user( $u );
     62
     63        // Admin
     64        $n = $this->factory->notification->create( array(
     65            'component_name' => 'messages',
     66            'user_id' => $u,
     67            'item_id' => $t,
     68            'component_action' => 'new_message',
     69        ) );
     70
     71        add_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
     72        $n = messages_format_notifications( 'new_message', $n, '', 2, 'array' );
     73        remove_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
     74
     75        $this->assertSame( 'bp_messages_multiple_new_message_notification', $this->filter_fired );
     76    }
     77
     78    /**
     79     * @group messages_format_notifications
     80     */
     81    public function test_friends_format_notifications_bp_messages_single_new_message_notification_nonstring_filter() {
     82        // Dummy thread ID
     83        $t = 12;
     84        $u = $this->factory->user->create();
     85        $this->set_current_user( $u );
     86
     87        // Admin
     88        $n = $this->factory->notification->create( array(
     89            'component_name' => 'messages',
     90            'user_id' => $u,
     91            'item_id' => $t,
     92            'component_action' => 'new_message',
     93        ) );
     94
     95        add_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
     96        $n = messages_format_notifications( 'new_message', $n, '', 1, 'array' );
     97        remove_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
     98
     99        $this->assertSame( 'bp_messages_single_new_message_notification', $this->filter_fired );
     100    }
     101
     102    /**
     103     * @group messages_format_notifications
     104     */
     105    public function test_friends_format_notifications_bp_messages_multiple_new_message_notification_string_filter() {
     106        // Dummy thread ID
     107        $t = 12;
     108        $u = $this->factory->user->create();
     109        $this->set_current_user( $u );
     110
     111        // Admin
     112        $n = $this->factory->notification->create( array(
     113            'component_name' => 'messages',
     114            'user_id' => $u,
     115            'item_id' => $t,
     116            'component_action' => 'new_message',
     117        ) );
     118
     119        add_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
     120        $n = messages_format_notifications( 'new_message', $n, '', 2 );
     121        remove_filter( 'bp_messages_multiple_new_message_notification', array( $this, 'notification_filter_callback' ) );
     122
     123        $this->assertSame( 'bp_messages_multiple_new_message_notification', $this->filter_fired );
     124    }
     125
     126    /**
     127     * @group messages_format_notifications
     128     */
     129    public function test_friends_format_notifications_bp_messages_single_new_message_notification_string_filter() {
     130        // Dummy thread ID
     131        $t = 12;
     132        $u = $this->factory->user->create();
     133        $this->set_current_user( $u );
     134
     135        // Admin
     136        $n = $this->factory->notification->create( array(
     137            'component_name' => 'messages',
     138            'user_id' => $u,
     139            'item_id' => $t,
     140            'component_action' => 'new_message',
     141        ) );
     142
     143        add_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
     144        $n = messages_format_notifications( 'new_message', $n, '', 1 );
     145        remove_filter( 'bp_messages_single_new_message_notification', array( $this, 'notification_filter_callback' ) );
     146
     147        $this->assertSame( 'bp_messages_single_new_message_notification', $this->filter_fired );
     148    }
     149
     150    public function notification_filter_callback( $value ) {
     151        $this->filter_fired = current_filter();
     152        return $value;
     153    }
    45154}
Note: See TracChangeset for help on using the changeset viewer.