Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/28/2016 05:25:24 PM (3 years ago)
Author:
r-a-y
Message:

Notifications: Fix issue with querying notifications by string format.

If someone is using:
bp_notifications_get_notifications_for_user( $user_id, 'string' )

This functionality broke in #7066.

Commit fixes this issue and includes unit tests.

Fixes #7141 (trunk).

File:
1 edited

Legend:

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

    r10788 r10911  
    349349        $this->assertEmpty( $found2 );
    350350    }
     351
     352    /**
     353     * @group  notification_callback
     354     * @ticket BP7141
     355     */
     356    public function test_notification_callback_parameter_integrity() {
     357        $u = $this->factory->user->create();
     358
     359        $n = $this->factory->notification->create( array(
     360            'component_name'    => 'activity',
     361            'component_action'  => 'new_at_mention',
     362            'item_id'           => 99,
     363            'user_id'           => $u,
     364        ) );
     365
     366        // Override activity notification callback so we can test integrity.
     367        buddypress()->activity->notification_callback = array( $this, 'dummy_notification_callback' );
     368
     369        // Fetch notifications with string format.
     370        bp_notifications_get_notifications_for_user( $u, 'string' );
     371
     372        // Assert!
     373        // @todo When we cast all numeric strings as integers, this needs to be changed.
     374        $expected = array(
     375            'action'            => 'new_at_mention',
     376            'item_id'           => '99',
     377            'secondary_item_id' => '0',
     378            'total_items'       => 1,
     379            'id'                => (string) $n,
     380            'format'            => 'string'
     381        );
     382        $this->assertEquals( $expected, $this->n_args );
     383
     384        // Fetch notifications with object format this time.
     385        bp_notifications_get_notifications_for_user( $u, 'object' );
     386
     387        // Assert!
     388        $expected['format'] = 'array';
     389        $this->assertEquals( $expected, $this->n_args );
     390
     391        // Reset!
     392        buddypress()->activity->notification_callback = 'bp_activity_format_notifications';
     393        unset( $this->n_args );
     394    }
     395
     396    /**
     397     * Used in test_notification_callback_parameter_integrity() test.
     398     */
     399    public function dummy_notification_callback( $action, $item_id, $secondary_item_id, $total_items, $format = 'string', $id = 0 ) {
     400        $this->n_args = compact( 'action', 'item_id', 'secondary_item_id', 'total_items', 'id', 'format' );
     401    }
    351402}
Note: See TracChangeset for help on using the changeset viewer.