remove paging from get_all_followers

and add tests
This commit is contained in:
Matthias Pfefferle 2023-12-04 10:02:30 +01:00
parent ca9e71ffc1
commit 5d417d9f5c
2 changed files with 77 additions and 0 deletions

View file

@ -199,6 +199,7 @@ class Followers {
*/
public static function get_all_followers() {
$args = array(
'nopaging' => true,
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array(
'relation' => 'AND',

View file

@ -329,6 +329,82 @@ class Test_Activitypub_Followers extends WP_UnitTestCase {
$this->assertEquals( $name, $follower->get_name() );
}
public function test_get_inboxes() {
for ( $i = 0; $i < 30; $i++ ) {
$meta = array(
'id' => 'https://example.org/users/' . $i,
'url' => 'https://example.org/users/' . $i,
'inbox' => 'https://example.org/users/' . $i . '/inbox',
'name' => 'user' . $i,
'preferredUsername' => 'user' . $i,
'publicKey' => 'https://example.org/users/' . $i . '#main-key',
'publicKeyPem' => $i,
);
$follower = new \Activitypub\Model\Follower();
$follower->from_array( $meta );
$id = $follower->upsert();
add_post_meta( $id, 'activitypub_user_id', 1 );
}
$inboxes = \Activitypub\Collection\Followers::get_inboxes( 1 );
$this->assertCount( 30, $inboxes );
wp_cache_delete( sprintf( \Activitypub\Collection\Followers::CACHE_KEY_INBOXES, 1 ), 'activitypub' );
for ( $j = 0; $j < 5; $j++ ) {
$k = $j + 100;
$meta = array(
'id' => 'https://example.org/users/' . $k,
'url' => 'https://example.org/users/' . $k,
'inbox' => 'https://example.org/users/' . $j . '/inbox',
'name' => 'user' . $k,
'preferredUsername' => 'user' . $k,
'publicKey' => 'https://example.org/users/' . $k . '#main-key',
'publicKeyPem' => $k,
);
$follower = new \Activitypub\Model\Follower();
$follower->from_array( $meta );
$id = $follower->upsert();
add_post_meta( $id, 'activitypub_user_id', 1 );
}
$inboxes2 = \Activitypub\Collection\Followers::get_inboxes( 1 );
$this->assertCount( 30, $inboxes2 );
}
public function test_get_all_followers() {
for ( $i = 0; $i < 30; $i++ ) {
$meta = array(
'id' => 'https://example.org/users/' . $i,
'url' => 'https://example.org/users/' . $i,
'inbox' => 'https://example.org/users/' . $i . '/inbox',
'name' => 'user' . $i,
'preferredUsername' => 'user' . $i,
'publicKey' => 'https://example.org/users/' . $i . '#main-key',
'publicKeyPem' => $i,
);
$follower = new \Activitypub\Model\Follower();
$follower->from_array( $meta );
$id = $follower->upsert();
add_post_meta( $id, 'activitypub_user_id', 1 );
}
$followers = \Activitypub\Collection\Followers::get_all_followers();
$this->assertCount( 30, $followers );
}
public static function http_request_host_is_external( $in, $host ) {
if ( in_array( $host, array( 'example.com', 'example.org' ), true ) ) {
return true;