phpcs
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 51s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 1m2s
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 56s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 53s

This commit is contained in:
André Menrath 2024-12-21 10:57:42 +01:00
parent e494aba31e
commit f413bb38d3
18 changed files with 447 additions and 134 deletions

View file

@ -61,7 +61,7 @@
], ],
"test-debug": [ "test-debug": [
"@prepare-test", "@prepare-test",
"@test-event-sources" "@test-gatherpress"
], ],
"test-vs-event-list": "phpunit --filter=vs_event_list", "test-vs-event-list": "phpunit --filter=vs_event_list",
"test-the-events-calendar": "phpunit --filter=the_events_calendar", "test-the-events-calendar": "phpunit --filter=the_events_calendar",

View file

@ -56,7 +56,7 @@ abstract class Base {
$post_id = $this->save_event(); $post_id = $this->save_event();
if ( $post_id ) { if ( $post_id ) {
update_post_meta( $post_id, 'event_bridge_for_activitypub_is_cached', 'yes' ); update_post_meta( $post_id, '_event_bridge_for_activitypub_is_cached', true );
update_post_meta( $post_id, 'activitypub_content_visibility', constant( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL' ) ?? '' ); update_post_meta( $post_id, 'activitypub_content_visibility', constant( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL' ) ?? '' );
} }
} }

View file

@ -131,8 +131,8 @@ class GatherPress extends Base {
$args = array( $args = array(
'post_title' => sanitize_text_field( $this->activitypub_event->get_name() ), 'post_title' => sanitize_text_field( $this->activitypub_event->get_name() ),
'post_type' => 'gatherpress_event', 'post_type' => 'gatherpress_event',
'post_content' => wp_kses_post( $this->activitypub_event->get_content() ) . '<!-- wp:gatherpress/venue /-->', 'post_content' => wp_kses_post( $this->activitypub_event->get_content() ?? '' ) . '<!-- wp:gatherpress/venue /-->',
'post_excerpt' => wp_kses_post( $this->activitypub_event->get_summary() ), 'post_excerpt' => wp_kses_post( $this->activitypub_event->get_summary() ?? '' ),
'post_status' => 'publish', 'post_status' => 'publish',
'guid' => sanitize_url( $this->activitypub_event->get_id() ), 'guid' => sanitize_url( $this->activitypub_event->get_id() ),
); );

View file

@ -71,7 +71,7 @@ class Event_Sources {
} }
\register_post_meta( \register_post_meta(
$event_plugin_integration::get_post_type(), $event_plugin_integration::get_post_type(),
'event_bridge_for_activitypub_is_cached', '_event_bridge_for_activitypub_is_cached',
array( array(
'type' => 'string', 'type' => 'string',
'single' => false, 'single' => false,
@ -159,7 +159,7 @@ class Event_Sources {
* @return bool * @return bool
*/ */
public static function is_cached_external_event_post( $post ): bool { public static function is_cached_external_event_post( $post ): bool {
if ( get_post_meta( $post->ID, 'event_bridge_for_activitypub_is_cached', true ) ) { if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_is_cached', true ) ) {
return true; return true;
} }

View file

@ -116,7 +116,7 @@ final class GatherPress extends Event_Plugin_Integration implements Feature_Even
if ( $post && 'gatherpress_event' === $post->post_type ) { if ( $post && 'gatherpress_event' === $post->post_type ) {
// Add your custom logic here to decide whether to force the link. // Add your custom logic here to decide whether to force the link.
// For example, force it only if a specific meta field exists. // For example, force it only if a specific meta field exists.
if ( get_post_meta( $post->ID, 'event_bridge_for_activitypub_is_cached', true ) ) { if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_is_cached', true ) ) {
return true; // Force the online event link. return true; // Force the online event link.
} }
} }

View file

@ -6,9 +6,9 @@
*/ */
// Defined here because setting them in .wp-env.json doesn't work for some reason. // Defined here because setting them in .wp-env.json doesn't work for some reason.
\define( 'WP_TESTS_DOMAIN', 'example.org' ); \defined( 'WP_TESTS_DOMAIN' ) ?? \define( 'WP_TESTS_DOMAIN', 'example.org' );
\define( 'WP_SITEURL', 'http://example.org' ); \defined( 'WP_SITEURL' ) ?? \define( 'WP_SITEURL', 'http://example.org' );
\define( 'WP_HOME', 'http://example.org' ); \defined( 'WP_HOME' ) ?? \define( 'WP_HOME', 'http://example.org' );
$_tests_dir = getenv( 'WP_TESTS_DIR' ); $_tests_dir = getenv( 'WP_TESTS_DIR' );
@ -87,6 +87,9 @@ function _manually_load_plugin() {
break; break;
case 'gatherpress': case 'gatherpress':
$plugin_file = 'gatherpress/gatherpress.php'; $plugin_file = 'gatherpress/gatherpress.php';
\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 );
break; break;
case 'wp_event_manager': case 'wp_event_manager':
$plugin_file = 'wp-event-manager/wp-event-manager.php'; $plugin_file = 'wp-event-manager/wp-event-manager.php';
@ -105,7 +108,7 @@ function _manually_load_plugin() {
// For the Event Sources feature we currently only test with GatherPress. // For the Event Sources feature we currently only test with GatherPress.
_manually_load_event_plugin( 'gatherpress/gatherpress.php' ); _manually_load_event_plugin( 'gatherpress/gatherpress.php' );
\update_option( 'event_bridge_for_activitypub_event_sources_active', true ); \update_option( 'event_bridge_for_activitypub_event_sources_active', true );
\update_option( 'event_bridge_for_activitypub_plugin_used_for_event_source_feature', 'GatherPress' ); \update_option( 'event_bridge_for_activitypub_integration_used_for_event_sources_feature', 'GatherPress' );
\update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE ); \update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE );
} else { } else {
// For all other tests we mainly use the Events Calendar as a reference. // For all other tests we mainly use the Events Calendar as a reference.

View file

@ -28,7 +28,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
$aec->activate_activitypub_support_for_active_event_plugins(); $aec->activate_activitypub_support_for_active_event_plugins();
// Run the install script just in time which makes sure the custom tables exist and more. // Run the install script just in time which makes sure the custom tables exist and more.
eventorganiser_install(); \eventorganiser_install();
// Delete all posts afterwards. // Delete all posts afterwards.
_delete_all_posts(); _delete_all_posts();
@ -48,8 +48,8 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
$this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) ); $this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) );
$event_data = array( $event_data = array(
'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), 'start' => new DateTime( '+10 days 15:00:00', \eo_get_blog_timezone() ),
'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ), 'end' => new DateTime( '+10 days 16:00:00', \eo_get_blog_timezone() ),
'all_day' => 0, 'all_day' => 0,
'schedule' => 'once', 'schedule' => 'once',
); );
@ -60,7 +60,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
'post_status' => 'publish', 'post_status' => 'publish',
); );
$post_id = eo_insert_event( $post_data, $event_data ); $post_id = \eo_insert_event( $post_data, $event_data );
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) ); $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) );
@ -87,7 +87,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
'post_status' => 'publish', 'post_status' => 'publish',
); );
$post_id = eo_insert_event( $post_data, $event_data ); $post_id = \eo_insert_event( $post_data, $event_data );
// Call the transformer Factory. // Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array();
@ -95,9 +95,9 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
// Check that the event ActivityStreams representation contains everything as expected. // Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Unit Test Event', $event_array['name'] ); $this->assertEquals( 'Unit Test Event', $event_array['name'] );
$this->assertEquals( 'Unit Test description.', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Unit Test description.', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array ); $this->assertArrayNotHasKey( 'location', $event_array );
} }
@ -118,7 +118,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
'longitude' => 15.421371, 'longitude' => 15.421371,
); );
$venue_name = 'Fediverse Venue'; $venue_name = 'Fediverse Venue';
$venue = eo_insert_venue( $venue_name, $venue_args ); $venue = \eo_insert_venue( $venue_name, $venue_args );
// Mock Event. // Mock Event.
$event_data = array( $event_data = array(
@ -132,8 +132,8 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
'post_content' => 'Unit Test description.', 'post_content' => 'Unit Test description.',
'post_status' => 'publish', 'post_status' => 'publish',
); );
$post_id = eo_insert_event( $post_data, $event_data ); $post_id = \eo_insert_event( $post_data, $event_data );
wp_set_object_terms( $post_id, $venue['term_id'], 'event-venue' ); \wp_set_object_terms( $post_id, $venue['term_id'], 'event-venue' );
// Call the transformer Factory. // Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array();
@ -141,12 +141,12 @@ class Test_Event_Organiser extends \WP_UnitTestCase {
// Check that the event ActivityStreams representation contains everything as expected. // Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Unit Test Event', $event_array['name'] ); $this->assertEquals( 'Unit Test Event', $event_array['name'] );
$this->assertEquals( 'Unit Test description.', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Unit Test description.', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayHasKey( 'location', $event_array ); $this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( $venue_args['description'], wp_strip_all_tags( $event_array['location']['content'] ) ); $this->assertEquals( $venue_args['description'], \wp_strip_all_tags( $event_array['location']['content'] ) );
$this->assertEquals( $venue_args['address'], $event_array['location']['address']['streetAddress'] ); $this->assertEquals( $venue_args['address'], $event_array['location']['address']['streetAddress'] );
$this->assertEquals( $venue_args['city'], $event_array['location']['address']['addressLocality'] ); $this->assertEquals( $venue_args['city'], $event_array['location']['address']['addressLocality'] );
$this->assertEquals( $venue_args['state'], $event_array['location']['address']['addressRegion'] ); $this->assertEquals( $venue_args['state'], $event_array['location']['address']['addressRegion'] );

View file

@ -8,6 +8,8 @@
namespace Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer; namespace Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer;
use Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer\Test_The_Events_Calendar;
/** /**
* Test class for Shortcodes. * Test class for Shortcodes.
*/ */
@ -49,15 +51,15 @@ class Test_Event extends \WP_UnitTestCase {
$transformer->register_shortcodes(); $transformer->register_shortcodes();
$summary = '[ap_start_time]'; $summary = '[ap_start_time]';
$summary = do_shortcode( $summary ); $summary = \do_shortcode( $summary );
$this->assertEquals( '🗓️ Start: December 1, 2024 3:00 pm', $summary ); $this->assertEquals( '🗓️ Start: December 1, 2024 3:00 pm', $summary );
$summary = '[ap_start_time icon="false"]'; $summary = '[ap_start_time icon="false"]';
$summary = do_shortcode( $summary ); $summary = \do_shortcode( $summary );
$this->assertEquals( 'Start: December 1, 2024 3:00 pm', $summary ); $this->assertEquals( 'Start: December 1, 2024 3:00 pm', $summary );
$summary = '[ap_start_time icon="false" label="false"]'; $summary = '[ap_start_time icon="false" label="false"]';
$summary = do_shortcode( $summary ); $summary = \do_shortcode( $summary );
$this->assertEquals( 'December 1, 2024 3:00 pm', $summary ); $this->assertEquals( 'December 1, 2024 3:00 pm', $summary );
$transformer->unregister_shortcodes(); $transformer->unregister_shortcodes();
@ -82,15 +84,15 @@ class Test_Event extends \WP_UnitTestCase {
$transformer->register_shortcodes(); $transformer->register_shortcodes();
$summary = '[ap_end_time]'; $summary = '[ap_end_time]';
$summary = do_shortcode( $summary ); $summary = \do_shortcode( $summary );
$this->assertEquals( '⏳ End: December 1, 2024 4:00 pm', $summary ); $this->assertEquals( '⏳ End: December 1, 2024 4:00 pm', $summary );
$summary = '[ap_end_time icon="false"]'; $summary = '[ap_end_time icon="false"]';
$summary = do_shortcode( $summary ); $summary = \do_shortcode( $summary );
$this->assertEquals( 'End: December 1, 2024 4:00 pm', $summary ); $this->assertEquals( 'End: December 1, 2024 4:00 pm', $summary );
$summary = '[ap_end_time icon="false" label="false"]'; $summary = '[ap_end_time icon="false" label="false"]';
$summary = do_shortcode( $summary ); $summary = \do_shortcode( $summary );
$this->assertEquals( 'December 1, 2024 4:00 pm', $summary ); $this->assertEquals( 'December 1, 2024 4:00 pm', $summary );
$transformer->unregister_shortcodes(); $transformer->unregister_shortcodes();

View file

@ -56,7 +56,7 @@ class Test_Eventin extends \WP_UnitTestCase {
$this->assertEquals( 1, count( $active_event_plugins ) ); $this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin. // Enable ActivityPub support for the event plugin.
$this->assertContains( 'etn', get_option( 'activitypub_support_post_types' ) ); $this->assertContains( 'etn', \get_option( 'activitypub_support_post_types' ) );
// Create a Eventin Event without content. // Create a Eventin Event without content.
$event = new \Etn\Core\Event\Event_Model(); $event = new \Etn\Core\Event\Event_Model();
@ -161,12 +161,12 @@ class Test_Eventin extends \WP_UnitTestCase {
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Eventin Test Event Title', $event_array['name'] ); $this->assertEquals( 'Eventin Test Event Title', $event_array['name'] );
$this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Eventin Test Event Description', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] );
$this->assertEquals( 'Europe/Vienna', $event_array['timezone'] ); $this->assertEquals( 'Europe/Vienna', $event_array['timezone'] );
$this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] ); $this->assertEquals( \comments_open( $event->id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( \comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayHasKey( 'location', $event_array ); $this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );

View file

@ -46,7 +46,7 @@ class Test_Events_Manager extends \WP_UnitTestCase {
$this->assertContains( EM_POST_TYPE_EVENT, get_option( 'activitypub_support_post_types' ) ); $this->assertContains( EM_POST_TYPE_EVENT, get_option( 'activitypub_support_post_types' ) );
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'Events Manager Test event', 'post_title' => 'Events Manager Test event',
'post_status' => 'publish', 'post_status' => 'publish',
@ -57,7 +57,7 @@ class Test_Events_Manager extends \WP_UnitTestCase {
) )
); );
$wp_object = get_post( $wp_post_id ); $wp_object = \get_post( $wp_post_id );
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
@ -102,7 +102,7 @@ class Test_Events_Manager extends \WP_UnitTestCase {
*/ */
public function test_transform_of__full_event_with_location() { public function test_transform_of__full_event_with_location() {
// Create a mockup location. // Create a mockup location.
$location = new EM_Location(); $location = new \EM_Location();
$location->location_name = 'Test location'; $location->location_name = 'Test location';
$location->location_address = 'Test Address'; $location->location_address = 'Test Address';
$location->location_town = 'Test Town'; $location->location_town = 'Test Town';
@ -113,7 +113,7 @@ class Test_Events_Manager extends \WP_UnitTestCase {
$this->assertTrue( $location->save() ); $this->assertTrue( $location->save() );
// Create mockup event. // Create mockup event.
$event = new EM_Event(); $event = new \EM_Event();
$event->event_name = 'Events Manager Test event'; $event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description'; $event->post_content = 'Event description';
$event->location_id = $location->location_id; $event->location_id = $location->location_id;
@ -151,21 +151,21 @@ class Test_Events_Manager extends \WP_UnitTestCase {
*/ */
public function test_transform_of_event_with_name_only_location() { public function test_transform_of_event_with_name_only_location() {
// Create a mockup location. // Create a mockup location.
$location = new EM_Location(); $location = new \EM_Location();
$location->location_name = 'Name only location'; $location->location_name = 'Name only location';
$this->assertTrue( $location->save() ); $this->assertTrue( $location->save() );
// Create mockup event. // Create mockup event.
$event = new EM_Event(); $event = new \EM_Event();
$event->event_name = 'Events Manager Test event'; $event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description'; $event->post_content = 'Event description';
$event->location_id = $location->location_id; $event->location_id = $location->location_id;
$event->event_start_date = gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ); $event->event_start_date = \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) );
$event->event_end_date = gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ); $event->event_end_date = \gmdate( 'Y-m-d', \strtotime( '+10 days 16:00:00' ) );
$event->event_start_time = '15:00:00'; $event->event_start_time = '15:00:00';
$event->event_end_time = '16:00:00'; $event->event_end_time = '16:00:00';
$event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time ); $event->start = \strtotime( $event->event_start_date . ' ' . $event->event_start_time );
$event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time ); $event->end = \strtotime( $event->event_end_date . ' ' . $event->event_end_time );
$event->force_status = 'publish'; $event->force_status = 'publish';
$event->event_rsvp = false; $event->event_rsvp = false;
$this->assertTrue( $event->save() ); $this->assertTrue( $event->save() );
@ -177,7 +177,7 @@ class Test_Events_Manager extends \WP_UnitTestCase {
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Events Manager Test event', $event_array['name'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] );
$this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Event description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertArrayHasKey( 'location', $event_array ); $this->assertArrayHasKey( 'location', $event_array );

View file

@ -22,9 +22,9 @@ class Test_GatherPress extends \WP_UnitTestCase {
} }
// Mock the plugin activation. // Mock the plugin activation.
GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false ); \GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false );
// Make sure that ActivityPub support is enabled for The Events Calendar. // Make sure that ActivityPub support is enabled for GatherPress.
$aec = \Event_Bridge_For_ActivityPub\Setup::get_instance(); $aec = \Event_Bridge_For_ActivityPub\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins(); $aec->activate_activitypub_support_for_active_event_plugins();

View file

@ -49,7 +49,7 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
$this->assertEquals( 1, count( $active_event_plugins ) ); $this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin. // Enable ActivityPub support for the event plugin.
$this->assertContains( 'mec-events', get_option( 'activitypub_support_post_types' ) ); $this->assertContains( 'mec-events', \get_option( 'activitypub_support_post_types' ) );
// Insert a new Event. // Insert a new Event.
$event = array( $event = array(
@ -70,7 +70,7 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
$post_id = $this->mec_main->save_event( $event ); $post_id = $this->mec_main->save_event( $event );
$wp_object = get_post( $post_id ); $wp_object = \get_post( $post_id );
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
@ -83,22 +83,22 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
* Test that the transformation of minimal event. * Test that the transformation of minimal event.
*/ */
public function test_modern_events_calendar_lite_minimal_event() { public function test_modern_events_calendar_lite_minimal_event() {
$start_timestamp = strtotime( '+10 days 15:00:00' ); $start_timestamp = \strtotime( '+10 days 15:00:00' );
$end_timestamp = strtotime( '+10 days 16:00:00' ); $end_timestamp = \strtotime( '+10 days 16:00:00' );
// Insert a new Event. // Insert a new Event.
$event = array( $event = array(
'title' => 'MEC Test Event', 'title' => 'MEC Test Event',
'status' => 'publish', 'status' => 'publish',
'content' => 'This is the content of the MEC!', 'content' => 'This is the content of the MEC!',
'start_time_hour' => gmdate( 'h', $start_timestamp ), 'start_time_hour' => \gmdate( 'h', $start_timestamp ),
'start_time_minutes' => gmdate( 'i', $start_timestamp ), 'start_time_minutes' => \gmdate( 'i', $start_timestamp ),
'start_time_ampm' => gmdate( 'A', $start_timestamp ), 'start_time_ampm' => \gmdate( 'A', $start_timestamp ),
'start' => gmdate( 'Y-m-d', $start_timestamp ), 'start' => \gmdate( 'Y-m-d', $start_timestamp ),
'end' => gmdate( 'Y-m-d', $end_timestamp ), 'end' => \gmdate( 'Y-m-d', $end_timestamp ),
'end_time_hour' => gmdate( 'h', $end_timestamp ), 'end_time_hour' => \gmdate( 'h', $end_timestamp ),
'end_time_minutes' => gmdate( 'i', $end_timestamp ), 'end_time_minutes' => \gmdate( 'i', $end_timestamp ),
'end_time_ampm' => gmdate( 'A', $end_timestamp ), 'end_time_ampm' => \gmdate( 'A', $end_timestamp ),
'repeat_status' => 0, 'repeat_status' => 0,
'repeat_type' => 'daily', 'repeat_type' => 'daily',
'interval' => 1, 'interval' => 1,
@ -106,16 +106,16 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
$post_id = $this->mec_main->save_event( $event ); $post_id = $this->mec_main->save_event( $event );
$wp_object = get_post( $post_id ); $wp_object = \get_post( $post_id );
// Call the transformer to make the ActivityStreams representation of the event. // Call the transformer to make the ActivityStreams representation of the event.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'MEC Test Event', $event_array['name'] ); $this->assertEquals( 'MEC Test Event', $event_array['name'] );
$this->assertEquals( 'This is the content of the MEC!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'This is the content of the MEC!', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertTrue( $event_array['commentsEnabled'] ); $this->assertTrue( $event_array['commentsEnabled'] );
$this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] ); $this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
@ -128,8 +128,8 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
* Test that the transformation of minimal event. * Test that the transformation of minimal event.
*/ */
public function test_modern_events_calendar_lite_event_with_location() { public function test_modern_events_calendar_lite_event_with_location() {
$start_timestamp = strtotime( '+10 days 15:00:00' ); $start_timestamp = \strtotime( '+10 days 15:00:00' );
$end_timestamp = strtotime( '+10 days 16:00:00' ); $end_timestamp = \strtotime( '+10 days 16:00:00' );
// Add new location. // Add new location.
$location = array( $location = array(
@ -147,14 +147,14 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
'title' => 'MEC Test Event', 'title' => 'MEC Test Event',
'status' => 'publish', 'status' => 'publish',
'content' => 'This is the content of the MEC!', 'content' => 'This is the content of the MEC!',
'start_time_hour' => gmdate( 'h', $start_timestamp ), 'start_time_hour' => \gmdate( 'h', $start_timestamp ),
'start_time_minutes' => gmdate( 'i', $start_timestamp ), 'start_time_minutes' => \gmdate( 'i', $start_timestamp ),
'start_time_ampm' => gmdate( 'A', $start_timestamp ), 'start_time_ampm' => \gmdate( 'A', $start_timestamp ),
'start' => gmdate( 'Y-m-d', $start_timestamp ), 'start' => \gmdate( 'Y-m-d', $start_timestamp ),
'end' => gmdate( 'Y-m-d', $end_timestamp ), 'end' => \gmdate( 'Y-m-d', $end_timestamp ),
'end_time_hour' => gmdate( 'h', $end_timestamp ), 'end_time_hour' => \gmdate( 'h', $end_timestamp ),
'end_time_minutes' => gmdate( 'i', $end_timestamp ), 'end_time_minutes' => \gmdate( 'i', $end_timestamp ),
'end_time_ampm' => gmdate( 'A', $end_timestamp ), 'end_time_ampm' => \gmdate( 'A', $end_timestamp ),
'repeat_status' => 0, 'repeat_status' => 0,
'repeat_type' => 'daily', 'repeat_type' => 'daily',
'interval' => 1, 'interval' => 1,
@ -163,20 +163,20 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase {
$post_id = $this->mec_main->save_event( $event ); $post_id = $this->mec_main->save_event( $event );
$wp_object = get_post( $post_id ); $wp_object = \get_post( $post_id );
// Call the transformer to make the ActivityStreams representation of the event. // Call the transformer to make the ActivityStreams representation of the event.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'MEC Test Event', $event_array['name'] ); $this->assertEquals( 'MEC Test Event', $event_array['name'] );
$this->assertEquals( 'This is the content of the MEC!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'This is the content of the MEC!', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertTrue( $event_array['commentsEnabled'] ); $this->assertTrue( $event_array['commentsEnabled'] );
$this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] ); $this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( get_permalink( $wp_object ), $event_array['externalParticipationUrl'] ); $this->assertEquals( \get_permalink( $wp_object ), $event_array['externalParticipationUrl'] );
$this->assertArrayHasKey( 'location', $event_array ); $this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertEquals( $location['address'], $event_array['location']['address'] ); $this->assertEquals( $location['address'], $event_array['location']['address'] );

View file

@ -40,21 +40,21 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
$this->assertEquals( 1, count( $active_event_plugins ) ); $this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin. // Enable ActivityPub support for the event plugin.
$this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) ); $this->assertContains( 'event', \get_option( 'activitypub_support_post_types' ) );
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'VSEL Test Event', 'post_title' => 'VSEL Test Event',
'post_status' => 'publish', 'post_status' => 'publish',
'post_type' => 'event', 'post_type' => 'event',
'meta_input' => array( 'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ), 'event-start-date' => \strtotime( '+10 days 15:00:00' ),
), ),
) )
); );
$wp_object = get_post( $wp_post_id ); $wp_object = \get_post( $wp_post_id );
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
@ -68,7 +68,7 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
*/ */
public function test_transform_of_minimal_event() { public function test_transform_of_minimal_event() {
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'VSEL Test Event', 'post_title' => 'VSEL Test Event',
'post_status' => 'publish', 'post_status' => 'publish',
@ -86,12 +86,12 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'VSEL Test Event', $event_array['name'] ); $this->assertEquals( 'VSEL Test Event', $event_array['name'] );
$this->assertEquals( '', $event_array['content'] ); $this->assertEquals( '', $event_array['content'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertArrayNotHasKey( 'endTime', $event_array ); $this->assertArrayNotHasKey( 'endTime', $event_array );
$this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); $this->assertEquals( \comments_open( $wp_post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); $this->assertEquals( \esc_url( \get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] );
$this->assertArrayNotHasKey( 'location', $event_array ); $this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );
} }
@ -101,14 +101,14 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
*/ */
public function test_transform_of_full_event() { public function test_transform_of_full_event() {
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'VSEL Test Event', 'post_title' => 'VSEL Test Event',
'post_status' => 'publish', 'post_status' => 'publish',
'post_type' => 'event', 'post_type' => 'event',
'meta_input' => array( 'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ), 'event-start-date' => \strtotime( '+10 days 15:00:00' ),
'event-date' => strtotime( '+10 days 16:00:00' ), 'event-date' => \strtotime( '+10 days 16:00:00' ),
'event-link' => 'https://event-federation.eu/vsel-test-event', 'event-link' => 'https://event-federation.eu/vsel-test-event',
'event-link-label' => 'Website', 'event-link-label' => 'Website',
), ),
@ -122,12 +122,12 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'VSEL Test Event', $event_array['name'] ); $this->assertEquals( 'VSEL Test Event', $event_array['name'] );
$this->assertEquals( '', $event_array['content'] ); $this->assertEquals( '', $event_array['content'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); $this->assertEquals( \comments_open( $wp_post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); $this->assertEquals( \esc_url( \get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] );
$this->assertArrayNotHasKey( 'location', $event_array ); $this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertContains( $this->assertContains(
@ -146,7 +146,7 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
*/ */
public function test_transform_of_event_with_hidden_end_time() { public function test_transform_of_event_with_hidden_end_time() {
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'VSEL Test Event', 'post_title' => 'VSEL Test Event',
'post_status' => 'publish', 'post_status' => 'publish',
@ -171,8 +171,8 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
*/ */
public function test_transform_event_with_mapped_categories() { public function test_transform_event_with_mapped_categories() {
// Create category. // Create category.
$category_id_music = wp_insert_term( 'Music', 'event_cat', array( 'slug' => 'music' ) ); $category_id_music = \wp_insert_term( 'Music', 'event_cat', array( 'slug' => 'music' ) );
$category_id_theatre = wp_insert_term( 'Theatre', 'event_cat', array( 'slug' => 'theatre' ) ); $category_id_theatre = \wp_insert_term( 'Theatre', 'event_cat', array( 'slug' => 'theatre' ) );
// Set default mapping for event categories. // Set default mapping for event categories.
update_option( 'event_bridge_for_activitypub_default_event_category', 'MUSIC' ); update_option( 'event_bridge_for_activitypub_default_event_category', 'MUSIC' );
@ -187,13 +187,13 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
'post_status' => 'publish', 'post_status' => 'publish',
'post_type' => 'event', 'post_type' => 'event',
'meta_input' => array( 'meta_input' => array(
'event-start-date' => strtotime( '+10 days 15:00:00' ), 'event-start-date' => \strtotime( '+10 days 15:00:00' ),
'event-date' => strtotime( '+10 days 16:00:00' ), 'event-date' => \strtotime( '+10 days 16:00:00' ),
'event-hide-end-time' => 'yes', 'event-hide-end-time' => 'yes',
), ),
) )
); );
wp_set_post_terms( $wp_post_id, $category_id_music['term_id'], 'event_cat' ); \wp_set_post_terms( $wp_post_id, $category_id_music['term_id'], 'event_cat' );
// Call the transformer. // Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();
@ -202,7 +202,7 @@ class Test_VS_Event_List extends \WP_UnitTestCase {
$this->assertEquals( 'MUSIC', $event_array['category'] ); $this->assertEquals( 'MUSIC', $event_array['category'] );
// Change the event category to theatre. // Change the event category to theatre.
wp_set_post_terms( $wp_post_id, $category_id_theatre['term_id'], 'event_cat', false ); \wp_set_post_terms( $wp_post_id, $category_id_theatre['term_id'], 'event_cat', false );
// Call the transformer. // Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array();

View file

@ -5,7 +5,7 @@
* @package Event_Bridge_For_ActivityPub * @package Event_Bridge_For_ActivityPub
*/ */
namespace Event_Bridge_For_ActivityPub\Tests\ActivityPub\Transformer; namespace Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer;
/** /**
* Sample test case. * Sample test case.
@ -126,28 +126,28 @@ class Test_The_Events_Calendar extends \WP_UnitTestCase {
*/ */
public function test_transform_event_with_mapped_categories() { public function test_transform_event_with_mapped_categories() {
// Create category. // Create category.
$category_id_music = wp_insert_term( 'Music', Tribe__Events__Main::TAXONOMY, array( 'slug' => 'music' ) ); $category_id_music = wp_insert_term( 'Music', \Tribe__Events__Main::TAXONOMY, array( 'slug' => 'music' ) );
$category_id_theatre = wp_insert_term( 'Theatre', Tribe__Events__Main::TAXONOMY, array( 'slug' => 'theatre' ) ); $category_id_theatre = wp_insert_term( 'Theatre', \Tribe__Events__Main::TAXONOMY, array( 'slug' => 'theatre' ) );
// Set default mapping for event categories. // Set default mapping for event categories.
update_option( 'event_bridge_for_activitypub_default_event_category', 'MUSIC' ); \update_option( 'event_bridge_for_activitypub_default_event_category', 'MUSIC' );
// Set an override for the category with the slug theatre. // Set an override for the category with the slug theatre.
update_option( 'event_bridge_for_activitypub_event_category_mappings', array( 'theatre' => 'THEATRE' ) ); \update_option( 'event_bridge_for_activitypub_event_category_mappings', array( 'theatre' => 'THEATRE' ) );
// Create a The Events Calendar event with the music category. // Create a The Events Calendar event with the music category.
$wp_object = tribe_events() $wp_object = tribe_events()
->set_args( self::MOCKUP_EVENTS['minimal_event'] ) ->set_args( self::MOCKUP_EVENTS['minimal_event'] )
->create(); ->create();
// Set the post term music to the event. // Set the post term music to the event.
wp_set_post_terms( $wp_object->ID, $category_id_music['term_id'], Tribe__Events__Main::TAXONOMY ); wp_set_post_terms( $wp_object->ID, $category_id_music['term_id'], \Tribe__Events__Main::TAXONOMY );
// Call the transformer. // Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// See if the default category mapping is applied. // See if the default category mapping is applied.
$this->assertEquals( 'MUSIC', $event_array['category'] ); $this->assertEquals( 'MUSIC', $event_array['category'] );
// Set the post term theatre to the event. // Set the post term theatre to the event.
wp_set_post_terms( $wp_object->ID, $category_id_theatre['term_id'], Tribe__Events__Main::TAXONOMY, false ); wp_set_post_terms( $wp_object->ID, $category_id_theatre['term_id'], \Tribe__Events__Main::TAXONOMY, false );
// Call the transformer. // Call the transformer.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// See if the default category mapping is applied. // See if the default category mapping is applied.

View file

@ -54,7 +54,7 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase {
) )
); );
$wp_object = get_post( $wp_post_id ); $wp_object = \get_post( $wp_post_id );
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object ); $transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
@ -68,7 +68,7 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase {
*/ */
public function test_transform_of_minimal_event() { public function test_transform_of_minimal_event() {
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'WP Event Manager TestEvent', 'post_title' => 'WP Event Manager TestEvent',
'post_status' => 'publish', 'post_status' => 'publish',
@ -86,13 +86,13 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase {
// Check that the event ActivityStreams representation contains everything as expected. // Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] ); $this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] );
$this->assertEquals( 'Come to my WP Event Manager event!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Come to my WP Event Manager event!', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertArrayNotHasKey( 'endTime', $event_array ); $this->assertArrayNotHasKey( 'endTime', $event_array );
$this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); $this->assertEquals( \comments_open( $wp_post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); $this->assertEquals( \esc_url( \get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] );
$this->assertArrayNotHasKey( 'location', $event_array ); $this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );
} }
@ -102,7 +102,7 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase {
*/ */
public function test_transform_of_full_online_event() { public function test_transform_of_full_online_event() {
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'WP Event Manager TestEvent', 'post_title' => 'WP Event Manager TestEvent',
'post_status' => 'publish', 'post_status' => 'publish',
@ -149,15 +149,15 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase {
*/ */
public function test_transform_of_event_with_location() { public function test_transform_of_event_with_location() {
// Insert a new Event. // Insert a new Event.
$wp_post_id = wp_insert_post( $wp_post_id = \wp_insert_post(
array( array(
'post_title' => 'WP Event Manager TestEvent', 'post_title' => 'WP Event Manager TestEvent',
'post_status' => 'publish', 'post_status' => 'publish',
'post_type' => 'event_listing', 'post_type' => 'event_listing',
'post_content' => 'Come to my WP Event Manager event!', 'post_content' => 'Come to my WP Event Manager event!',
'meta_input' => array( 'meta_input' => array(
'_event_start_date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 15:00:00' ) ), '_event_start_date' => \gmdate( 'Y-m-d H:i:s', \strtotime( '+10 days 15:00:00' ) ),
'_event_end_date' => \gmdate( 'Y-m-d H:i:s', strtotime( '+10 days 16:00:00' ) ), '_event_end_date' => \gmdate( 'Y-m-d H:i:s', \strtotime( '+10 days 16:00:00' ) ),
'_event_location' => 'Some text location', '_event_location' => 'Some text location',
'_event_online' => 'no', '_event_online' => 'no',
), ),
@ -170,14 +170,14 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase {
// Check that the event ActivityStreams representation contains everything as expected. // Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] ); $this->assertEquals( 'WP Event Manager TestEvent', $event_array['name'] );
$this->assertEquals( 'Come to my WP Event Manager event!', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Come to my WP Event Manager event!', \wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( \gmdate( 'Y-m-d', \strtotime( '+10 days 15:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
$this->assertEquals( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); $this->assertEquals( \comments_open( $wp_post_id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( false, $event_array['isOnline'] ); $this->assertEquals( false, $event_array['isOnline'] );
$this->assertEquals( esc_url( get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] ); $this->assertEquals( \esc_url( \get_permalink( $wp_post_id ) ), $event_array['externalParticipationUrl'] );
$this->assertArrayHasKey( 'location', $event_array ); $this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Some text location', $event_array['location']['address'] ); $this->assertEquals( 'Some text location', $event_array['location']['address'] );
} }

View file

@ -0,0 +1,148 @@
<?php
/**
* Test file for the Transmogrifier (import of ActivityPub Event objects) of GatherPress.
*
* @package Event_Bridge_For_ActivityPub
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Event_Bridge_For_ActivityPub\Tests\ActivityPub\Transmogrifier;
use Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source;
use GatherPress\Core\Event;
use GatherPress\Core\Event_Query;
use WP_REST_Request;
use WP_REST_Server;
/**
* Test class for the Transmogrifier (import of ActivityPub Event objects) of GatherPress.
*
* @coversDefaultClass \Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier\GatherPress
*/
class Test_GatherPress 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',
);
/**
* Post ID.
*
* @var int
*/
protected static $event_source_post_id;
/**
* REST Server.
*
* @var WP_REST_Server
*/
protected $server;
/**
* Create fake data before tests run.
*/
public static function wpSetUpBeforeClass() {
// Follow actor.
$event_source = Event_Source::init_from_array( self::FOLLOWED_ACTOR );
$post_id = $event_source->save();
// Save the post ID for usage in tests.
self::$event_source_post_id = $post_id;
}
/**
* 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();
\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' );
\add_filter( 'activitypub_defer_signature_verification', '__return_false' );
}
/**
* Test receiving event from followed actor.
*/
public function test_incoming_event() {
\add_filter( 'activitypub_defer_signature_verification', '__return_true' );
$json = array(
'id' => 'https://remote.example/@organizer/events/new-year-party#create',
'type' => 'Create',
'actor' => 'https://remote.example/@organizer',
'object' => array(
'id' => 'https://remote.example/@organizer/events/new-year-party',
'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' => 'Fediverse Party',
'to' => 'https://www.w3.org/ns/activitystreams#Public',
'published' => '2020-01-01T00:00:00Z',
'location' => array(
'type' => 'Place',
'name' => 'Fediverse Concert Hall',
'address' => 'Fedistreet 13, Feditown 1337',
),
),
);
$request = new WP_REST_Request( 'POST', '/activitypub/1.0/users/0/inbox' );
$request->set_header( 'Content-Type', 'application/activity+json' );
$request->set_body( \wp_json_encode( $json ) );
// Dispatch the request.
$response = \rest_do_request( $request );
$this->assertEquals( 202, $response->get_status() );
// Check if post has been created.
$event_query = Event_Query::get_instance();
$the_query = $event_query->get_upcoming_events();
$this->assertEquals( true, $the_query->have_posts() );
$this->assertEquals( 1, $the_query->post_count );
// Initialize new GatherPress Event object.
$event = new Event( $the_query->get_posts()[0] );
$this->assertEquals( $json['object']['name'], $event->event->post_title );
$this->assertEquals( $json['object']['startTime'], $event->get_datetime_start( 'Y-m-d\TH:i:s\Z' ) );
$this->assertEquals( $json['object']['endTime'], $event->get_datetime_end( 'Y-m-d\TH:i:s\Z' ) );
$this->assertEquals( $json['object']['location']['address'], $event->get_venue_information()['full_address'] );
$this->assertEquals( $json['object']['location']['name'], $event->get_venue_information()['name'] );
$this->assertEquals( false, $event->get_venue_information()['is_online_event'] );
}
}

View file

@ -0,0 +1,160 @@
<?php
/**
* Test file for the Transmogrifier (import of ActivityPub Event objects) of GatherPress.
*
* @package Event_Bridge_For_ActivityPub
* @since 1.0.0
* @license AGPL-3.0-or-later
*/
namespace Event_Bridge_For_ActivityPub\Tests\ActivityPub\Transmogrifier;
use Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source;
use WP_REST_Request;
use WP_REST_Server;
/**
* Test class for the Transmogrifier (import of ActivityPub Event objects) of GatherPress.
*
* @coversDefaultClass \Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier\The_Events_Calendar
*/
class Test_The_Events_Calendar 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',
);
/**
* Post ID.
*
* @var int
*/
protected static $event_source_post_id;
/**
* REST Server.
*
* @var WP_REST_Server
*/
protected $server;
/**
* Create fake data before tests run.
*/
public static function wpSetUpBeforeClass() {
// Follow actor.
$event_source = Event_Source::init_from_array( self::FOLLOWED_ACTOR );
$post_id = $event_source->save();
// Save the post ID for usage in tests.
self::$event_source_post_id = $post_id;
}
/**
* Set up the test.
*/
public function set_up() {
if ( ! class_exists( '\Tribe__Events__Main' ) ) {
self::markTestSkipped( 'The Events Calendar 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 The Events Calendar.
$aec = \Event_Bridge_For_ActivityPub\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
\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\The_Events_Calendar::class
);
\update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE );
}
/**
* Tear down the test.
*/
public function tear_down() {
\delete_option( 'permalink_structure' );
\add_filter( 'activitypub_defer_signature_verification', '__return_false' );
}
/**
* Test receiving event from followed actor.
*/
public function test_incoming_event() {
\add_filter( 'activitypub_defer_signature_verification', '__return_true' );
$json = array(
'id' => 'https://remote.example/@organizer/events/new-year-party#create',
'type' => 'Create',
'actor' => 'https://remote.example/@organizer',
'object' => array(
'id' => 'https://remote.example/@organizer/events/new-year-party',
'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' => 'Fediverse Party',
'to' => 'https://www.w3.org/ns/activitystreams#Public',
'published' => '2020-01-01T00:00:00Z',
'location' => array(
'type' => 'Place',
'name' => 'Fediverse Concert Hall',
'address' => 'Fedistreet 13, Feditown 1337',
),
),
);
$request = new WP_REST_Request( 'POST', '/activitypub/1.0/users/0/inbox' );
$request->set_header( 'Content-Type', 'application/activity+json' );
$request->set_body( \wp_json_encode( $json ) );
// Dispatch the request.
$response = \rest_do_request( $request );
$this->assertEquals( 202, $response->get_status() );
// Check if post has been created.
$the_query = tribe_get_events();
$this->assertEquals( true, $the_query->have_posts() );
$this->assertEquals( 1, $the_query->post_count );
// Initialize new GatherPress Event object.
$event = tribe_get_event( $the_query->get_posts()[0] );
$this->assertEquals( $json['object']['name'], $event->post_title );
$this->assertEquals( $json['object']['startTime'], $event->start->format( 'Y-m-d\TH:i:s\Z' ) );
$this->assertEquals( $json['object']['endTime'], $event->end->format( 'Y-m-d\TH:i:s\Z' ) );
$venues = $event->venues;
// Get first venue. We currently only support a single venue.
if ( $venues instanceof \Tribe\Events\Collections\Lazy_Post_Collection ) {
$venue = $venues->first();
} elseif ( empty( $this->wp_object->venues ) || ! empty( $this->wp_object->venues[0] ) ) {
return null;
} else {
$venue = $venues[0];
}
$this->assertEquals( $json['object']['location']['address'], $venue->address );
$this->assertEquals( $json['object']['location']['name'], $venue->post_title );
\remove_filter( 'activitypub_defer_signature_verification', '__return_true' );
}
}

View file

@ -13,7 +13,7 @@ use WP_REST_Request;
use WP_REST_Server; use WP_REST_Server;
/** /**
* Test class for Activitypub Rest Inbox. * Test class for the Event Sources Feature.
* *
* @coversDefaultClass \Event_Bridge_For_ActivityPub\Event_Sources * @coversDefaultClass \Event_Bridge_For_ActivityPub\Event_Sources
*/ */
@ -48,9 +48,9 @@ class Test_Event_Sources extends \WP_UnitTestCase {
*/ */
public static function wpSetUpBeforeClass( $factory ) { public static function wpSetUpBeforeClass( $factory ) {
// Follow actor. // Follow actor.
$event_source = new \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source(); $event_source = \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source::init_from_array( self::FOLLOWED_ACTOR );
$event_source->from_array( self::FOLLOWED_ACTOR );
$post_id = $event_source->save(); $post_id = $event_source->save();
self::$event_source_post_id = $post_id; self::$event_source_post_id = $post_id;
} }