diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index af0156e..f5527f1 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -189,7 +189,8 @@ class Followers { self::add_error( $follower->get__id(), $error ); } - if ( is_array( $meta ) && ! in_array( $user_id, $meta, true ) ) { + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict + if ( is_array( $meta ) && ! in_array( $user_id, $meta ) ) { add_post_meta( $follower->get__id(), 'activitypub_user_id', $user_id ); wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' ); } diff --git a/tests/test-class-db-activitypub-followers.php b/tests/test-class-db-activitypub-followers.php index 559bd06..2f21767 100644 --- a/tests/test-class-db-activitypub-followers.php +++ b/tests/test-class-db-activitypub-followers.php @@ -244,6 +244,29 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase { $this->assertEquals( 0, count( $followers ) ); } + public function test_add_duplicate_follower() { + $pre_http_request = new MockAction(); + add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 ); + + $follower = 'https://12345.example.com'; + + \Activitypub\Collection\Followers::add_follower( 1, $follower ); + \Activitypub\Collection\Followers::add_follower( 1, $follower ); + \Activitypub\Collection\Followers::add_follower( 1, $follower ); + \Activitypub\Collection\Followers::add_follower( 1, $follower ); + \Activitypub\Collection\Followers::add_follower( 1, $follower ); + \Activitypub\Collection\Followers::add_follower( 1, $follower ); + + $db_followers = \Activitypub\Collection\Followers::get_followers( 1 ); + + $this->assertContains( $follower, $db_followers ); + + $follower = current( $db_followers ); + $meta = get_post_meta( $follower->get__id(), 'activitypub_user_id' ); + + $this->assertCount( 1, $meta ); + } + public static function http_request_host_is_external( $in, $host ) { if ( in_array( $host, array( 'example.com', 'example.org' ), true ) ) {