Compare commits

...

6 commits

Author SHA1 Message Date
7151f186b9 add more tests
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 36s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 59s
2024-10-12 20:20:17 +02:00
aaa0ffc026 todo: fix timezones
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 34s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 1m0s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 58s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 58s
2024-10-12 14:26:35 +02:00
a70c188922 run unit tests for eventin
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 47s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 59s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 59s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m3s
2024-10-12 14:03:11 +02:00
960f80ae28 fix tests
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 44s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 59s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m3s
2024-10-12 13:59:50 +02:00
679698a920 initial draft
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 34s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m26s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 59s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m7s
2024-10-12 13:52:06 +02:00
dedc0079ac wip
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 33s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 58s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 59s
2024-10-12 10:34:21 +02:00
8 changed files with 422 additions and 4 deletions

View file

@ -37,7 +37,7 @@ jobs:
path: |
${{ env.WP_CORE_DIR }}
${{ env.WP_TESTS_DIR }}
key: cache-wordpress-5
key: cache-wordpress-8
- name: Cache Composer
id: cache-composer-phpunit
@ -96,5 +96,10 @@ jobs:
- name: Run Integration tests for WP Event Manager
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=wp_event_manager
env:
PHP_VERSION: ${{ matrix.php-version }}
- 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 }}

View file

@ -239,6 +239,7 @@ install_wp_plugins() {
install_wp_plugin gatherpress
install_wp_plugin events-manager
install_wp_plugin wp-event-manager
install_wp_plugin wp-event-solution
}
install_wp

View file

@ -1,5 +1,6 @@
{
"name": "menrath/wordpress-activitypub-event-bridge",
"version": "1.0.0",
"description": "The ActivityPub Event Bridge help for event custom post types to federate properly.",
"type": "wordpress-plugin",
"require": {
@ -51,16 +52,19 @@
"@test-the-events-calendar",
"@test-gatherpress",
"@test-events-manager",
"@test-wp-event-manager"
"@test-wp-event-manager",
"@test-eventin"
],
"test-debug": [
"@prepare-test",
"@test-wp-event-manager"
"@test-eventin"
],
"test-vs-event-list": "phpunit --filter=vs_event_list",
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
"test-gatherpress": "phpunit --filter=gatherpress",
"test-events-manager": "phpunit --filter=events_manager",
"test-wp-event-manager": "phpunit --filter=wp_event_manager"
"test-wp-event-manager": "phpunit --filter=wp_event_manager",
"test-eventin": "phpunit --filter=eventin",
"test-all": "phpunit"
}
}

View file

@ -0,0 +1,164 @@
<?php
/**
* ActivityPub Transformer for Events managed with Eventin.
*
* @link https://support.themewinter.com/docs/plugins/docs-category/eventin/
*
* @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;
use DateTime;
use DateTimeZone;
use Etn\Core\Event\Event_Model;
use function Activitypub\esc_hashtag;
/**
* ActivityPub Transformer for Events managed with Eventin.
*
* @since 1.0.0
*/
final class Eventin extends Event {
/**
* Holds the EM_Event object.
*
* @var Event_Model
*/
protected $event_model;
/**
* Extend the constructor, to also set the Event Model.
*
* This is a special class object form The Events Calendar which
* has a lot of useful functions, we make use of our getter functions.
*
* @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->event_model = new Event_Model( $this->wp_object->ID );
}
/**
* Get the end time from the event object.
*/
public function get_start_time(): string {
return \gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $this->event_model->get_start_datetime() ) );
}
/**
* Get the end time from the event object.
*/
public function get_end_time(): string {
return \gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $this->event_model->get_end_datetime() ) );
}
/**
* Get the timezone of the event.
*/
public function get_timezone(): string {
return $this->event_model->get_timezone();
}
/**
* Get whether the event is online.
*
* @return bool
*/
public function get_is_online(): bool {
return 'online' === $this->event_model->__get( 'event_type' ) ? true : false;
}
/**
* Maybe add online link to attachments.
*
* @return array
*/
public function get_attachment(): array {
$attachment = parent::get_attachment();
$location = (array) $this->event_model->__get( 'location' );
if ( array_key_exists( 'integration', $location ) && array_key_exists( $location['integration'], $location ) ) {
$online_link = array(
'type' => 'Link',
'mediaType' => 'text/html',
'name' => $location[ $location['integration'] ],
'href' => $location[ $location['integration'] ],
);
$attachment[] = $online_link;
}
return $attachment;
}
/**
* Compose the events tags.
*/
public function get_tag() {
// The parent tag function also fetches the mentions.
$tags = parent::get_tag();
$post_tags = \wp_get_post_terms( $this->wp_object->ID, 'etn_tags' );
$post_categories = \wp_get_post_terms( $this->wp_object->ID, 'etn_category' );
if ( ! is_wp_error( $post_tags ) && $post_tags ) {
foreach ( $post_tags as $term ) {
$tag = array(
'type' => 'Hashtag',
'href' => \esc_url( \get_tag_link( $term->term_id ) ),
'name' => esc_hashtag( $term->name ),
);
$tags[] = $tag;
}
}
if ( ! is_wp_error( $post_categories ) && $post_categories ) {
foreach ( $post_categories as $term ) {
$tag = array(
'type' => 'Hashtag',
'href' => \esc_url( \get_tag_link( $term->term_id ) ),
'name' => esc_hashtag( $term->name ),
);
$tags[] = $tag;
}
}
if ( empty( $tags ) ) {
return null;
}
return $tags;
}
/**
* Get the location.
*
* @return ?Place
*/
public function get_location(): ?Place {
$location = (array) $this->event_model->__get( 'location' );
if ( ! array_key_exists( 'address', $location ) ) {
return null;
}
$place = new Place();
$address = $location['address'];
$place->set_name( $address );
$place->set_address( $address );
$place->set_sensitive( null );
return $place;
}
}

View file

@ -129,6 +129,7 @@ class Setup {
'\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar',
'\ActivityPub_Event_Bridge\Plugins\VS_Event_List',
'\ActivityPub_Event_Bridge\Plugins\WP_Event_Manager',
'\ActivityPub_Event_Bridge\Plugins\Eventin',
);
/**

View file

@ -0,0 +1,60 @@
<?php
/**
* The Events Calendar.
*
* Defines all the necessary meta information for the events calendar.
*
* @link https://wordpress.org/plugins/the-events-calendar/
* @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 Eventin extends Event_plugin {
/**
* Returns the full plugin file.
*
* @return string
*/
public static function get_plugin_file(): string {
return 'wp-event-solution/eventin.php';
}
/**
* Returns the event post type of the plugin.
*
* @return string
*/
public static function get_post_type(): string {
return 'etn';
}
/**
* Returns the ID of the main settings page of the plugin.
*
* @return string The settings page url.
*/
public static function get_settings_page(): string {
return 'eventin'; // Base always is wp-admin/admin.php?page=eventin.
}
/**
* Returns the taxonomy used for the plugin's event categories.
*
* @return string
*/
public static function get_event_category_taxonomy(): string {
return 'etn_category';
}
}

View file

@ -43,6 +43,10 @@ function _manually_load_plugin() {
}
}
// Hot fixes for eventin.
update_option( 'purchase_history_table_structure_migration_done', true );
update_option( 'etn_wizard', 'active' );
$plugin_file = null;
// See if we want to run integration tests for a specific event-plugin.
switch ( $activitypub_event_extension_integration_filter ) {
@ -55,6 +59,9 @@ function _manually_load_plugin() {
case 'events_manager':
$plugin_file = 'events-manager/events-manager.php';
break;
case 'eventin':
$plugin_file = 'wp-event-solution/eventin.php';
break;
case 'gatherpress':
$plugin_file = 'gatherpress/gatherpress.php';
break;
@ -66,6 +73,7 @@ function _manually_load_plugin() {
if ( $plugin_file ) {
// Manually load the event plugin.
require_once $plugin_dir . $plugin_file;
update_option( 'purchase_history_table_structure_migration_done', true );
$current = get_option( 'active_plugins', array() );
$current[] = $plugin_file;
sort( $current );

View file

@ -0,0 +1,175 @@
<?php
/**
* Tests for WP Event Solution.
*
* @package ActivityPub_Event_Bridge
*/
/**
* Test cases for WP Event Solution.
*/
class Test_Eventin extends WP_UnitTestCase {
/**
* Basic Mock-up event.
*/
private function get_mockup_event(): array {
return array(
'post_status' => 'publish',
'post_title' => 'Eventin Test Event Title',
'post_content' => 'Eventin Test Event Description',
'etn_start_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 15:00:00' ) ),
'etn_end_date' => \gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ),
'etn_start_time' => \gmdate( 'H:i', strtotime( '+10 days 15:00:00' ) ),
'etn_end_time' => \gmdate( 'H:i', strtotime( '+10 days 16:00:00' ) ),
'event_timezone' => 'Europe/Vienna',
);
}
/**
* 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( '\Wpeventin' ) ) {
self::markTestSkipped( 'Eventin plugin 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();
// Delete all posts afterwards.
_delete_all_posts();
}
/**
* Test that the right transformer gets applied.
*/
public function test_eventin_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( 'etn', get_option( 'activitypub_support_post_types' ) );
// Create a Eventin Event without content.
$event = new \Etn\Core\Event\Event_Model();
$event->create( $this->get_mockup_event() );
// Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) );
// Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer );
}
/**
* Test that the right transformer gets applied.
*/
public function test_eventin_test_minimal_event() {
// Create a Eventin Event without content.
$event = new \Etn\Core\Event\Event_Model();
$event->create( $this->get_mockup_event() );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array();
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Eventin Test Event Title', $event_array['name'] );
$this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] );
$this->assertEquals( 'Europe/Vienna', $event_array['timezone'] );
$this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertEquals( false, $event_array['isOnline'] );
}
/**
* Test that the right transformer gets applied.
*/
public function test_eventin_test_online_event_with_custom_link() {
// Create a Eventin Event without content.
$event = new \Etn\Core\Event\Event_Model();
$args = array_merge(
$this->get_mockup_event(),
array(
'event_type' => 'online',
'location' => array(
'integration' => 'custom_url',
'custom_url' => 'https://jit.si/eventmeeting',
),
)
);
$event->create( $args );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array();
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Eventin Test Event Title', $event_array['name'] );
$this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] );
$this->assertEquals( 'Europe/Vienna', $event_array['timezone'] );
$this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertEquals( true, $event_array['isOnline'] );
$this->assertContains(
array(
'type' => 'Link',
'mediaType' => 'text/html',
'name' => 'https://jit.si/eventmeeting',
'href' => 'https://jit.si/eventmeeting',
),
$event_array['attachment']
);
}
/**
* Test that the right transformer gets applied.
*/
public function test_eventin_test_online_event_with_physical_location() {
// Create a Eventin Event without content.
$event = new \Etn\Core\Event\Event_Model();
$args = array_merge(
$this->get_mockup_event(),
array(
'event_type' => 'offline',
'location' => array(
'address' => 'The NlNet center',
),
)
);
$event->create( $args );
// Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array();
$this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Eventin Test Event Title', $event_array['name'] );
$this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 15:00:00' ) ), $event_array['startTime'] );
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '+10 days 16:00:00' ) ), $event_array['endTime'] );
$this->assertEquals( 'Europe/Vienna', $event_array['timezone'] );
$this->assertEquals( comments_open( $event->id ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayHasKey( 'location', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] );
$this->assertEquals( false, $event_array['isOnline'] );
$this->assertEquals( 'The NlNet center', $event_array['location']['address'] );
$this->assertEquals( 'The NlNet center', $event_array['location']['name'] );
}
}