fix/adopt some unit tests
Some checks failed
PHP_CodeSniffer / phpcs (push) Has been cancelled
Unit Testing / phpunit (5.6, 6.2) (push) Has been cancelled
Unit Testing / phpunit (7.0) (push) Has been cancelled
Unit Testing / phpunit (7.2) (push) Has been cancelled
Unit Testing / phpunit (7.3) (push) Has been cancelled
Unit Testing / phpunit (7.4) (push) Has been cancelled
Unit Testing / phpunit (8.0) (push) Has been cancelled
Unit Testing / phpunit (8.1) (push) Has been cancelled
Unit Testing / phpunit (8.2) (push) Has been cancelled
Unit Testing / phpunit (latest) (push) Has been cancelled

This commit is contained in:
André Menrath 2023-12-27 22:41:32 +01:00
parent b1d65a64a8
commit f8ad036dbf
4 changed files with 30 additions and 20 deletions

View file

@ -224,11 +224,11 @@ class Followers {
*
* @return array The Term list of Followers.
*/
public static function get_all_followers() {
public static function get_all_followers( $user_id ) {
$args = array(
'nopaging' => true,
);
return self::get_followers( null, null, null, $args );
return self::get_followers( $user_id, null, null, $args );
}
/**

View file

@ -67,24 +67,24 @@ class Follow {
/**
* Send Follow response
*
* @param Activitypub\Model\User $user The Target Users ActivityPub object
* @param Activitypub\Model\Follower $follower The Followers ActivityPub object
* @param int|string $user_id The target users internal user id
* @param Activitypub\Model\Follower $follower The followers ActivityPub object
* @param array|object $object The ActivityPub follow object
* @param string $type The reponse object type: 'Accept' or 'Reject'
*
* @return void
*/
public static function send_follow_response( $user, $inbox, $object, $type ) {
public static function send_follow_response( $user_id, $inbox, $object, $type ) {
// send activity
$activity = new Activity();
$activity->set_type( $type );
$activity->set_object( $object );
$activity->set_actor( $user->get_id() );
$activity->set_actor( $user_id );
$activity->set_to( $object['actor'] );
$activity->set_id( $user->get_id() . '#accept-' . \preg_replace( '~^https?://~', '', $object['actor'] ) . '-' . \time() );
$activity->set_id( $user_id . '#accept-' . \preg_replace( '~^https?://~', '', $object['actor'] ) . '-' . \time() );
$activity = $activity->to_json();
Http::post( $inbox, $activity, $user->get__id() );
Http::post( $inbox, $activity, $user_id );
}
}

View file

@ -198,7 +198,7 @@ class Follow_Request extends Base_Object {
$this->save_follow_request_status( self::FOLLOW_REQUEST_STATUS_REJECTED );
$this->send_response( 'Reject' );
$this->send_response( 'Reject', $user_id );
$this->delete();
}
@ -214,7 +214,7 @@ class Follow_Request extends Base_Object {
$this->save_follow_request_status( self::FOLLOW_REQUEST_STATUS_APPROVED );
$this->send_response( 'Accept' );
$this->send_response( 'Accept', $user_id, $follower_id );
}
/**
@ -228,12 +228,21 @@ class Follow_Request extends Base_Object {
/**
* Prepere the sending of the follow request response and hand it over to the sending handler.
*
* @param string $type The Activity type of the response: 'Accept', or 'Reject'.
* @param int|string $user_id The user id of who gets followed.
* @param int $follwer_id The internal follower id.
*/
public function send_response( $type ) {
$user_id = get_post_meta( $this->get__id(), 'activitypub_user_id', true );
$user = Users::get_by_id( $user_id );
public function send_response( $type, $user_id = null, $follower_id = null ) {
if ( ! $user_id ) {
$user_id = get_post_meta( $this->get__id(), 'activitypub_user_id', true );
}
$follower_id = $this->get_follower_id();
$user = Users::get_by_id( $user_id );
if ( ! $follower_id ) {
$follower_id = $this->get_follower_id();
}
$follower_inbox = get_post_field( 'post_content_filtered', $follower_id );
@ -241,9 +250,8 @@ class Follow_Request extends Base_Object {
$follow_object = array(
'id' => $this->get_id(),
'type' => $this->get_type(),
'object' => $user,
);
do_action( 'activitypub_send_follow_response', $user, $follower_inbox, $follow_object, $type );
do_action( 'activitypub_send_follow_response', $user_id, $follower_inbox, $follow_object, $type );
}
}

View file

@ -251,7 +251,7 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
foreach ( $followers as $follower ) {
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower_id );
\Activitypub\Collection\Followers::add_follow_relationship( 1, $follower_id );
}
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' );
@ -288,8 +288,8 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
$follower2_id = \Activitypub\Collection\Followers::add_follower( $follower );
$follower3_id = \Activitypub\Collection\Followers::add_follower( $follower );
$this->assertEqual( $follower1_id, $follower2_id );
$this->assertEqual( $follower1_id, $follower3_id );
$this->assertEquals( $follower1_id, $follower2_id );
$this->assertEquals( $follower1_id, $follower3_id );
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower1_id );
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower2_id );
@ -408,10 +408,12 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
$id = $follower->upsert();
echo $id . '\n';
add_post_meta( $id, 'activitypub_user_id', 1 );
}
$followers = \Activitypub\Collection\Followers::get_all_followers();
$followers = \Activitypub\Collection\Followers::get_all_followers( 1 );
$this->assertCount( 30, $followers );
}