Run integration tests and improve transformers for all integrations #32

Merged
linos merged 13 commits from ci_multiple_integrations into main 2024-09-25 11:27:17 +02:00
3 changed files with 109 additions and 2 deletions
Showing only changes of commit ef3389e64d - Show all commits

View file

@ -94,16 +94,21 @@ final class Events_Manager extends Event_Transformer {
return null;
}
$location = new Place();
$em_location = $this->em_event->get_location();
if ( '' === $em_location->location_id ) {
return null;
}
$location = new Place();
$location->set_name( $em_location->location_name );
$address = array(
'type' => 'PostalAddress',
'addressCountry' => $em_location->location_country,
'addressLocality' => $em_location->location_town,
'streetAddress' => $em_location->location_address,
'postalAddress' => $em_location->location_address,
'postalCode' => $em_location->location_postcode,
'name' => $em_location->location_name,
);
if ( $em_location->location_state ) {

View file

@ -69,6 +69,14 @@ function _manually_load_plugin() {
update_option( 'active_plugins', $current );
}
// Hot fix that allows using Events Manager within unit tests, because the em_init() is later not run as admin.
if ( 'events_manager' === $activitypub_event_extension_integration_filter ) {
require_once $plugin_dir . 'events-manager/em-install.php';
em_create_events_table();
em_create_events_meta_table();
em_create_locations_table();
}
// At last manually load our WordPress plugin.
require dirname( __DIR__ ) . '/activitypub-event-extensions.php';
}

View file

@ -19,6 +19,9 @@ class Test_Events_Manager extends WP_UnitTestCase {
self::markTestSkipped( 'VS Event List plugin is not active.' );
}
// For tests allow every user to create new events.
update_option( 'dbem_events_anonymous_submissions', true );
// Make sure that ActivityPub support is enabled for Events Manager.
$aec = \Activitypub_Event_Extensions\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
@ -60,4 +63,95 @@ class Test_Events_Manager extends WP_UnitTestCase {
// Check that we got the right transformer.
$this->assertInstanceOf( \Activitypub_Event_Extensions\Activitypub\Transformer\Events_Manager::class, $transformer );
}
/**
* Test the transformation of a minimal event.
*/
public function test_transform_of_minimal_event() {
// Create mockup event.
$event = new EM_Event();
$event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description';
$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->force_status = 'published';
$event->event_rsvp = false;
// Save the Event.
$event->save();
// Insert a new Event.
$post = get_post( $event->post_id );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $post )->to_object()->to_array();
// Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Events Manager 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->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 the transformation of a minimal event.
*/
public function test_transform_of_event_with_location() {
// Create a mockup location.
$location = new EM_Location();
$location->location_name = 'Test location';
$location->location_address = 'Test Address';
$location->location_town = 'Test Town';
$location->location_state = 'Test state';
$location->location_postcode = '1337';
$location->location_region = 'Test region';
$location->location_country = 'AT'; // Must be a two char country code.
$location->save();
// Create mockup 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_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->force_status = 'published';
$event->event_rsvp = false;
// Save the Event.
$event->save();
// Insert a new Event.
$post = get_post( $event->post_id );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $post )->to_object()->to_array();
// Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Events Manager 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->assertTrue( $event_array['commentsEnabled'] );
// $this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Test location', $event_array['location']['name'] );
$this->assertEquals( 'Test Address', $event_array['location']['address']['postalAddress'] );
$this->assertEquals( 'Test Town', $event_array['location']['address']['addressLocality'] );
$this->assertEquals( 'Test state', $event_array['location']['address']['addressRegion'] );
$this->assertEquals( '1337', $event_array['location']['address']['postalCode'] );
$this->assertEquals( 'AT', $event_array['location']['address']['addressCountry'] );
}
}