2024-09-24 16:24:31 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class SampleTest
|
|
|
|
*
|
2024-10-02 21:54:03 +02:00
|
|
|
* @package ActivityPub_Event_Bridge
|
2024-09-24 16:24:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sample test case.
|
|
|
|
*/
|
|
|
|
class Test_The_Events_Calendar extends WP_UnitTestCase {
|
|
|
|
/**
|
|
|
|
* Mockup events of certain complexity.
|
|
|
|
*/
|
|
|
|
public const MOCKUP_VENUS = array(
|
|
|
|
'minimal_venue' => array(
|
|
|
|
'venue' => 'Minimal Venue',
|
|
|
|
'status' => 'publish',
|
|
|
|
),
|
|
|
|
'complex_venue' => array(
|
|
|
|
'venue' => 'Complex Venue',
|
|
|
|
'status' => 'publish',
|
|
|
|
'show_map' => false,
|
|
|
|
'show_map_link' => false,
|
|
|
|
'address' => 'Venue address',
|
|
|
|
'city' => 'Venue city',
|
|
|
|
'country' => 'Venue country',
|
|
|
|
'province' => 'Venue province',
|
|
|
|
'state' => 'Venue state',
|
|
|
|
'stateprovince' => 'Venue stateprovince',
|
|
|
|
'zip' => 'Venue zip',
|
|
|
|
'phone' => 'Venue phone',
|
|
|
|
'website' => 'http://venue.com',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
public const MOCKUP_EVENTS = array(
|
|
|
|
'minimal_event' => array(
|
|
|
|
'title' => 'My Event',
|
2024-10-02 19:15:28 +02:00
|
|
|
'content' => 'Come to my event!',
|
2024-09-24 16:24:31 +02:00
|
|
|
'start_date' => '+10 days 15:00:00',
|
|
|
|
'duration' => HOUR_IN_SECONDS,
|
|
|
|
'status' => 'publish',
|
|
|
|
),
|
|
|
|
'complex_event' => array(
|
|
|
|
'title' => 'My Event',
|
2024-10-02 19:15:28 +02:00
|
|
|
'content' => 'Come to my event!',
|
2024-09-24 16:24:31 +02:00
|
|
|
'start_date' => '+10 days 15:00:00',
|
|
|
|
'duration' => HOUR_IN_SECONDS,
|
|
|
|
'status' => 'publish',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the setup function, so that tests don't run if the Events Calendar is not active.
|
|
|
|
*/
|
|
|
|
public function set_up() {
|
|
|
|
parent::set_up();
|
|
|
|
|
|
|
|
if ( ! class_exists( '\Tribe__Events__Main' ) ) {
|
|
|
|
self::markTestSkipped( 'The Events Calendar plugin is not active.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that ActivityPub support is enabled for The Events Calendar.
|
2024-10-02 21:54:03 +02:00
|
|
|
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
|
2024-09-24 16:24:31 +02:00
|
|
|
$aec->activate_activitypub_support_for_active_event_plugins();
|
|
|
|
|
|
|
|
// Delete all posts afterwards.
|
|
|
|
_delete_all_posts();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the right transformer gets applied.
|
|
|
|
*/
|
2024-09-25 11:27:17 +02:00
|
|
|
public function test_the_events_calendar_transformer_class() {
|
2024-09-24 16:24:31 +02:00
|
|
|
// We only test for one event plugin being active at the same time,
|
|
|
|
// even though we support multiple onces in theory.
|
|
|
|
// But testing all combinations is beyond scope.
|
2024-10-02 21:54:03 +02:00
|
|
|
$active_event_plugins = \ActivityPub_Event_Bridge\Setup::get_instance()->get_active_event_plugins();
|
2024-09-24 16:24:31 +02:00
|
|
|
$this->assertEquals( 1, count( $active_event_plugins ) );
|
|
|
|
|
|
|
|
// Enable ActivityPub support for the event plugin.
|
|
|
|
$this->assertContains( 'tribe_events', get_option( 'activitypub_support_post_types' ) );
|
|
|
|
|
|
|
|
// Create a The Events Calendar Event without content.
|
|
|
|
$wp_object = tribe_events()
|
|
|
|
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
|
|
|
|
->create();
|
|
|
|
|
|
|
|
// Call the transformer Factory.
|
|
|
|
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
|
|
|
|
|
|
|
// Check that we got the right transformer.
|
2024-10-02 21:54:03 +02:00
|
|
|
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\The_Events_Calendar::class, $transformer );
|
2024-09-24 16:24:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transformation of minimal event without venue.
|
|
|
|
*/
|
|
|
|
public function test_transform_of_minimal_event_without_venue() {
|
|
|
|
// Create a The Events Calendar Event.
|
|
|
|
$wp_object = tribe_events()
|
|
|
|
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
|
|
|
|
->create();
|
|
|
|
|
|
|
|
// Call the transformer.
|
|
|
|
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
|
|
|
|
|
|
|
|
// Check that the event ActivityStreams representation contains everything as expected.
|
|
|
|
$this->assertEquals( 'Event', $event_array['type'] );
|
|
|
|
$this->assertEquals( 'My Event', $event_array['name'] );
|
2024-10-02 19:15:28 +02:00
|
|
|
$this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) );
|
2024-09-24 16:24:31 +02:00
|
|
|
$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'] );
|
2024-09-24 17:14:39 +02:00
|
|
|
$this->assertEquals( 'external', $event_array['joinMode'] );
|
2024-09-24 16:24:31 +02:00
|
|
|
$this->assertArrayNotHasKey( 'location', $event_array );
|
|
|
|
$this->assertEquals( 'MEETING', $event_array['category'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transformation of event with mapped category.
|
|
|
|
*/
|
|
|
|
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' ) );
|
|
|
|
|
|
|
|
// Set default mapping for event categories.
|
2024-10-02 21:54:03 +02:00
|
|
|
update_option( 'activitypub_event_bridge_default_event_category', 'MUSIC' );
|
2024-09-24 16:24:31 +02:00
|
|
|
|
|
|
|
// Set an override for the category with the slug theatre.
|
2024-10-02 21:54:03 +02:00
|
|
|
update_option( 'activitypub_event_bridge_event_category_mappings', array( 'theatre' => 'THEATRE' ) );
|
2024-09-24 16:24:31 +02:00
|
|
|
|
|
|
|
// 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 );
|
|
|
|
// 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.
|
2024-09-24 17:14:39 +02:00
|
|
|
wp_set_post_terms( $wp_object->ID, $category_id_theatre['term_id'], Tribe__Events__Main::TAXONOMY, false );
|
2024-09-24 16:24:31 +02:00
|
|
|
// 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( 'THEATRE', $event_array['category'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transformation of minimal event with minimal venue.
|
|
|
|
*/
|
|
|
|
public function test_transform_of_minimal_event_with_venue() {
|
|
|
|
// Create Venue.
|
|
|
|
$venue = tribe_venues()->set_args( self::MOCKUP_VENUS['minimal_venue'] )->create();
|
|
|
|
// Create a The Events Calendar Event.
|
|
|
|
$wp_object = tribe_events()
|
|
|
|
->set_args( self::MOCKUP_EVENTS['complex_event'] )
|
|
|
|
->set( 'venue', $venue->ID )
|
|
|
|
->create();
|
|
|
|
|
|
|
|
// Call the transformer.
|
|
|
|
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
|
|
|
|
|
|
|
|
// Check that the event ActivityStreams representation contains everything as expected.
|
|
|
|
$this->assertEquals( 'Event', $event_array['type'] );
|
|
|
|
$this->assertEquals( 'My Event', $event_array['name'] );
|
2024-10-02 19:15:28 +02:00
|
|
|
$this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) );
|
2024-09-24 16:24:31 +02:00
|
|
|
$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['commentsEnabled'] );
|
|
|
|
$this->assertArrayHasKey( 'location', $event_array );
|
|
|
|
$this->assertEquals( 'Place', $event_array['location']['type'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['minimal_venue']['venue'], $event_array['location']['name'] );
|
|
|
|
}
|
2024-09-24 17:14:39 +02:00
|
|
|
|
|
|
|
/**
|
2024-09-25 11:27:17 +02:00
|
|
|
* Test transformation of minimal event with fully filled venue.
|
2024-09-24 17:14:39 +02:00
|
|
|
*/
|
|
|
|
public function test_transform_of_minimal_event_with_address_venue() {
|
|
|
|
// Create Venue.
|
|
|
|
$venue = tribe_venues()->set_args( self::MOCKUP_VENUS['complex_venue'] )->create();
|
|
|
|
// Create a The Events Calendar Event.
|
|
|
|
$wp_object = tribe_events()
|
|
|
|
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
|
|
|
|
->set( 'venue', $venue->ID )
|
|
|
|
->create();
|
|
|
|
|
|
|
|
// Call the transformer.
|
|
|
|
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
|
|
|
|
|
|
|
|
// Check that the event ActivityStreams representation contains everything as expected.
|
|
|
|
$this->assertEquals( 'Event', $event_array['type'] );
|
|
|
|
$this->assertEquals( 'My Event', $event_array['name'] );
|
2024-10-02 19:15:28 +02:00
|
|
|
$this->assertEquals( 'Come to my event!', wp_strip_all_tags( $event_array['content'] ) );
|
2024-09-24 17:14:39 +02:00
|
|
|
$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['commentsEnabled'] );
|
|
|
|
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
|
|
|
|
$this->assertArrayHasKey( 'location', $event_array );
|
|
|
|
$this->assertEquals( 'Place', $event_array['location']['type'] );
|
|
|
|
$this->assertEquals( 'PostalAddress', $event_array['location']['address']['type'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['venue'], $event_array['location']['name'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['venue'], $event_array['location']['address']['name'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['province'], $event_array['location']['address']['addressRegion'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['address'], $event_array['location']['address']['streetAddress'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['city'], $event_array['location']['address']['addressLocality'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['country'], $event_array['location']['address']['addressCountry'] );
|
|
|
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['zip'], $event_array['location']['address']['postalCode'] );
|
|
|
|
}
|
2024-09-24 16:24:31 +02:00
|
|
|
}
|