|
|
|
@ -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'] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|