more tests
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 49s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 59s

This commit is contained in:
André Menrath 2024-11-26 09:17:59 +01:00
parent ed773761bd
commit 33bdba1ed0

View file

@ -10,46 +10,18 @@
*/ */
class Test_EventPrime extends WP_UnitTestCase { class Test_EventPrime extends WP_UnitTestCase {
/** /**
* Mockup events of certain complexity. * Mockup venues of certain complexity.
*
* @var array
*/ */
public const MOCKUP_VENUS = array( private $mockup_venue = 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',
),
);
public const MOCKUP_EVENTS = array( /**
'minimal_event' => array( * Mockup events for tests.
'title' => 'My Event', *
'content' => 'Come to my event!', * @var array
'start_date' => '+10 days 15:00:00', */
'duration' => HOUR_IN_SECONDS, protected $mockup_events = array();
'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',
),
);
/** /**
* Override the setup function, so that tests don't run if the Events Calendar is not active. * 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 afterwards.
_delete_all_posts(); _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. // Enable ActivityPub support for the event plugin.
$this->assertContains( 'em_event', get_option( 'activitypub_support_post_types' ) ); $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. // Create an EventPrime Event without content.
$ep_functions = new Eventprime_Basic_Functions(); $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 ); $wp_object = get_post( $post_id );
@ -108,4 +95,92 @@ class Test_EventPrime extends WP_UnitTestCase {
// Check that we got the right transformer. // Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\EventPrime::class, $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'] );
}
} }