make the save of a follower return the post id instead of the object and adopt unit tests
Some checks are pending
PHP_CodeSniffer / phpcs (push) Waiting to run
Unit Testing / phpunit (5.6, 6.2) (push) Waiting to run
Unit Testing / phpunit (7.0) (push) Waiting to run
Unit Testing / phpunit (7.2) (push) Waiting to run
Unit Testing / phpunit (7.3) (push) Waiting to run
Unit Testing / phpunit (7.4) (push) Waiting to run
Unit Testing / phpunit (8.0) (push) Waiting to run
Unit Testing / phpunit (8.1) (push) Waiting to run
Unit Testing / phpunit (8.2) (push) Waiting to run
Unit Testing / phpunit (latest) (push) Waiting to run
Some checks are pending
PHP_CodeSniffer / phpcs (push) Waiting to run
Unit Testing / phpunit (5.6, 6.2) (push) Waiting to run
Unit Testing / phpunit (7.0) (push) Waiting to run
Unit Testing / phpunit (7.2) (push) Waiting to run
Unit Testing / phpunit (7.3) (push) Waiting to run
Unit Testing / phpunit (7.4) (push) Waiting to run
Unit Testing / phpunit (8.0) (push) Waiting to run
Unit Testing / phpunit (8.1) (push) Waiting to run
Unit Testing / phpunit (8.2) (push) Waiting to run
Unit Testing / phpunit (latest) (push) Waiting to run
This commit is contained in:
parent
32acc511b1
commit
94751480d6
5 changed files with 48 additions and 34 deletions
|
@ -23,14 +23,15 @@ class Followers {
|
|||
/**
|
||||
* Add new Follower.
|
||||
*
|
||||
* This does not add the follow relationship. It is added when the Accept respone is sent.
|
||||
* This does not add the follow relationship.
|
||||
*
|
||||
* The follow relationship can be added later with add_follow_relationship which is usually done when the Accept respone is sent.
|
||||
*
|
||||
* @param int $user_id The ID of the WordPress User
|
||||
* @param string $actor The Actor URL
|
||||
*
|
||||
* @return array|WP_Error The Follower (WP_Post array) or an WP_Error
|
||||
*/
|
||||
public static function add_follower( $user_id, $actor ) {
|
||||
public static function add_follower( $actor ) {
|
||||
$meta = get_remote_metadata_by_actor( $actor );
|
||||
|
||||
if ( is_tombstone( $meta ) ) {
|
||||
|
@ -55,7 +56,7 @@ class Followers {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add the follow relationship.
|
||||
* Add follow relationship between follower actor identified by internal post id and target actor identified by WordPress user id.
|
||||
*
|
||||
* @param int|string $user_id The internal id of the target WordPress user that gets followed.
|
||||
* @param int|string $follower_id The internal id of the follower actor.
|
||||
|
|
|
@ -46,19 +46,19 @@ class Follow {
|
|||
$user_id = $user->get__id();
|
||||
|
||||
// save follower
|
||||
$follower = Followers::add_follower(
|
||||
$follower_id = Followers::add_follower(
|
||||
$user_id,
|
||||
$activity['actor']
|
||||
);
|
||||
|
||||
if ( \is_wp_error( $follower ) ) {
|
||||
if ( \is_wp_error( $follower_id ) ) {
|
||||
// it is not even possible to send a "Reject" or "Accept" because
|
||||
// we can not get the Remote-Inbox
|
||||
return;
|
||||
}
|
||||
|
||||
// save follow request by this follower
|
||||
$follow_request = Follow_Request::save( $follower, $user_id, $activity['id'] );
|
||||
$follow_request = Follow_Request::save( $follower_id, $user_id, $activity['id'] );
|
||||
|
||||
if ( ! $user->get_manually_approves_followers() ) {
|
||||
$follow_request->approve();
|
||||
|
|
|
@ -129,8 +129,7 @@ class Follow_Request extends Base_Object {
|
|||
*
|
||||
* @return Follow_Request|WP_Error The Follow_Request or an WP_Error.
|
||||
*/
|
||||
public static function save( $follower, $user_id, $activity_id ) {
|
||||
$follower_id = $follower->get__id();
|
||||
public static function save( $follower_id, $user_id, $activity_id ) {
|
||||
$meta_input = array(
|
||||
'activitypub_user_id' => $user_id,
|
||||
);
|
||||
|
|
|
@ -21,7 +21,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
|
|||
$followers = array( 'https://example.com/author/jon', 'https://example.org/users/username' );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 1, $follower_id );
|
||||
}
|
||||
|
||||
$post = \wp_insert_post(
|
||||
|
@ -100,7 +101,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
|
|||
$followers = array( 'https://example.com/author/jon' );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( \Activitypub\Collection\Users::BLOG_USER_ID, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( \Activitypub\Collection\Users::BLOG_USER_ID, $follower_id );
|
||||
}
|
||||
|
||||
$post = \wp_insert_post(
|
||||
|
@ -148,7 +150,8 @@ class Test_Activitypub_Activity_Dispatcher extends ActivityPub_TestCase_Cache_HT
|
|||
$this->assertTrue( \Activitypub\is_single_user() );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( \Activitypub\Collection\Users::BLOG_USER_ID, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( \Activitypub\Collection\Users::BLOG_USER_ID, $follower_id );
|
||||
}
|
||||
|
||||
$post = \wp_insert_post(
|
||||
|
|
|
@ -68,7 +68,8 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
$response = \Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
$response = \Activitypub\Collection\Followers::add_follow_relationship( 1, $follower_id );
|
||||
}
|
||||
|
||||
$db_followers = \Activitypub\Collection\Followers::get_followers( 1 );
|
||||
|
@ -91,9 +92,11 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
|
||||
$follower = 'https://12345.example.com';
|
||||
$follower2 = 'https://user2.example.com';
|
||||
\Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
\Activitypub\Collection\Followers::add_follower( 2, $follower );
|
||||
\Activitypub\Collection\Followers::add_follower( 2, $follower2 );
|
||||
$follwer_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
$follower2_id = \Activitypub\Collection\Followers::add_follower( $follower2 );
|
||||
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 1, $follwer_id );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 2, $follower2_id );
|
||||
|
||||
$db_followers = \Activitypub\Collection\Followers::get_followers( 1 );
|
||||
$db_followers2 = \Activitypub\Collection\Followers::get_followers( 2 );
|
||||
|
@ -108,13 +111,13 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
|
||||
$follower = 'error@example.com';
|
||||
|
||||
$result = \Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
$result = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
|
||||
$this->assertTrue( is_wp_error( $result ) );
|
||||
|
||||
$follower2 = 'https://error.example.com';
|
||||
|
||||
$result = \Activitypub\Collection\Followers::add_follower( 1, $follower2 );
|
||||
$result = \Activitypub\Collection\Followers::add_follower( $follower2 );
|
||||
|
||||
$this->assertTrue( is_wp_error( $result ) );
|
||||
|
||||
|
@ -131,11 +134,13 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 1, $follower_id );
|
||||
}
|
||||
|
||||
foreach ( $followers2 as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( 2, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 2, $follower_id );
|
||||
}
|
||||
|
||||
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'https://example.com/author/jon' );
|
||||
|
@ -155,7 +160,7 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
$this->assertEquals( 'úser2', $follower2->get_name() );
|
||||
}
|
||||
|
||||
public function test_delete_follower() {
|
||||
public function test_delete_follow_relatioship() {
|
||||
$followers = array(
|
||||
'https://example.com/author/jon',
|
||||
'https://example.org/author/doe',
|
||||
|
@ -166,14 +171,14 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
|
||||
|
||||
foreach ( $followers as $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( 2, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 1, $follower_id );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 2, $follower_id );
|
||||
}
|
||||
|
||||
foreach ( $followers2 as $follower2 ) {
|
||||
\Activitypub\Collection\Followers::add_follower( 2, $follower2 );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower2 );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship( 2, $follower_id );
|
||||
}
|
||||
|
||||
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'https://example.com/author/jon' );
|
||||
|
@ -204,7 +209,8 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower_id );
|
||||
}
|
||||
|
||||
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'https://example.com/author/jon' );
|
||||
|
@ -244,7 +250,8 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
\Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||
$follower_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower_id );
|
||||
}
|
||||
|
||||
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' );
|
||||
|
@ -277,12 +284,16 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
|
|||
|
||||
$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 );
|
||||
$follower1_id = \Activitypub\Collection\Followers::add_follower( $follower );
|
||||
$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 );
|
||||
|
||||
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower1_id );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower2_id );
|
||||
\Activitypub\Collection\Followers::add_follow_relationship(1, $follower3_id );
|
||||
|
||||
$db_followers = \Activitypub\Collection\Followers::get_followers( 1 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue