Add Event plugin integration: EventPrime #82

Open
linos wants to merge 10 commits from eventprime into main
Showing only changes of commit 33bdba1ed0 - Show all commits

View file

@ -10,46 +10,18 @@
*/
class Test_EventPrime extends WP_UnitTestCase {
/**
* Mockup events of certain complexity.
* Mockup venues of certain complexity.
*
* @var array
*/
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',
),
);
private $mockup_venue = array();
public const MOCKUP_EVENTS = array(
'minimal_event' => array(
'title' => 'My Event',
'content' => 'Come to my event!',
'start_date' => '+10 days 15:00:00',
'duration' => HOUR_IN_SECONDS,
'status' => 'publish',
),
'complex_event' => array(
'title' => 'My Event',
'content' => 'Come to my event!',
'start_date' => '+10 days 15:00:00',
'duration' => HOUR_IN_SECONDS,
'status' => 'publish',
),
);
/**
* Mockup events for tests.
*
* @var array
*/
protected $mockup_events = array();
/**
* Override the setup function, so that tests don't run if the Events Calendar is not active.
@ -67,6 +39,34 @@ class Test_EventPrime extends WP_UnitTestCase {
// Delete all posts afterwards.
_delete_all_posts();
$this->setup_mockup_data();
}
/**
* Setup mockup events.
*/
private function setup_mockup_data() {
$this->mockup_events = array(
'minimal_event' => array(
'name' => 'EventPrime Event title',
'description' => 'EventPrime event description',
'status' => 'Publish',
'em_event_type' => '',
'em_venue' => '',
'em_organizer' => '',
'em_performer' => '',
'em_start_date' => strtotime( '+10 days 15:00:00' ),
'em_end_date' => strtotime( '+10 days 16:00:00' ),
'em_enable_booking' => 'bookings_off',
'em_ticket_price' => 0,
),
);
$this->mockup_venue = array(
'name' => 'Test Venue',
'address' => 'Fediverse-street 1337, 1234 Fediverse-town',
);
}
/**
@ -82,23 +82,10 @@ class Test_EventPrime extends WP_UnitTestCase {
// Enable ActivityPub support for the event plugin.
$this->assertContains( 'em_event', get_option( 'activitypub_support_post_types' ) );
$event_data = array();
$event_data['name'] = 'EventPrime Event title';
$event_data['description'] = 'EventPrime event description';
$event_data['status'] = 'Publish';
$event_data['em_event_type'] = '';
$event_data['em_venue'] = '';
$event_data['em_organizer'] = '';
$event_data['em_performer'] = '';
$event_data['em_start_date'] = strtotime( '+10 days 15:00:00' );
$event_data['em_end_date'] = strtotime( '+10 days 16:00:00' );
$event_data['em_enable_booking'] = 'bookings_off';
$event_data['em_ticket_price'] = 0;
// Create an EventPrime Event without content.
$ep_functions = new Eventprime_Basic_Functions();
$post_id = $ep_functions->insert_event_post_data( $event_data );
$post_id = $ep_functions->insert_event_post_data( $this->mockup_events['minimal_event'] );
$wp_object = get_post( $post_id );
@ -108,4 +95,92 @@ class Test_EventPrime extends WP_UnitTestCase {
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\EventPrime::class, $transformer );
}
/**
* Test transformation of minimal event.
*/
public function test_transformation_of_minimal_event() {
// Create an EventPrime Event without content.
$ep_functions = new Eventprime_Basic_Functions();
$post_id = $ep_functions->insert_event_post_data( $this->mockup_events['minimal_event'] );
$wp_object = get_post( $post_id );
// Call the transformer Factory.
$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( 'EventPrime Event title', $event_array['name'] );
$this->assertEquals( 'EventPrime 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 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->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
}
/**
* Test transformation of minimal event.
*/
public function test_transformation_of_minimal_event_with_venue() {
// Create an EventPrime Event without content.
$ep_functions = new Eventprime_Basic_Functions();
$venue_term_id = wp_insert_term( $this->mockup_venue['name'], 'em_venue' )['term_id'];
add_term_meta( $venue_term_id, 'em_address', $this->mockup_venue['address'], true );
add_term_meta( $venue_term_id, 'em_display_address_on_frontend', true, true );
$event_data = $this->mockup_events['minimal_event'];
$event_data['em_venue'] = $venue_term_id;
$post_id = $ep_functions->insert_event_post_data( $event_data );
$wp_object = get_post( $post_id );
// Call the transformer Factory.
$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( 'EventPrime Event title', $event_array['name'] );
$this->assertEquals( 'EventPrime 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 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( $this->mockup_venue['name'], $event_array['location']['name'] );
$this->assertEquals( $this->mockup_venue['address'], $event_array['location']['address'] );
$this->assertEquals( 'MEETING', $event_array['category'] );
}
/**
* Test transformation of minimal event with venue which has a hidden address.
*/
public function test_transformation_of_minimal_event_with_venue_with_hidden_address() {
// Create an EventPrime Event without content.
$ep_functions = new Eventprime_Basic_Functions();
$venue_term_id = wp_insert_term( $this->mockup_venue['name'], 'em_venue' )['term_id'];
add_term_meta( $venue_term_id, 'em_address', $this->mockup_venue['address'], true );
add_term_meta( $venue_term_id, 'em_display_address_on_frontend', false, true );
$event_data = $this->mockup_events['minimal_event'];
$event_data['em_venue'] = $venue_term_id;
$post_id = $ep_functions->insert_event_post_data( $event_data );
$wp_object = get_post( $post_id );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected.
$this->assertArrayNotHasKey( 'address', $event_array['location'] );
}
}