add basic integration tests ffor modern-events-calendar-lite
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 40s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m34s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m8s

This commit is contained in:
André Menrath 2024-10-17 20:50:21 +02:00
parent bee70bcb88
commit 6964e08559
6 changed files with 124 additions and 3 deletions

View file

@ -37,7 +37,7 @@ jobs:
path: |
${{ env.WP_CORE_DIR }}
${{ env.WP_TESTS_DIR }}
key: cache-wordpress-8
key: cache-wordpress-9
- name: Cache Composer
id: cache-composer-phpunit
@ -101,5 +101,10 @@ jobs:
- name: Run Integration tests for Eventin (WP Event Solution)
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=eventin
env:
PHP_VERSION: ${{ matrix.php-version }}
- name: Run Integration tests for Modern Events Calendar Lite
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=modern_events_calendar_lite
env:
PHP_VERSION: ${{ matrix.php-version }}

View file

@ -226,6 +226,20 @@ install_wp_plugin() {
unzip -q -o "$TMPDIR/$PLUGIN_FILE" -d "$WP_CORE_DIR/wp-content/plugins/"
}
install_wp_plugin_mec() {
mkdir -p "$WP_CORE_DIR/wp-content/plugins/"
if [ -d "$WP_CORE_DIR/wp-content/plugins/modern-events-calendar-lite" ]; then
return;
fi
PLUGIN_VERSION="v7.15.0"
URL="https://code.event-federation.eu/Event-Federation/modern-events-calendar-lite"
git clone $URL "$WP_CORE_DIR/wp-content/plugins/modern-events-calendar-lite"
}
install_wp_plugins() {
if [ "$SKIP_PLUGINS_INSTALL" = "true" ]; then
echo "Skipping WordPress plugin installation."
@ -240,6 +254,8 @@ install_wp_plugins() {
install_wp_plugin events-manager
install_wp_plugin wp-event-manager
install_wp_plugin wp-event-solution
# Mec is not installable via wordpress.org, we use our own mirror.
install_wp_plugin_mec
}
install_wp

View file

@ -53,11 +53,12 @@
"@test-gatherpress",
"@test-events-manager",
"@test-wp-event-manager",
"@test-eventin"
"@test-eventin",
"@test-modern-events-calendar-lite"
],
"test-debug": [
"@prepare-test",
"@test-eventin"
"@test-modern-events-calendar-lite"
],
"test-vs-event-list": "phpunit --filter=vs_event_list",
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
@ -65,6 +66,7 @@
"test-events-manager": "phpunit --filter=events_manager",
"test-wp-event-manager": "phpunit --filter=wp_event_manager",
"test-eventin": "phpunit --filter=eventin",
"test-modern-events-calendar-lite": "phpunit --filter=modern_events_calendar_lite",
"test-all": "phpunit"
}
}

16
improvements.md Normal file
View file

@ -0,0 +1,16 @@
Make use of:
https://docs.theeventscalendar.com/reference/classes/tribe__events__api/get_event_terms/
for getting all tags/terms for an event!
```
public static function get_event_terms( $event_id, array $args = array() ) {
$terms = array();
foreach ( get_post_taxonomies( $event_id ) as $taxonomy ) {
$tax_terms = wp_get_object_terms( $event_id, $taxonomy, $args );
$terms[ $taxonomy ] = $tax_terms;
}
return $terms;
}
```

View file

@ -62,6 +62,9 @@ function _manually_load_plugin() {
case 'eventin':
$plugin_file = 'wp-event-solution/eventin.php';
break;
case 'modern_events_calendar_lite':
$plugin_file = 'modern-events-calendar-lite/modern-events-calendar-lite.php';
break;
case 'gatherpress':
$plugin_file = 'gatherpress/gatherpress.php';
break;

View file

@ -0,0 +1,79 @@
<?php
/**
* Tests or Modern Events Calendar Lite
*
* @package ActivityPub_Event_Bridge
*/
/**
* Sample test case.
*/
class Test_Modern_Events_Calendar_Lite extends WP_UnitTestCase {
/**
* The MEC main instance.
*
* @var \MEC_main|null
*/
protected $mec_main;
/**
* 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( '\MEC' ) ) {
self::markTestSkipped( 'Modern Events Calendar Lite is not active.' );
}
// Make sure that ActivityPub support is enabled for The Events Calendar.
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
$aec->activate_activitypub_support_for_active_event_plugins();
$this->mec_main = \MEC::getInstance( 'app.libraries.main' );
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_modern_events_calendar_lite_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_Bridge\Setup::get_instance()->get_active_event_plugins();
$this->assertEquals( 1, count( $active_event_plugins ) );
// Enable ActivityPub support for the event plugin.
$this->assertContains( 'mec-events', get_option( 'activitypub_support_post_types' ) );
// Insert a new Event.
$event = array(
'title' => 'MEC Test Event',
'status' => 'publish',
'start_time_hour' => '3',
'start_time_minutes' => '00',
'start_time_ampm' => 'PM',
'start' => '2025-01-01',
'end' => '2025-01-01',
'end_time_hour' => '4',
'end_time_minutes' => '00',
'end_time_ampm' => 'PM',
'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 Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Modern_Events_Calendar_Lite::class, $transformer );
}
}