Skip to:
Content

BuddyPress.org

Ticket #8642: 8642.tests.patch

File 8642.tests.patch, 3.2 KB (added by imath, 3 years ago)
  • tests/phpunit/testcases/notifications/cache.php

    diff --git tests/phpunit/testcases/notifications/cache.php tests/phpunit/testcases/notifications/cache.php
    index 4c99dff0a..b0356e9a9 100644
    class BP_Tests_Notifications_Cache extends BP_UnitTestCase { 
    226226                $this->assertContains( $notification_id, $all_ids );
    227227        }
    228228
     229        /**
     230         * @group cache
     231         * @ticket BP8642
     232         */
     233        public function test_bp_notifications_clear_all_for_user_cache_before_update_when_marked_unread() {
     234                $u = self::factory()->user->create();
     235                $a = self::factory()->activity->create();
     236
     237                $notification_ids = self::factory()->notification->create_many(
     238                        4,
     239                        array(
     240                                'component_name'    => 'activity',
     241                                'component_action'  => 'at_mentions',
     242                                'user_id'           => $u,
     243                                'item_id'           => $a,
     244                                'is_new'            => 0,
     245                                'allow_duplicate'   => true,
     246                        )
     247                );
     248
     249                $all_for_user_notifications = bp_notifications_get_all_notifications_for_user( $u );
     250                $this->assertEmpty( $all_for_user_notifications );
     251
     252                // Mark as unread.
     253                $amount = bp_notifications_mark_notifications_by_ids( $notification_ids, 1 );
     254                $this->assertTrue( $amount === count( $notification_ids ) );
     255
     256                $all_for_user_notifications = bp_notifications_get_all_notifications_for_user( $u );
     257                $this->assertEquals( $notification_ids, wp_list_pluck( $all_for_user_notifications, 'id' ) );
     258        }
     259
    229260        /**
    230261         * @group cache
    231262         * @ticket BP8637
    class BP_Tests_Notifications_Cache extends BP_UnitTestCase { 
    314345                $this->assertContains( $message_id, $all_ids );
    315346        }
    316347
     348        /**
     349         * @group cache
     350         * @ticket BP8642
     351         */
     352        public function test_bp_notifications_clear_all_for_user_cache_before_update_when_item_ids_and_marked_unread() {
     353                $s                = self::factory()->user->create();
     354                $r                = self::factory()->user->create();
     355                $notification_ids = array();
     356
     357                remove_action( 'messages_message_sent', 'bp_messages_message_sent_add_notification', 10 );
     358
     359                $message_ids = self::factory()->message->create_many(
     360                        4,
     361                        array(
     362                                'sender_id'  => $s,
     363                                'recipients' => array( $r ),
     364                                'content'    => 'testing notification all for user cache',
     365                        )
     366                );
     367
     368                foreach ( $message_ids as $message_id ) {
     369                        $notification_ids[] = self::factory()->notification->create(
     370                                array(
     371                                        'component_name'    => 'messages',
     372                                        'component_action'  => 'new_message',
     373                                        'user_id'           => $r,
     374                                        'item_id'           => $message_id,
     375                                        'is_new'            => 0,
     376                                )
     377                        );
     378                }
     379
     380                add_action( 'messages_message_sent', 'bp_messages_message_sent_add_notification', 10 );
     381
     382                $all_for_user_notifications = bp_notifications_get_all_notifications_for_user( $r );
     383                $this->assertEmpty( $all_for_user_notifications );
     384
     385                // Mark unread.
     386                $amount = bp_notifications_mark_notifications_by_item_ids( $r, $message_ids, 'messages', 'new_message', 1 );
     387                $this->assertTrue( $amount === count( $message_ids ) );
     388
     389                $all_for_user_notifications = bp_notifications_get_all_notifications_for_user( $r );
     390                $this->assertEquals( $message_ids, wp_list_pluck( $all_for_user_notifications, 'item_id' ) );
     391        }
     392
    317393        /**
    318394         * @group cache
    319395         * @ticket BP8637