test with PHP 8.4 #84
11 changed files with 341 additions and 4 deletions
|
@ -38,7 +38,7 @@ jobs:
|
|||
path: |
|
||||
${{ env.WP_CORE_DIR }}
|
||||
${{ env.WP_TESTS_DIR }}
|
||||
key: cache-wordpress-67-3
|
||||
key: cache-wordpress-67-4
|
||||
|
||||
- name: Cache Composer
|
||||
id: cache-composer-phpunit
|
||||
|
@ -113,4 +113,9 @@ jobs:
|
|||
- name: Run Integration tests for EventPrime
|
||||
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=eventprime
|
||||
env:
|
||||
PHP_VERSION: ${{ matrix.php-version }}
|
||||
PHP_VERSION: ${{ matrix.php-version }}
|
||||
|
||||
- name: Run Integration tests for Event Organiser
|
||||
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=event_organiser
|
||||
env:
|
||||
PHP_VERSION: ${{ matrix.php-version }}
|
||||
|
|
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Added
|
||||
|
||||
* Integration for Event Organiser
|
||||
* Integration for EventPrime – Events Calendar, Bookings and Tickets
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -64,6 +64,7 @@ This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/ac
|
|||
* [Modern Events Calendar Lite](https://webnus.net/modern-events-calendar/)
|
||||
* [GatherPress](https://gatherpress.org/)
|
||||
* [EventPrime – Events Calendar, Bookings and Tickets](https://wordpress.org/plugins/eventprime-event-calendar-management/)
|
||||
* [Event Organiser](https://wordpress.org/plugins/event-organiser/)
|
||||
|
||||
## Configuration ##
|
||||
|
||||
|
@ -105,6 +106,7 @@ We're always interested in your feedback. Feel free to reach out to us via [E-Ma
|
|||
|
||||
### Added
|
||||
|
||||
* Integration for Event Organiser
|
||||
* Integration for EventPrime – Events Calendar, Bookings and Tickets
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -261,6 +261,7 @@ install_wp_plugins() {
|
|||
install_wp_plugin events-manager "6.6.3"
|
||||
install_wp_plugin wp-event-manager "3.1.45.1"
|
||||
install_wp_plugin wp-event-solution "4.0.14"
|
||||
install_wp_plugin event-organiser "3.12.8"
|
||||
# Mec is not installable via wordpress.org, we use our own mirror.
|
||||
install_wp_plugin_mec
|
||||
}
|
||||
|
|
|
@ -55,11 +55,12 @@
|
|||
"@test-wp-event-manager",
|
||||
"@test-eventin",
|
||||
"@test-modern-events-calendar-lite",
|
||||
"@test-eventprime"
|
||||
"@test-eventprime",
|
||||
"@test-event-organiser"
|
||||
],
|
||||
"test-debug": [
|
||||
"@prepare-test",
|
||||
"@test-eventprime"
|
||||
"@test-event-organiser"
|
||||
],
|
||||
"test-vs-event-list": "phpunit --filter=vs_event_list",
|
||||
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
|
||||
|
@ -69,6 +70,7 @@
|
|||
"test-eventin": "phpunit --filter=eventin",
|
||||
"test-modern-events-calendar-lite": "phpunit --filter=modern_events_calendar_lite",
|
||||
"test-eventprime": "phpunit --filter=eventprime",
|
||||
"test-event-organiser": "phpunit --filter=event_organiser",
|
||||
"test-all": "phpunit"
|
||||
}
|
||||
}
|
||||
|
|
99
includes/activitypub/transformer/class-event-organiser.php
Normal file
99
includes/activitypub/transformer/class-event-organiser.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* ActivityPub Transformer for the plugin Event Organiser.
|
||||
*
|
||||
* @package ActivityPub_Event_Bridge
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
/**
|
||||
* ActivityPub Transformer for Event Organiser.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Event_Organiser extends Event {
|
||||
/**
|
||||
* Extended constructor.
|
||||
*
|
||||
* The wp_object is overridden with a the wp_object with filters. This object
|
||||
* also contains attributes specific to the Event organiser plugin like the
|
||||
* occurrence id.
|
||||
*
|
||||
* @param WP_Post $wp_object The WordPress object.
|
||||
* @param string $wp_taxonomy The taxonomy slug of the event post type.
|
||||
*/
|
||||
public function __construct( $wp_object, $wp_taxonomy ) {
|
||||
parent::__construct( $wp_object, $wp_taxonomy );
|
||||
$this->wp_object = get_posts(
|
||||
array(
|
||||
'ID' => $wp_object->ID,
|
||||
'post_type' => 'event',
|
||||
'suppress_filters' => false,
|
||||
)
|
||||
)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time from the event object.
|
||||
*/
|
||||
protected function get_end_time(): ?string {
|
||||
return eo_get_the_end( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID, $this->wp_object->occurrence_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time from the event object.
|
||||
*/
|
||||
protected function get_start_time(): string {
|
||||
return eo_get_the_start( 'Y-m-d\TH:i:s\Z', $this->wp_object->ID, $this->wp_object->occurrence_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get location from the event object.
|
||||
*/
|
||||
protected function get_location(): ?Place {
|
||||
$venue_id = eo_get_venue( $this->wp_object->ID );
|
||||
|
||||
if ( ! $venue_id ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$address = eo_get_venue_address( $venue_id );
|
||||
|
||||
$venue_name = eo_get_venue_name( $venue_id );
|
||||
|
||||
$address['streetAddress'] = $address['address'];
|
||||
unset( $address['address'] );
|
||||
|
||||
$address['postalCode'] = $address['postcode'];
|
||||
unset( $address['postcode'] );
|
||||
|
||||
$address['addressRegion'] = $address['state'];
|
||||
unset( $address['state'] );
|
||||
|
||||
$address['addressLocality'] = $address['city'];
|
||||
unset( $address['city'] );
|
||||
|
||||
$address['addressCountry'] = $address['country'];
|
||||
unset( $address['country'] );
|
||||
|
||||
$address['type'] = 'PostalAddress';
|
||||
|
||||
$location = new Place();
|
||||
$location->set_name( eo_get_venue_name( $this->wp_object->ID ) );
|
||||
$location->set_latitude( eo_get_venue_lat( $this->wp_object->ID ) ?? null );
|
||||
$location->set_longitude( eo_get_venue_lng( $this->wp_object->ID ) ?? null );
|
||||
$location->set_address( $address );
|
||||
$location->set_name( $venue_name );
|
||||
$location->set_content( eo_get_venue_description( $venue_id ) );
|
||||
|
||||
return $location;
|
||||
}
|
||||
}
|
|
@ -133,6 +133,7 @@ class Setup {
|
|||
'\ActivityPub_Event_Bridge\Plugins\Eventin',
|
||||
'\ActivityPub_Event_Bridge\Plugins\Modern_Events_Calendar_Lite',
|
||||
'\ActivityPub_Event_Bridge\Plugins\EventPrime',
|
||||
'\ActivityPub_Event_Bridge\Plugins\Event_Organiser',
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
69
includes/plugins/class-event-organiser.php
Normal file
69
includes/plugins/class-event-organiser.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Event Organiser.
|
||||
*
|
||||
* Defines all the necessary meta information for the Event Organiser plugin.
|
||||
*
|
||||
* @link https://wordpress.org/plugins/event-organiser/
|
||||
* @package ActivityPub_Event_Bridge
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Plugins;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
/**
|
||||
* Interface for a supported event plugin.
|
||||
*
|
||||
* This interface defines which information is necessary for a supported event plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Event_Organiser extends Event_Plugin {
|
||||
/**
|
||||
* Returns the full plugin file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_file(): string {
|
||||
return 'event-organiser/event-organiser.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the event post type of the plugin.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_post_type(): string {
|
||||
return 'event';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IDs of the admin pages of the plugin.
|
||||
*
|
||||
* @return array The settings page urls.
|
||||
*/
|
||||
public static function get_settings_pages(): array {
|
||||
return array( 'event-organiser' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ActivityPub transformer class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_activitypub_transformer_class_name(): string {
|
||||
return 'Event_Organiser';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the taxonomy used for the plugin's event categories.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_event_category_taxonomy(): string {
|
||||
return 'event-category';
|
||||
}
|
||||
}
|
|
@ -58,6 +58,7 @@ This plugin depends on the [ActivityPub plugin](https://wordpress.org/plugins/ac
|
|||
* [Modern Events Calendar Lite](https://webnus.net/modern-events-calendar/)
|
||||
* [GatherPress](https://gatherpress.org/)
|
||||
* [EventPrime – Events Calendar, Bookings and Tickets](https://wordpress.org/plugins/eventprime-event-calendar-management/)
|
||||
* [Event Organiser](https://wordpress.org/plugins/event-organiser/)
|
||||
|
||||
== Configuration ==
|
||||
|
||||
|
|
|
@ -74,6 +74,9 @@ function _manually_load_plugin() {
|
|||
case 'eventprime':
|
||||
$plugin_file = 'eventprime-event-calendar-management/event-prime.php';
|
||||
break;
|
||||
case 'event_organiser':
|
||||
$plugin_file = 'event-organiser/event-organiser.php';
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $plugin_file ) {
|
||||
|
|
153
tests/test-class-plugin-event-organiser.php
Normal file
153
tests/test-class-plugin-event-organiser.php
Normal file
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/**
|
||||
* Test class for the integration of the Event Organiser.
|
||||
*
|
||||
* @package ActivityPub_Event_Bridge
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sample test case.
|
||||
*/
|
||||
class Test_Event_Organiser extends WP_UnitTestCase {
|
||||
/**
|
||||
* 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 ( ! function_exists( 'eo_get_events' ) ) {
|
||||
self::markTestSkipped( 'Event Organiser plugin is not active.' );
|
||||
}
|
||||
|
||||
// Make sure that ActivityPub support is enabled.
|
||||
$aec = \ActivityPub_Event_Bridge\Setup::get_instance();
|
||||
$aec->activate_activitypub_support_for_active_event_plugins();
|
||||
|
||||
// Run the install script just in time which makes sure the custom tables exist and more.
|
||||
eventorganiser_install();
|
||||
|
||||
// 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_Bridge\Setup::get_instance()->get_active_event_plugins();
|
||||
$this->assertEquals( 1, count( $active_event_plugins ) );
|
||||
|
||||
// Enable ActivityPub support for the event plugin.
|
||||
$this->assertContains( 'event', get_option( 'activitypub_support_post_types' ) );
|
||||
|
||||
$event_data = array(
|
||||
'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ),
|
||||
'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ),
|
||||
'all_day' => 0,
|
||||
'schedule' => 'once',
|
||||
);
|
||||
|
||||
$post_data = array(
|
||||
'post_title' => 'Unit Test Event',
|
||||
'post_content' => 'Unit Test description.',
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
|
||||
$post_id = eo_insert_event( $post_data, $event_data );
|
||||
|
||||
// Call the transformer Factory.
|
||||
$transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $post_id ) );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event_Organiser::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test transformation to ActivityPub for basic event.
|
||||
*/
|
||||
public function test_transform_of_basic_event() {
|
||||
// Mock Event.
|
||||
$event_data = array(
|
||||
'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ),
|
||||
'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ),
|
||||
'all_day' => 0,
|
||||
'schedule' => 'once',
|
||||
);
|
||||
|
||||
$post_data = array(
|
||||
'post_title' => 'Unit Test Event',
|
||||
'post_content' => 'Unit Test description.',
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
|
||||
$post_id = eo_insert_event( $post_data, $event_data );
|
||||
|
||||
// Call the transformer Factory.
|
||||
$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.
|
||||
$this->assertEquals( 'Event', $event_array['type'] );
|
||||
$this->assertEquals( 'Unit Test Event', $event_array['name'] );
|
||||
$this->assertEquals( 'Unit Test 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->assertEquals( 'external', $event_array['joinMode'] );
|
||||
$this->assertArrayNotHasKey( 'location', $event_array );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test transformation to ActivityPub for event with location.
|
||||
*/
|
||||
public function test_transform_of_event_with_location() {
|
||||
// Create venue.
|
||||
$venue_args = array(
|
||||
'description' => 'This is a test venue for the Fediverse.',
|
||||
'address' => 'Fediverse-Street 1337',
|
||||
'city' => 'Fediverse-Town',
|
||||
'state' => 'Fediverse-Sate',
|
||||
'postcode' => '1337',
|
||||
'country' => 'Fediverse-Country',
|
||||
'latitude' => 7.076668,
|
||||
'longitude' => 15.421371,
|
||||
);
|
||||
$venue_name = 'Fediverse Venue';
|
||||
$venue = eo_insert_venue( $venue_name, $venue_args );
|
||||
|
||||
// Mock Event.
|
||||
$event_data = array(
|
||||
'start' => new DateTime( '+10 days 15:00:00', eo_get_blog_timezone() ),
|
||||
'end' => new DateTime( '+10 days 16:00:00', eo_get_blog_timezone() ),
|
||||
'all_day' => 0,
|
||||
'schedule' => 'once',
|
||||
);
|
||||
$post_data = array(
|
||||
'post_title' => 'Unit Test Event',
|
||||
'post_content' => 'Unit Test description.',
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
$post_id = eo_insert_event( $post_data, $event_data );
|
||||
wp_set_object_terms( $post_id, $venue['term_id'], 'event-venue' );
|
||||
|
||||
// Call the transformer Factory.
|
||||
$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.
|
||||
$this->assertEquals( 'Event', $event_array['type'] );
|
||||
$this->assertEquals( 'Unit Test Event', $event_array['name'] );
|
||||
$this->assertEquals( 'Unit Test 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->assertEquals( 'external', $event_array['joinMode'] );
|
||||
$this->assertArrayHasKey( 'location', $event_array );
|
||||
$this->assertEquals( $venue_args['description'], wp_strip_all_tags( $event_array['location']['content'] ) );
|
||||
$this->assertEquals( $venue_args['address'], $event_array['location']['address']['streetAddress'] );
|
||||
$this->assertEquals( $venue_args['city'], $event_array['location']['address']['addressLocality'] );
|
||||
$this->assertEquals( $venue_args['state'], $event_array['location']['address']['addressRegion'] );
|
||||
$this->assertEquals( $venue_args['country'], $event_array['location']['address']['addressCountry'] );
|
||||
$this->assertEquals( $venue_args['postcode'], $event_array['location']['address']['postalCode'] );
|
||||
$this->assertEquals( $venue_name, $event_array['location']['name'] );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue