add more tests for Events Manager
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 34s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 59s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 54s

This commit is contained in:
André Menrath 2024-09-25 10:10:15 +02:00
parent 1873b940f8
commit c7e5acdccb
2 changed files with 48 additions and 19 deletions

View file

@ -73,21 +73,14 @@ class Test_Events_Manager extends WP_UnitTestCase {
$event->event_name = 'Events Manager Test event'; $event->event_name = 'Events Manager Test event';
$event->post_content = 'Event description'; $event->post_content = 'Event description';
$event->event_start_date = gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ); $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_start_time = '15:00:00';
$event->event_end_time = '16:00:00';
$event->start = strtotime( $event->event_start_date . ' ' . $event->event_start_time ); $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->force_status = 'published';
$event->event_rsvp = false; $event->event_rsvp = false;
// Save the Event. $this->assertTrue( $event->save() );
$event->save();
// Insert a new Event.
$post = get_post( $event->post_id );
// Call the transformer Factory. // Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $post )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->post_id ) )->to_object()->to_array();
// Check that we got the right transformer. // Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
@ -98,13 +91,14 @@ class Test_Events_Manager extends WP_UnitTestCase {
$this->assertEquals( comments_open( $event->post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( comments_open( $event->post_id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array ); $this->assertArrayNotHasKey( 'location', $event_array );
$this->assertArrayNotHasKey( 'endTime', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $this->assertEquals( 'MEETING', $event_array['category'] );
} }
/** /**
* Test the transformation of a minimal event. * Test the transformation of a event with full location.
*/ */
public function test_transform_of_event_with_location() { public function test_transform_of__full_event_with_location() {
// Create a mockup location. // Create a mockup location.
$location = new EM_Location(); $location = new EM_Location();
$location->location_name = 'Test location'; $location->location_name = 'Test location';
@ -114,7 +108,8 @@ class Test_Events_Manager extends WP_UnitTestCase {
$location->location_postcode = '1337'; $location->location_postcode = '1337';
$location->location_region = 'Test region'; $location->location_region = 'Test region';
$location->location_country = 'AT'; // Must be a two char country code. $location->location_country = 'AT'; // Must be a two char country code.
$location->save(); $this->assertTrue( $location->save() );
// Create mockup event. // Create mockup event.
$event = new EM_Event(); $event = new EM_Event();
$event->event_name = 'Events Manager Test event'; $event->event_name = 'Events Manager Test event';
@ -128,14 +123,10 @@ class Test_Events_Manager extends WP_UnitTestCase {
$event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time ); $event->end = strtotime( $event->event_end_date . ' ' . $event->event_end_time );
$event->force_status = 'published'; $event->force_status = 'published';
$event->event_rsvp = false; $event->event_rsvp = false;
// Save the Event. $this->assertTrue( $event->save() );
$event->save();
// Insert a new Event.
$post = get_post( $event->post_id );
// Call the transformer Factory. // Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $post )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->post_id ) )->to_object()->to_array();
// Check that we got the right transformer. // Check that we got the right transformer.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
@ -152,4 +143,42 @@ class Test_Events_Manager extends WP_UnitTestCase {
$this->assertEquals( '1337', $event_array['location']['address']['postalCode'] ); $this->assertEquals( '1337', $event_array['location']['address']['postalCode'] );
$this->assertEquals( 'AT', $event_array['location']['address']['addressCountry'] ); $this->assertEquals( 'AT', $event_array['location']['address']['addressCountry'] );
} }
/**
* Test the transformation of a minimal event.
*/
public function test_transform_of_event_with_name_only_location() {
// Create a mockup location.
$location = new EM_Location();
$location->location_name = 'Name only location';
$this->assertTrue( $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;
$this->assertTrue( $event->save() );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->post_id ) )->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->assertEquals( 'external', $event_array['joinMode'] );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'Name only location', $event_array['location']['name'] );
}
} }

View file

@ -180,7 +180,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase {
} }
/** /**
* Test transformation of minimal event with minimal venue. * Test transformation of minimal event with fully filled venue.
*/ */
public function test_transform_of_minimal_event_with_address_venue() { public function test_transform_of_minimal_event_with_address_venue() {
// Create Venue. // Create Venue.