André Menrath
ddeb5c6cca
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 47s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 52s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 54s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 53s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 52s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 51s
* Use WP_Post ID of the event source for linking the event source with an cached remote event post * Improve docs * Add tests for retrieving the event_sources list
98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Test file for the Event Sources collection.
|
|
*
|
|
* @package Event_Bridge_For_ActivityPub
|
|
* @since 1.0.0
|
|
* @license AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace Event_Bridge_For_ActivityPub\Tests\ActivityPub\Collection;
|
|
|
|
use WP_REST_Server;
|
|
|
|
/**
|
|
* Test class for the Event Sources collection.
|
|
*
|
|
* @coversDefaultClass \Event_Bridge_For_ActivityPub\ActivityPub\Collections\Event_Sources
|
|
*/
|
|
class Test_Event_Sources extends \WP_UnitTestCase {
|
|
const FOLLOWED_ACTOR_1 = array(
|
|
'id' => 'https://remote.example/@organizer',
|
|
'type' => 'Person',
|
|
'inbox' => 'https://remote.example/@organizer/inbox',
|
|
'outbox' => 'https://remote.example/@organizer/outbox',
|
|
'name' => 'The Organizer',
|
|
'summary' => 'Just a random organizer of events in the Fediverse',
|
|
);
|
|
|
|
const FOLLOWED_ACTOR_2 = array(
|
|
'id' => 'https://remote.example/@organizer2',
|
|
'type' => 'Person',
|
|
'inbox' => 'https://remote.example/@organizer2/inbox',
|
|
'outbox' => 'https://remote.example/@organizer2/outbox',
|
|
'name' => 'The Second Organizer',
|
|
'summary' => 'Just a second random organizer of events in the Fediverse',
|
|
);
|
|
|
|
/**
|
|
* REST Server.
|
|
*
|
|
* @var WP_REST_Server
|
|
*/
|
|
protected $server;
|
|
|
|
/**
|
|
* Set up the test.
|
|
*/
|
|
public function set_up() {
|
|
if ( ! defined( 'GATHERPRESS_CORE_FILE' ) ) {
|
|
self::markTestSkipped( 'GatherPress plugin is not active.' );
|
|
}
|
|
|
|
\add_option( 'permalink_structure', '/%postname%/' );
|
|
|
|
global $wp_rest_server;
|
|
$wp_rest_server = new WP_REST_Server();
|
|
$this->server = $wp_rest_server;
|
|
|
|
do_action( 'rest_api_init' );
|
|
|
|
\Activitypub\Rest\Server::add_hooks();
|
|
|
|
// Mock the plugin activation.
|
|
\GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false );
|
|
|
|
// Make sure that ActivityPub support is enabled for GatherPress.
|
|
$aec = \Event_Bridge_For_ActivityPub\Setup::get_instance();
|
|
$aec->activate_activitypub_support_for_active_event_plugins();
|
|
|
|
// Add event sources (ActivityPub followers).
|
|
_delete_all_posts();
|
|
\Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source::init_from_array( self::FOLLOWED_ACTOR_1 )->save();
|
|
\Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source::init_from_array( self::FOLLOWED_ACTOR_2 )->save();
|
|
|
|
\update_option( 'event_bridge_for_activitypub_event_sources_active', true );
|
|
\update_option(
|
|
'event_bridge_for_activitypub_integration_used_for_event_sources_feature',
|
|
\Event_Bridge_For_ActivityPub\Integrations\GatherPress::class
|
|
);
|
|
\update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE );
|
|
}
|
|
|
|
/**
|
|
* Testing the fetching of event sources from the database.
|
|
*
|
|
* @covers \Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources::get_event_sources_with_count
|
|
* @covers \Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources::get_event_sources
|
|
*/
|
|
public function test_get_event_sources_with_count() {
|
|
\delete_transient( 'event_bridge_for_activitypub_event_sources' );
|
|
$event_sources = \Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources::get_event_sources();
|
|
|
|
$this->assertCount( 2, $event_sources );
|
|
|
|
$this->assertArrayHasKey( self::FOLLOWED_ACTOR_1['id'], $event_sources );
|
|
$this->assertArrayHasKey( self::FOLLOWED_ACTOR_2['id'], $event_sources );
|
|
}
|
|
}
|