From bf16ba56ec2c52ba2e414553455f7328feeb99ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Fri, 29 Dec 2023 17:53:32 +0100 Subject: [PATCH] fix/adpot unit tests --- includes/class-migration.php | 5 +++-- includes/collection/class-followers.php | 22 +++------------------- tests/test-class-activitypub-followers.php | 5 ++--- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/includes/class-migration.php b/includes/class-migration.php index adebb7e..8037269 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -132,10 +132,11 @@ class Migration { // migrate followers foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) { $followers = get_user_meta( $user_id, 'activitypub_followers', true ); - + if ( $followers ) { foreach ( $followers as $actor ) { - Followers::add_follower( $user_id, $actor ); + $follower_id = Followers::add_follower( $actor ); + Followers::add_follow_relationship( $user_id, $follower_id ); } } } diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index a09e86d..5ba1e6f 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -364,24 +364,6 @@ class Followers { 'key' => 'activitypub_errors', 'compare' => 'EXISTS', ), - array( - 'key' => 'activitypub_inbox', - 'compare' => 'NOT EXISTS', - ), - array( - 'key' => 'activitypub_actor_json', - 'compare' => 'NOT EXISTS', - ), - array( - 'key' => 'activitypub_inbox', - 'value' => '', - 'compare' => '=', - ), - array( - 'key' => 'activitypub_actor_json', - 'value' => '', - 'compare' => '=', - ), ), ); @@ -389,7 +371,9 @@ class Followers { $items = array(); foreach ( $posts->get_posts() as $follower ) { - $items[] = Follower::init_from_cpt( $follower ); // phpcs:ignore + if ( ! $follower->filtered_post_content || ! $follower->post_content ) { + $items[] = Follower::init_from_cpt( $follower ); // phpcs:ignore + } } return $items; diff --git a/tests/test-class-activitypub-followers.php b/tests/test-class-activitypub-followers.php index 0c2b4cd..dce1866 100644 --- a/tests/test-class-activitypub-followers.php +++ b/tests/test-class-activitypub-followers.php @@ -257,7 +257,7 @@ class Test_Activitypub_Followers extends WP_UnitTestCase { $follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' ); for ( $i = 1; $i <= 15; $i++ ) { - add_post_meta( $follower->get__id(), 'activitypub_errors', 'error ' . $i ); + add_post_meta( $follower_id, 'activitypub_errors', 'error ' . $i ); } $follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' ); @@ -265,6 +265,7 @@ class Test_Activitypub_Followers extends WP_UnitTestCase { $followers = \Activitypub\Collection\Followers::get_faulty_followers(); + $this->assertEquals( 15, $count ); $this->assertEquals( 1, count( $followers ) ); $this->assertEquals( 'http://sally.example.org', $followers[0] ); @@ -408,8 +409,6 @@ class Test_Activitypub_Followers extends WP_UnitTestCase { $id = $follower->upsert(); - echo $id . '\n'; - add_post_meta( $id, 'activitypub_user_id', 1 ); }