From 4c2e2c70c172e223b8ea2c81726e2cd0a5963a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Fri, 18 Oct 2024 13:43:37 +0200 Subject: [PATCH] basic tests --- ...ass-plugin-modern-events-calendar-lite.php | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/test-class-plugin-modern-events-calendar-lite.php b/tests/test-class-plugin-modern-events-calendar-lite.php index fa658ec..55114d9 100644 --- a/tests/test-class-plugin-modern-events-calendar-lite.php +++ b/tests/test-class-plugin-modern-events-calendar-lite.php @@ -76,4 +76,110 @@ class Test_Modern_Events_Calendar_Lite extends WP_UnitTestCase { // Check that we got the right transformer. $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Modern_Events_Calendar_Lite::class, $transformer ); } + + /** + * 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' ); + + // 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 ), + 'repeat_status' => 0, + 'repeat_type' => 'daily', + 'interval' => 1, + ); + + $post_id = $this->mec_main->save_event( $event ); + + $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->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->assertArrayNotHasKey( 'location', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + } + + /** + * 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' ); + + // Add new location. + $location = array( + 'name' => 'MEC Location', + 'latitude' => '52.356370', + 'longitude' => '4.955760', + 'address' => 'Stichting NLnet, Science Park 400, 1098 XH Amsterdam', + 'url' => 'https://nlnet.nl/', + ); + + $location_id = $this->mec_main->save_location( $location ); + + // 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 ), + 'repeat_status' => 0, + 'repeat_type' => 'daily', + 'interval' => 1, + 'location_id' => $location_id, + ); + + $post_id = $this->mec_main->save_event( $event ); + + $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->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->assertArrayHasKey( 'location', $event_array ); + $this->assertEquals( 'MEETING', $event_array['category'] ); + $this->assertEquals( $location['address'], $event_array['location']['address'] ); + $this->assertEquals( $location['name'], $event_array['location']['name'] ); + $this->assertEquals( $location['latitude'], $event_array['location']['latitude'] ); + $this->assertEquals( $location['longitude'], $event_array['location']['longitude'] ); + } }