basic tests
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 46s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 59s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Has been cancelled

This commit is contained in:
André Menrath 2024-11-28 21:55:28 +01:00
parent b7be4fc028
commit 8f179ff9f3

View file

@ -15,14 +15,11 @@ class Test_Event_Organiser extends WP_UnitTestCase {
public function set_up() { public function set_up() {
parent::set_up(); parent::set_up();
if ( ! function_exists( 'eo_get_events' ) ) { if ( ! class_exists( '\EO_Query_Result' ) ) {
self::markTestSkipped( 'Event Organiser plugin is not active.' ); self::markTestSkipped( 'Event Organiser plugin is not active.' );
} }
// Mock the plugin activation. // Make sure that ActivityPub support is enabled.
GatherPress\Core\Setup::get_instance()->activate_gatherpress_plugin( false );
// Make sure that ActivityPub support is enabled for The Events Calendar.
$aec = \ActivityPub_Event_Bridge\Setup::get_instance(); $aec = \ActivityPub_Event_Bridge\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins(); $aec->activate_activitypub_support_for_active_event_plugins();
@ -41,56 +38,50 @@ class Test_Event_Organiser extends WP_UnitTestCase {
$this->assertEquals( 1, count( $active_event_plugins ) ); $this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin. // Enable ActivityPub support for the event plugin.
$this->assertContains( 'gatherpress_event', get_option( 'activitypub_support_post_types' ) ); $this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) );
// Mock GatherPress Event. $event_data = array(
$post_id = wp_insert_post( 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ),
array( 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ),
'post_title' => 'Unit Test Event', 'all_day' => 0,
'post_type' => 'gatherpress_event', 'schedule' => 'once',
'post_content' => 'Unit Test description.',
'post_status' => 'publish',
)
);
$event = new \GatherPress\Core\Event( $post_id );
$params = array(
'datetime_start' => '+10 days 15:00:00',
'datetime_end' => '+10 days 16:00:00',
'timezone' => 'America/New_York',
); );
$event->save_datetimes( $params ); $post_data = array(
'post_title' => 'Unit Test Event',
'post_content' => 'Unit Test description.',
);
$post_id = eo_insert_event( $post_data, $event_data );
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $event->event ); $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) );
// Check that we got the right transformer. // Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\GatherPress::class, $transformer ); $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event_Organiser::class, $transformer );
} }
/** /**
* Test transformation to ActivityPUb for basic event. * Test transformation to ActivityPUb for basic event.
*/ */
public function test_transform_of_basic_event() { public function test_transform_of_basic_event() {
// Mock GatherPress Event. // Mock Event.
$post_id = wp_insert_post( $event_data = array(
array( 'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ),
'post_title' => 'Unit Test Event', 'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ),
'post_type' => 'gatherpress_event', 'all_day' => 0,
'post_content' => 'Unit Test description.', 'schedule' => 'once',
'post_status' => 'publish',
)
); );
$event = new \GatherPress\Core\Event( $post_id );
$params = array( $post_data = array(
'datetime_start' => '+10 days 15:00:00', 'post_title' => 'Unit Test Event',
'datetime_end' => '+10 days 16:00:00', 'post_content' => 'Unit Test description.',
'timezone' => 'America/New_York',
); );
$event->save_datetimes( $params );
$post_id = eo_insert_event( $post_data, $event_data );
// Call the transformer Factory. // Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( $event->event )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) )->to_object()->to_array();
// Check that the event ActivityStreams representation contains everything as expected. // Check that the event ActivityStreams representation contains everything as expected.
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );