From f413bb38d30a225d647eb7567a0947eff8c19fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 21 Dec 2024 10:57:42 +0100 Subject: [PATCH] phpcs --- composer.json | 2 +- .../activitypub/transmogrifier/class-base.php | 2 +- .../transmogrifier/class-gatherpress.php | 4 +- includes/class-event-sources.php | 4 +- includes/integrations/class-gatherpress.php | 2 +- tests/bootstrap.php | 11 +- .../class-test-event-organiser.php | 30 ++-- .../transformer/class-test-event.php | 14 +- .../transformer/class-test-eventin.php | 12 +- .../transformer/class-test-events-manger.php | 22 +-- .../transformer/class-test-gatherpress.php | 4 +- ...class-test-modern-events-calendar-lite.php | 62 +++---- .../class-test-plugin-vs-event-list.php | 48 +++--- .../class-test-the-events-calendar.php | 14 +- .../class-test-wp-event-manager.php | 34 ++-- .../transmogrifier/class-test-gatherpress.php | 148 ++++++++++++++++ .../class-test-the-events-calendar.php | 160 ++++++++++++++++++ tests/includes/class-test-event-sources.php | 8 +- 18 files changed, 447 insertions(+), 134 deletions(-) create mode 100644 tests/includes/activitypub/transmogrifier/class-test-gatherpress.php create mode 100644 tests/includes/activitypub/transmogrifier/class-test-the-events-calendar.php diff --git a/composer.json b/composer.json index f38bc96..0f33ee4 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ ], "test-debug": [ "@prepare-test", - "@test-event-sources" + "@test-gatherpress" ], "test-vs-event-list": "phpunit --filter=vs_event_list", "test-the-events-calendar": "phpunit --filter=the_events_calendar", diff --git a/includes/activitypub/transmogrifier/class-base.php b/includes/activitypub/transmogrifier/class-base.php index 4b3f52a..517ae89 100644 --- a/includes/activitypub/transmogrifier/class-base.php +++ b/includes/activitypub/transmogrifier/class-base.php @@ -56,7 +56,7 @@ abstract class Base { $post_id = $this->save_event(); 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' ) ?? '' ); } } diff --git a/includes/activitypub/transmogrifier/class-gatherpress.php b/includes/activitypub/transmogrifier/class-gatherpress.php index 9420eb5..7567373 100644 --- a/includes/activitypub/transmogrifier/class-gatherpress.php +++ b/includes/activitypub/transmogrifier/class-gatherpress.php @@ -131,8 +131,8 @@ class GatherPress extends Base { $args = array( 'post_title' => sanitize_text_field( $this->activitypub_event->get_name() ), 'post_type' => 'gatherpress_event', - 'post_content' => wp_kses_post( $this->activitypub_event->get_content() ) . '', - 'post_excerpt' => wp_kses_post( $this->activitypub_event->get_summary() ), + 'post_content' => wp_kses_post( $this->activitypub_event->get_content() ?? '' ) . '', + 'post_excerpt' => wp_kses_post( $this->activitypub_event->get_summary() ?? '' ), 'post_status' => 'publish', 'guid' => sanitize_url( $this->activitypub_event->get_id() ), ); diff --git a/includes/class-event-sources.php b/includes/class-event-sources.php index e4b12aa..7019d3f 100644 --- a/includes/class-event-sources.php +++ b/includes/class-event-sources.php @@ -71,7 +71,7 @@ class Event_Sources { } \register_post_meta( $event_plugin_integration::get_post_type(), - 'event_bridge_for_activitypub_is_cached', + '_event_bridge_for_activitypub_is_cached', array( 'type' => 'string', 'single' => false, @@ -159,7 +159,7 @@ class Event_Sources { * @return 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; } diff --git a/includes/integrations/class-gatherpress.php b/includes/integrations/class-gatherpress.php index c54156d..87f5dae 100644 --- a/includes/integrations/class-gatherpress.php +++ b/includes/integrations/class-gatherpress.php @@ -116,7 +116,7 @@ final class GatherPress extends Event_Plugin_Integration implements Feature_Even if ( $post && 'gatherpress_event' === $post->post_type ) { // Add your custom logic here to decide whether to force the link. // 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. } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 35433bf..7ad614c 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,9 +6,9 @@ */ // Defined here because setting them in .wp-env.json doesn't work for some reason. -\define( 'WP_TESTS_DOMAIN', 'example.org' ); -\define( 'WP_SITEURL', 'http://example.org' ); -\define( 'WP_HOME', 'http://example.org' ); +\defined( 'WP_TESTS_DOMAIN' ) ?? \define( 'WP_TESTS_DOMAIN', 'example.org' ); +\defined( 'WP_SITEURL' ) ?? \define( 'WP_SITEURL', 'http://example.org' ); +\defined( 'WP_HOME' ) ?? \define( 'WP_HOME', 'http://example.org' ); $_tests_dir = getenv( 'WP_TESTS_DIR' ); @@ -87,6 +87,9 @@ function _manually_load_plugin() { break; case 'gatherpress': $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; case 'wp_event_manager': $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. _manually_load_event_plugin( 'gatherpress/gatherpress.php' ); \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 ); } else { // For all other tests we mainly use the Events Calendar as a reference. diff --git a/tests/includes/activitypub/transformer/class-test-event-organiser.php b/tests/includes/activitypub/transformer/class-test-event-organiser.php index ecced27..fc5dee5 100644 --- a/tests/includes/activitypub/transformer/class-test-event-organiser.php +++ b/tests/includes/activitypub/transformer/class-test-event-organiser.php @@ -28,7 +28,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase { $aec->activate_activitypub_support_for_active_event_plugins(); // 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(); @@ -48,8 +48,8 @@ class Test_Event_Organiser extends \WP_UnitTestCase { $this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) ); $event_data = array( - 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ), - 'end' => new DateTime( '+10 days 16: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() ), 'all_day' => 0, 'schedule' => 'once', ); @@ -60,7 +60,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase { '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. $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_id = eo_insert_event( $post_data, $event_data ); + $post_id = \eo_insert_event( $post_data, $event_data ); // Call the transformer Factory. $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. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Unit Test Event', $event_array['name'] ); - $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 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $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 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertArrayNotHasKey( 'location', $event_array ); } @@ -118,7 +118,7 @@ class Test_Event_Organiser extends \WP_UnitTestCase { 'longitude' => 15.421371, ); $venue_name = 'Fediverse Venue'; - $venue = eo_insert_venue( $venue_name, $venue_args ); + $venue = \eo_insert_venue( $venue_name, $venue_args ); // Mock Event. $event_data = array( @@ -132,8 +132,8 @@ class Test_Event_Organiser extends \WP_UnitTestCase { 'post_content' => 'Unit Test description.', 'post_status' => 'publish', ); - $post_id = eo_insert_event( $post_data, $event_data ); - wp_set_object_terms( $post_id, $venue['term_id'], 'event-venue' ); + $post_id = \eo_insert_event( $post_data, $event_data ); + \wp_set_object_terms( $post_id, $venue['term_id'], 'event-venue' ); // Call the transformer Factory. $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. $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Unit Test Event', $event_array['name'] ); - $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 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $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 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $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['city'], $event_array['location']['address']['addressLocality'] ); $this->assertEquals( $venue_args['state'], $event_array['location']['address']['addressRegion'] ); diff --git a/tests/includes/activitypub/transformer/class-test-event.php b/tests/includes/activitypub/transformer/class-test-event.php index ddabfe1..37e4d14 100644 --- a/tests/includes/activitypub/transformer/class-test-event.php +++ b/tests/includes/activitypub/transformer/class-test-event.php @@ -8,6 +8,8 @@ namespace Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer; +use Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer\Test_The_Events_Calendar; + /** * Test class for Shortcodes. */ @@ -49,15 +51,15 @@ class Test_Event extends \WP_UnitTestCase { $transformer->register_shortcodes(); $summary = '[ap_start_time]'; - $summary = do_shortcode( $summary ); + $summary = \do_shortcode( $summary ); $this->assertEquals( '🗓️ Start: December 1, 2024 3:00 pm', $summary ); $summary = '[ap_start_time icon="false"]'; - $summary = do_shortcode( $summary ); + $summary = \do_shortcode( $summary ); $this->assertEquals( 'Start: December 1, 2024 3:00 pm', $summary ); $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 ); $transformer->unregister_shortcodes(); @@ -82,15 +84,15 @@ class Test_Event extends \WP_UnitTestCase { $transformer->register_shortcodes(); $summary = '[ap_end_time]'; - $summary = do_shortcode( $summary ); + $summary = \do_shortcode( $summary ); $this->assertEquals( '⏳ End: December 1, 2024 4:00 pm', $summary ); $summary = '[ap_end_time icon="false"]'; - $summary = do_shortcode( $summary ); + $summary = \do_shortcode( $summary ); $this->assertEquals( 'End: December 1, 2024 4:00 pm', $summary ); $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 ); $transformer->unregister_shortcodes(); diff --git a/tests/includes/activitypub/transformer/class-test-eventin.php b/tests/includes/activitypub/transformer/class-test-eventin.php index fb1960f..019eb0e 100644 --- a/tests/includes/activitypub/transformer/class-test-eventin.php +++ b/tests/includes/activitypub/transformer/class-test-eventin.php @@ -56,7 +56,7 @@ class Test_Eventin extends \WP_UnitTestCase { $this->assertEquals( 1, count( $active_event_plugins ) ); // 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. $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( 'Eventin Test Event Title', $event_array['name'] ); - $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 16:00:00' ) ), $event_array['endTime'] ); + $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 16:00:00' ) ), $event_array['endTime'] ); $this->assertEquals( 'Europe/Vienna', $event_array['timezone'] ); - $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 ), $event_array['commentsEnabled'] ); + $this->assertEquals( \comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertArrayHasKey( 'location', $event_array ); $this->assertEquals( 'MEETING', $event_array['category'] ); diff --git a/tests/includes/activitypub/transformer/class-test-events-manger.php b/tests/includes/activitypub/transformer/class-test-events-manger.php index 9031f88..b5fb931 100644 --- a/tests/includes/activitypub/transformer/class-test-events-manger.php +++ b/tests/includes/activitypub/transformer/class-test-events-manger.php @@ -46,7 +46,7 @@ class Test_Events_Manager extends \WP_UnitTestCase { $this->assertContains( EM_POST_TYPE_EVENT, get_option( 'activitypub_support_post_types' ) ); // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'Events Manager Test event', '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. $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() { // Create a mockup location. - $location = new EM_Location(); + $location = new \EM_Location(); $location->location_name = 'Test location'; $location->location_address = 'Test Address'; $location->location_town = 'Test Town'; @@ -113,7 +113,7 @@ class Test_Events_Manager extends \WP_UnitTestCase { $this->assertTrue( $location->save() ); // Create mockup event. - $event = new EM_Event(); + $event = new \EM_Event(); $event->event_name = 'Events Manager Test event'; $event->post_content = 'Event description'; $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() { // Create a mockup location. - $location = new EM_Location(); + $location = new \EM_Location(); $location->location_name = 'Name only location'; $this->assertTrue( $location->save() ); // Create mockup event. - $event = new EM_Event(); + $event = new \EM_Event(); $event->event_name = 'Events Manager Test event'; $event->post_content = 'Event description'; $event->location_id = $location->location_id; - $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_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_start_time = '15:00:00'; $event->event_end_time = '16:00:00'; - $event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time ); - $event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time ); + $event->start = \strtotime( $event->event_start_date . ' ' . $event->event_start_time ); + $event->end = \strtotime( $event->event_end_date . ' ' . $event->event_end_time ); $event->force_status = 'publish'; $event->event_rsvp = false; $this->assertTrue( $event->save() ); @@ -177,7 +177,7 @@ class Test_Events_Manager extends \WP_UnitTestCase { $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Events Manager Test event', $event_array['name'] ); $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( 'MEETING', $event_array['category'] ); $this->assertArrayHasKey( 'location', $event_array ); diff --git a/tests/includes/activitypub/transformer/class-test-gatherpress.php b/tests/includes/activitypub/transformer/class-test-gatherpress.php index 58d70fb..a95058e 100644 --- a/tests/includes/activitypub/transformer/class-test-gatherpress.php +++ b/tests/includes/activitypub/transformer/class-test-gatherpress.php @@ -22,9 +22,9 @@ class Test_GatherPress extends \WP_UnitTestCase { } // 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->activate_activitypub_support_for_active_event_plugins(); diff --git a/tests/includes/activitypub/transformer/class-test-modern-events-calendar-lite.php b/tests/includes/activitypub/transformer/class-test-modern-events-calendar-lite.php index 35e3221..b58fe24 100644 --- a/tests/includes/activitypub/transformer/class-test-modern-events-calendar-lite.php +++ b/tests/includes/activitypub/transformer/class-test-modern-events-calendar-lite.php @@ -49,7 +49,7 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase { $this->assertEquals( 1, count( $active_event_plugins ) ); // 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. $event = array( @@ -70,7 +70,7 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase { $post_id = $this->mec_main->save_event( $event ); - $wp_object = get_post( $post_id ); + $wp_object = \get_post( $post_id ); // Call the transformer Factory. $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. */ public function test_modern_events_calendar_lite_minimal_event() { - $start_timestamp = strtotime( '+10 days 15:00:00' ); - $end_timestamp = strtotime( '+10 days 16:00:00' ); + $start_timestamp = \strtotime( '+10 days 15:00:00' ); + $end_timestamp = \strtotime( '+10 days 16:00:00' ); // Insert a new Event. $event = array( 'title' => 'MEC Test Event', 'status' => 'publish', 'content' => 'This is the content of the MEC!', - 'start_time_hour' => gmdate( 'h', $start_timestamp ), - 'start_time_minutes' => gmdate( 'i', $start_timestamp ), - 'start_time_ampm' => gmdate( 'A', $start_timestamp ), - 'start' => gmdate( 'Y-m-d', $start_timestamp ), - 'end' => gmdate( 'Y-m-d', $end_timestamp ), - 'end_time_hour' => gmdate( 'h', $end_timestamp ), - 'end_time_minutes' => gmdate( 'i', $end_timestamp ), - 'end_time_ampm' => gmdate( 'A', $end_timestamp ), + 'start_time_hour' => \gmdate( 'h', $start_timestamp ), + 'start_time_minutes' => \gmdate( 'i', $start_timestamp ), + 'start_time_ampm' => \gmdate( 'A', $start_timestamp ), + 'start' => \gmdate( 'Y-m-d', $start_timestamp ), + 'end' => \gmdate( 'Y-m-d', $end_timestamp ), + 'end_time_hour' => \gmdate( 'h', $end_timestamp ), + 'end_time_minutes' => \gmdate( 'i', $end_timestamp ), + 'end_time_ampm' => \gmdate( 'A', $end_timestamp ), 'repeat_status' => 0, 'repeat_type' => 'daily', 'interval' => 1, @@ -106,16 +106,16 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase { $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. $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); $this->assertEquals( 'Event', $event_array['type'] ); $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( 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( '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 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertTrue( $event_array['commentsEnabled'] ); $this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] ); $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. */ public function test_modern_events_calendar_lite_event_with_location() { - $start_timestamp = strtotime( '+10 days 15:00:00' ); - $end_timestamp = strtotime( '+10 days 16:00:00' ); + $start_timestamp = \strtotime( '+10 days 15:00:00' ); + $end_timestamp = \strtotime( '+10 days 16:00:00' ); // Add new location. $location = array( @@ -147,14 +147,14 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase { 'title' => 'MEC Test Event', 'status' => 'publish', 'content' => 'This is the content of the MEC!', - 'start_time_hour' => gmdate( 'h', $start_timestamp ), - 'start_time_minutes' => gmdate( 'i', $start_timestamp ), - 'start_time_ampm' => gmdate( 'A', $start_timestamp ), - 'start' => gmdate( 'Y-m-d', $start_timestamp ), - 'end' => gmdate( 'Y-m-d', $end_timestamp ), - 'end_time_hour' => gmdate( 'h', $end_timestamp ), - 'end_time_minutes' => gmdate( 'i', $end_timestamp ), - 'end_time_ampm' => gmdate( 'A', $end_timestamp ), + 'start_time_hour' => \gmdate( 'h', $start_timestamp ), + 'start_time_minutes' => \gmdate( 'i', $start_timestamp ), + 'start_time_ampm' => \gmdate( 'A', $start_timestamp ), + 'start' => \gmdate( 'Y-m-d', $start_timestamp ), + 'end' => \gmdate( 'Y-m-d', $end_timestamp ), + 'end_time_hour' => \gmdate( 'h', $end_timestamp ), + 'end_time_minutes' => \gmdate( 'i', $end_timestamp ), + 'end_time_ampm' => \gmdate( 'A', $end_timestamp ), 'repeat_status' => 0, 'repeat_type' => 'daily', 'interval' => 1, @@ -163,20 +163,20 @@ class Test_Modern_Events_Calendar_Lite extends \WP_UnitTestCase { $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. $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); $this->assertEquals( 'Event', $event_array['type'] ); $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( 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( '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 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] ); $this->assertTrue( $event_array['commentsEnabled'] ); $this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] ); $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->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( $location['address'], $event_array['location']['address'] ); diff --git a/tests/includes/activitypub/transformer/class-test-plugin-vs-event-list.php b/tests/includes/activitypub/transformer/class-test-plugin-vs-event-list.php index 4cb764d..278e565 100644 --- a/tests/includes/activitypub/transformer/class-test-plugin-vs-event-list.php +++ b/tests/includes/activitypub/transformer/class-test-plugin-vs-event-list.php @@ -40,21 +40,21 @@ class Test_VS_Event_List extends \WP_UnitTestCase { $this->assertEquals( 1, count( $active_event_plugins ) ); // 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. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'VSEL Test Event', 'post_status' => 'publish', 'post_type' => 'event', '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. $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() { // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'VSEL Test Event', 'post_status' => 'publish', @@ -86,12 +86,12 @@ class Test_VS_Event_List extends \WP_UnitTestCase { $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'VSEL Test Event', $event_array['name'] ); $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->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 ), $event_array['commentsEnabled'] ); + $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $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->assertEquals( 'MEETING', $event_array['category'] ); } @@ -101,14 +101,14 @@ class Test_VS_Event_List extends \WP_UnitTestCase { */ public function test_transform_of_full_event() { // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'VSEL Test Event', 'post_status' => 'publish', 'post_type' => 'event', 'meta_input' => array( - 'event-start-date' => strtotime( '+10 days 15:00:00' ), - 'event-date' => strtotime( '+10 days 16:00:00' ), + 'event-start-date' => \strtotime( '+10 days 15:00:00' ), + 'event-date' => \strtotime( '+10 days 16:00:00' ), 'event-link' => 'https://event-federation.eu/vsel-test-event', 'event-link-label' => 'Website', ), @@ -122,12 +122,12 @@ class Test_VS_Event_List extends \WP_UnitTestCase { $this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'VSEL Test Event', $event_array['name'] ); $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' ) ) . 'T16:00:00Z', $event_array['endTime'] ); - $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( \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( \comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); + $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $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->assertEquals( 'MEETING', $event_array['category'] ); $this->assertContains( @@ -146,7 +146,7 @@ class Test_VS_Event_List extends \WP_UnitTestCase { */ public function test_transform_of_event_with_hidden_end_time() { // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'VSEL Test Event', 'post_status' => 'publish', @@ -171,8 +171,8 @@ class Test_VS_Event_List extends \WP_UnitTestCase { */ public function test_transform_event_with_mapped_categories() { // Create category. - $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_music = \wp_insert_term( 'Music', 'event_cat', array( 'slug' => 'music' ) ); + $category_id_theatre = \wp_insert_term( 'Theatre', 'event_cat', array( 'slug' => 'theatre' ) ); // Set default mapping for event categories. 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_type' => 'event', 'meta_input' => array( - 'event-start-date' => strtotime( '+10 days 15:00:00' ), - 'event-date' => strtotime( '+10 days 16:00:00' ), + 'event-start-date' => \strtotime( '+10 days 15:00:00' ), + 'event-date' => \strtotime( '+10 days 16:00:00' ), '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. $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'] ); // 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. $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $wp_post_id ) )->to_object()->to_array(); diff --git a/tests/includes/activitypub/transformer/class-test-the-events-calendar.php b/tests/includes/activitypub/transformer/class-test-the-events-calendar.php index c01254e..f760c70 100644 --- a/tests/includes/activitypub/transformer/class-test-the-events-calendar.php +++ b/tests/includes/activitypub/transformer/class-test-the-events-calendar.php @@ -5,7 +5,7 @@ * @package Event_Bridge_For_ActivityPub */ -namespace Event_Bridge_For_ActivityPub\Tests\ActivityPub\Transformer; +namespace Event_Bridge_For_ActivityPup\Tests\ActivityPub\Transformer; /** * Sample test case. @@ -126,28 +126,28 @@ class Test_The_Events_Calendar extends \WP_UnitTestCase { */ public function test_transform_event_with_mapped_categories() { // Create category. - $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_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' ) ); // 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. - 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. $wp_object = tribe_events() ->set_args( self::MOCKUP_EVENTS['minimal_event'] ) ->create(); // 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. $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); // See if the default category mapping is applied. $this->assertEquals( 'MUSIC', $event_array['category'] ); // 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. $event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array(); // See if the default category mapping is applied. diff --git a/tests/includes/activitypub/transformer/class-test-wp-event-manager.php b/tests/includes/activitypub/transformer/class-test-wp-event-manager.php index 025c3fe..ec8e04e 100644 --- a/tests/includes/activitypub/transformer/class-test-wp-event-manager.php +++ b/tests/includes/activitypub/transformer/class-test-wp-event-manager.php @@ -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. $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() { // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'WP Event Manager TestEvent', '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. $this->assertEquals( 'Event', $event_array['type'] ); $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( gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ) . 'T15:00:00Z', $event_array['startTime'] ); + $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->assertArrayNotHasKey( 'endTime', $event_array ); - $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 ), $event_array['commentsEnabled'] ); + $this->assertEquals( \comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $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->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() { // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'WP Event Manager TestEvent', 'post_status' => 'publish', @@ -149,15 +149,15 @@ class Test_WP_Event_Manager extends \WP_UnitTestCase { */ public function test_transform_of_event_with_location() { // Insert a new Event. - $wp_post_id = wp_insert_post( + $wp_post_id = \wp_insert_post( array( 'post_title' => 'WP Event Manager TestEvent', 'post_status' => 'publish', 'post_type' => 'event_listing', 'post_content' => 'Come to my WP Event Manager event!', 'meta_input' => array( - '_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_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_location' => 'Some text location', '_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. $this->assertEquals( 'Event', $event_array['type'] ); $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( 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( comments_open( $wp_post_id ), $event_array['commentsEnabled'] ); - $this->assertEquals( comments_open( $wp_post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); + $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' ) ) . 'T16:00:00Z', $event_array['endTime'] ); + $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( 'external', $event_array['joinMode'] ); $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->assertEquals( 'Some text location', $event_array['location']['address'] ); } diff --git a/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php b/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php new file mode 100644 index 0000000..9141a01 --- /dev/null +++ b/tests/includes/activitypub/transmogrifier/class-test-gatherpress.php @@ -0,0 +1,148 @@ + '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'] ); + } +} diff --git a/tests/includes/activitypub/transmogrifier/class-test-the-events-calendar.php b/tests/includes/activitypub/transmogrifier/class-test-the-events-calendar.php new file mode 100644 index 0000000..6f59712 --- /dev/null +++ b/tests/includes/activitypub/transmogrifier/class-test-the-events-calendar.php @@ -0,0 +1,160 @@ + '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' ); + } +} diff --git a/tests/includes/class-test-event-sources.php b/tests/includes/class-test-event-sources.php index b9afeea..8209a32 100644 --- a/tests/includes/class-test-event-sources.php +++ b/tests/includes/class-test-event-sources.php @@ -13,7 +13,7 @@ use WP_REST_Request; use WP_REST_Server; /** - * Test class for Activitypub Rest Inbox. + * Test class for the Event Sources Feature. * * @coversDefaultClass \Event_Bridge_For_ActivityPub\Event_Sources */ @@ -48,9 +48,9 @@ class Test_Event_Sources extends \WP_UnitTestCase { */ public static function wpSetUpBeforeClass( $factory ) { // Follow actor. - $event_source = new \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source(); - $event_source->from_array( self::FOLLOWED_ACTOR ); - $post_id = $event_source->save(); + $event_source = \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source::init_from_array( self::FOLLOWED_ACTOR ); + $post_id = $event_source->save(); + self::$event_source_post_id = $post_id; }