Add basic test for parsing of outbox
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 46s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m4s
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 46s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m4s
This commit is contained in:
parent
9a2dda0388
commit
6950d52264
1 changed files with 147 additions and 0 deletions
147
tests/includes/class-test-outbox-parser.php
Normal file
147
tests/includes/class-test-outbox-parser.php
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/**
|
||||
* Test file for the Outbox Parser Library.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\Tests;
|
||||
|
||||
use WP_REST_Server;
|
||||
|
||||
/**
|
||||
* Test class for the Outbox Parser Library.
|
||||
*
|
||||
* @coversDefaultClass \Event_Bridge_For_ActivityPub\Outbox_Parser
|
||||
*/
|
||||
class Test_Outbox_Parser extends \WP_UnitTestCase {
|
||||
const FOLLOWED_ACTOR = 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',
|
||||
);
|
||||
|
||||
/**
|
||||
* 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 source (ActivityPub follower).
|
||||
_delete_all_posts();
|
||||
\Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source::init_from_array( self::FOLLOWED_ACTOR )->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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down the test.
|
||||
*/
|
||||
public function tear_down() {
|
||||
\delete_option( 'permalink_structure' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the import of events from an items array of an outbox.
|
||||
*/
|
||||
public function test_import_events_from_items() {
|
||||
$items = array(
|
||||
array(
|
||||
'id' => 'https://remote.example/@organizer/events/concert#create',
|
||||
'type' => 'Create',
|
||||
'actor' => 'https://remote.example/@organizer',
|
||||
'object' => array(
|
||||
'id' => 'https://remote.example/@organizer/events/concert',
|
||||
'type' => 'Event',
|
||||
'startTime' => \gmdate( 'Y-m-d\TH:i:s\Z', time() + WEEK_IN_SECONDS ),
|
||||
'endTime' => \gmdate( 'Y-m-d\TH:i:s\Z', time() + WEEK_IN_SECONDS + HOUR_IN_SECONDS ),
|
||||
'name' => 'Concert',
|
||||
'to' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'published' => \gmdate( 'Y-m-d\TH:i:s\Z', time() - WEEK_IN_SECONDS ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'https://remote.example/@organizer/events/birthday-party#create',
|
||||
'type' => 'Create',
|
||||
'actor' => 'https://remote.example/@organizer',
|
||||
'object' => array(
|
||||
'id' => 'https://remote.example/@organizer/events/birthday-party',
|
||||
'type' => 'Event',
|
||||
'startTime' => \gmdate( 'Y-m-d\TH:i:s\Z', time() + 2 * WEEK_IN_SECONDS ),
|
||||
'endTime' => \gmdate( 'Y-m-d\TH:i:s\Z', time() + 2 * WEEK_IN_SECONDS + HOUR_IN_SECONDS ),
|
||||
'name' => 'Birthday Party',
|
||||
'to' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'published' => \gmdate( 'Y-m-d\TH:i:s\Z', time() - WEEK_IN_SECONDS ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'https://remote.example/@organizer/events/status/1#create',
|
||||
'type' => 'Create',
|
||||
'actor' => 'https://remote.example/@organizer',
|
||||
'object' => array(
|
||||
'id' => 'https://remote.example/@organizer/status/1',
|
||||
'type' => 'Note',
|
||||
'content' => 'This is a note',
|
||||
'to' => 'https://www.w3.org/ns/activitystreams#Public',
|
||||
'published' => \gmdate( 'Y-m-d\TH:i:s\Z', time() - WEEK_IN_SECONDS ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'https://remote.example/@organizer/likes/1',
|
||||
'type' => 'Like',
|
||||
'actor' => 'https://remote.example/@organizer',
|
||||
'object' => 'https://remote2.example/@actor/status/1',
|
||||
),
|
||||
array(
|
||||
'id' => 'https://remote.example/@organizer/shares/1',
|
||||
'type' => 'Announce',
|
||||
'actor' => 'https://remote.example/@organizer',
|
||||
'object' => 'https://remote2.example/@actor/status/2',
|
||||
),
|
||||
);
|
||||
$count = \Event_Bridge_For_ActivityPub\Outbox_Parser::import_events_from_items( $items, 'https://remote.example/@organizer' );
|
||||
|
||||
$this->assertEquals( 2, $count );
|
||||
|
||||
// Check that we have two event posts.
|
||||
$event_query = \GatherPress\Core\Event_Query::get_instance();
|
||||
$the_query = $event_query->get_upcoming_events();
|
||||
$this->assertEquals( 2, $the_query->post_count );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue