wordpress-activitypub-event.../tests/test-class-plugin-events-manger.php

64 lines
1.9 KiB
PHP
Raw Normal View History

2024-09-24 17:37:44 +02:00
<?php
/**
* Class SampleTest
*
* @package Activitypub_Event_Extensions
*/
/**
* Sample test case.
*/
class Test_Events_Manager extends WP_UnitTestCase {
2024-09-24 17:37:44 +02:00
/**
* Override the setup function, so that tests don't run if the Events Calendar is not active.
*/
public function set_up() {
parent::set_up();
if ( ! class_exists( 'EM_Events' ) ) {
2024-09-24 17:37:44 +02:00
self::markTestSkipped( 'VS Event List plugin is not active.' );
}
// Make sure that ActivityPub support is enabled for Events Manager.
2024-09-24 17:37:44 +02:00
$aec = \Activitypub_Event_Extensions\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_transformer_class() {
// We only test for one event plugin being active at the same time,
// even though we support multiple onces in theory.
// But testing all combinations is beyond scope.
$active_event_plugins = \Activitypub_Event_Extensions\Setup::get_instance()->get_active_event_plugins();
$this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin.
$this->assertContains( EM_POST_TYPE_EVENT, get_option( 'activitypub_support_post_types' ) );
2024-09-24 17:37:44 +02:00
// Insert a new Event.
$wp_post_id = wp_insert_post(
array(
'post_title' => 'Events Manager Test event',
2024-09-24 17:37:44 +02:00
'post_status' => 'published',
'post_type' => EM_POST_TYPE_EVENT,
2024-09-24 17:37:44 +02:00
'meta_input' => array(
'event_start_time' => strtotime( '+10 days 15:00:00' ),
2024-09-24 17:37:44 +02:00
),
)
);
$wp_object = get_post( $wp_post_id );
// Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
// Check that we got the right transformer.
$this->assertInstanceOf( \Activitypub_Event_Extensions\Activitypub\Transformer\Events_Manager::class, $transformer );
2024-09-24 17:37:44 +02:00
}
}