WIP: mycalendar transformer closes #54 #57
8 changed files with 446 additions and 3 deletions
|
@ -37,7 +37,7 @@ jobs:
|
|||
path: |
|
||||
${{ env.WP_CORE_DIR }}
|
||||
${{ env.WP_TESTS_DIR }}
|
||||
key: cache-wordpress-9
|
||||
key: cache-wordpress-10
|
||||
|
||||
- name: Cache Composer
|
||||
id: cache-composer-phpunit
|
||||
|
|
|
@ -208,7 +208,7 @@ install_wp_plugin() {
|
|||
fi
|
||||
|
||||
# Get the latest tag.
|
||||
LATEST_TAG=$(svn log https://plugins.svn.wordpress.org/$PLUGIN_NAME/tags --limit 1 | awk 'NR == 4 { print $4 }')
|
||||
LATEST_TAG=$(svn log https://plugins.svn.wordpress.org/$PLUGIN_NAME/tags --limit 1 | awk 'NR == 4 { print $4 }' | sed 's/,$//')
|
||||
if [ -n "$LATEST_TAG" ]; then
|
||||
PLUGIN_FILE="$PLUGIN_NAME.$LATEST_TAG.zip"
|
||||
else
|
||||
|
@ -254,6 +254,7 @@ install_wp_plugins() {
|
|||
install_wp_plugin events-manager
|
||||
install_wp_plugin wp-event-manager
|
||||
install_wp_plugin wp-event-solution
|
||||
install_wp_plugin my-calendar
|
||||
# Mec is not installable via wordpress.org, we use our own mirror.
|
||||
install_wp_plugin_mec
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
],
|
||||
"test-debug": [
|
||||
"@prepare-test",
|
||||
"@test-gatherpress"
|
||||
"@test-my-calendar"
|
||||
],
|
||||
"test-vs-event-list": "phpunit --filter=vs_event_list",
|
||||
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
|
||||
|
@ -67,6 +67,7 @@
|
|||
"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-my-calendar": "phpunit --filter=my_calendar",
|
||||
"test-all": "phpunit"
|
||||
}
|
||||
}
|
||||
|
|
137
includes/activitypub/transformer/class-my-calendar.php
Normal file
137
includes/activitypub/transformer/class-my-calendar.php
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* ActivityPub Transformer for the WordPress plugin "My Calendar – Accessible Event Manager".
|
||||
*
|
||||
* @see https://wordpress.org/plugins/my-calendar/
|
||||
*
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @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 as Event_Transformer;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
|
||||
/**
|
||||
* ActivityPub Transformer for events from the WordPress plugin "My Calendar – Accessible Event Manager".
|
||||
*
|
||||
* @see https://wordpress.org/plugins/my-calendar/
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class My_Calendar extends Event_Transformer {
|
||||
/**
|
||||
* Holds the My Calendar post object.
|
||||
*
|
||||
* @var object $event Event object.
|
||||
*/
|
||||
protected $mc_event;
|
||||
|
||||
/**
|
||||
* Holds the My Calendar Schema object.
|
||||
*
|
||||
* @var array JSON/LD Schema for event.
|
||||
*/
|
||||
protected $mc_event_schema;
|
||||
|
||||
/**
|
||||
* Extend the constructor, to also set the Event plugins API objects.
|
||||
*
|
||||
* 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 );
|
||||
$mc_event_id = get_post_meta( $this->wp_object->ID, '_mc_event_id', true );
|
||||
$this->mc_event = mc_get_event( $mc_event_id );
|
||||
$this->mc_event_schema = mc_event_schema( $this->mc_event );
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats time from the plugin to the activitypub standard.
|
||||
*
|
||||
* @param string $date_string The plugins string representation for a date without time.
|
||||
* @param string $time_string The plugins string representation for a time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function convert_time( $date_string, $time_string ): string {
|
||||
// Create a DateTime object with the given date, time, and timezone.
|
||||
$datetime = new DateTime( $date_string . ' ' . $time_string );
|
||||
|
||||
// Set the timezone for proper formatting.
|
||||
$datetime->setTimezone( new DateTimeZone( 'UTC' ) );
|
||||
|
||||
// Format the DateTime object as 'Y-m-d\TH:i:s\Z'.
|
||||
$formatted_date = $datetime->format( 'Y-m-d\TH:i:s\Z' );
|
||||
return $formatted_date;
|
||||
}
|
||||
/**
|
||||
* Get the start time from the events metadata.
|
||||
*
|
||||
* @return string The events start date-time.
|
||||
*/
|
||||
public function get_start_time(): string {
|
||||
return $this->convert_time( $this->mc_event->event_begin, $this->mc_event->event_time );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time from the events metadata.
|
||||
*
|
||||
* @return string The events start end-time.
|
||||
*/
|
||||
public function get_end_time(): ?string {
|
||||
return $this->convert_time( $this->mc_event->event_end, $this->mc_event->event_endtime );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event location.
|
||||
*
|
||||
* @return Place|null The place/venue if one is set.
|
||||
*/
|
||||
public function get_location(): ?Place {
|
||||
if ( array_key_exists( 'location', $this->mc_event_schema ) && 'Place' === $this->mc_event_schema['location']['@type'] ) {
|
||||
$mc_place = $this->mc_event_schema['location'];
|
||||
|
||||
$place = new Place();
|
||||
$place->set_name( $mc_place['name'] );
|
||||
$place->set_url( $mc_place['url'] );
|
||||
$place->set_address( $mc_place['address'] );
|
||||
|
||||
if ( ! empty( $mc_place['geo'] ) ) {
|
||||
$place->set_latitude( $mc_place['geo']['latitude'] );
|
||||
$place->set_longitude( $mc_place['geo']['longitude'] );
|
||||
}
|
||||
return $place;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status of the event
|
||||
*
|
||||
* @return string status of the event
|
||||
*/
|
||||
public function get_status(): ?string {
|
||||
return 'CONFIRMED'; // My Calendar doesn't implement canceled events.
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the external participation url.
|
||||
*
|
||||
* @return ?string The external participation URL.
|
||||
*/
|
||||
public function get_external_participation_url(): ?string {
|
||||
|
||||
return $this->mc_event->event_tickets ? $this->mc_event->event_tickets : null;
|
||||
}
|
||||
}
|
|
@ -129,6 +129,7 @@ class Setup {
|
|||
'\ActivityPub_Event_Bridge\Plugins\GatherPress',
|
||||
'\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar',
|
||||
'\ActivityPub_Event_Bridge\Plugins\VS_Event_List',
|
||||
'\ActivityPub_Event_Bridge\Plugins\My_Calendar',
|
||||
'\ActivityPub_Event_Bridge\Plugins\WP_Event_Manager',
|
||||
'\ActivityPub_Event_Bridge\Plugins\Eventin',
|
||||
'\ActivityPub_Event_Bridge\Plugins\Modern_Events_Calendar_Lite',
|
||||
|
|
63
includes/plugins/class-my-calendar.php
Normal file
63
includes/plugins/class-my-calendar.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* My Calendar.
|
||||
*
|
||||
* Defines all the necessary meta information for the WordPress event plugin
|
||||
* "My Calendar".
|
||||
*
|
||||
* @link https://wordpress.org/plugins/my-calendar/
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Plugins;
|
||||
|
||||
use Activitypub_Event_Extensions\Event_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 My_Calendar extends Event_Plugin {
|
||||
/**
|
||||
* Returns the full plugin file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_file(): string {
|
||||
return 'my-calendar/my-calendar.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the event post type of the plugin.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_post_type(): string {
|
||||
return 'mc-events';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'my-calendar-config';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the taxonomy used for the plugin's event categories.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_event_category_taxonomy(): string {
|
||||
return 'mc-event-category';
|
||||
}
|
||||
}
|
|
@ -71,6 +71,9 @@ function _manually_load_plugin() {
|
|||
case 'wp_event_manager':
|
||||
$plugin_file = 'wp-event-manager/wp-event-manager.php';
|
||||
break;
|
||||
case 'my_calendar':
|
||||
$plugin_file = 'my-calendar/my-calendar.php';
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $plugin_file ) {
|
||||
|
@ -97,6 +100,11 @@ function _manually_load_plugin() {
|
|||
$mec_factory->install();
|
||||
}
|
||||
|
||||
if ( 'my_calendar' === $activitypub_event_extension_integration_filter ) {
|
||||
require_once $plugin_dir . 'my-calendar/my-calendar.php';
|
||||
add_action( 'init', 'mc_default_settings' );
|
||||
}
|
||||
|
||||
// At last manually load our WordPress plugin.
|
||||
require dirname( __DIR__ ) . '/activitypub-event-bridge.php';
|
||||
}
|
||||
|
|
232
tests/test-class-plugin-my-calendar.php
Normal file
232
tests/test-class-plugin-my-calendar.php
Normal file
|
@ -0,0 +1,232 @@
|
|||
<?php
|
||||
/**
|
||||
* Test class for My Calendar.
|
||||
*
|
||||
* @package ActivityPub_Event_Bridge
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for My Calendar.
|
||||
*/
|
||||
class Test_My_Calendar extends WP_UnitTestCase {
|
||||
/**
|
||||
* Mockup Event.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mockup_event;
|
||||
|
||||
/**
|
||||
* Mockup Location.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mockup_location;
|
||||
|
||||
/**
|
||||
* Mockup Category.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mockup_category;
|
||||
|
||||
/**
|
||||
* Setup mockup data.
|
||||
*/
|
||||
private function setUpMockupEvents() {
|
||||
$this->mockup_event = array(
|
||||
// Begin strings.
|
||||
'event_begin' => date( 'Y-m-d', strtotime( '+10 days' ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
'event_end' => date( 'Y-m-d', strtotime( '+10 days', ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
'event_title' => 'Demo: Florence Price: Symphony No. 3 in c minor',
|
||||
'event_desc' => "<p>Florence Price's <a href='https://en.wikipedia.org/wiki/Symphony_No._3_(Price)'>Symphony No. 3</a> was commissioned by the Works Progress Administration's <a href='https://en.wikipedia.org/wiki/Federal_Music_Project'>Federal Music Project</a> during the height of the Great Depression. It was first performed at the Detroit Institute of Arts on November 6, 1940, by the Detroit Civic Orchestra under the conductor Valter Poole.</p><p>The composition is Price's third symphony, following her Symphony in E minor—the first symphony by a black woman to be performed by a major American orchestra—and her lost Symphony No. 2.</p>",
|
||||
'event_short' => "Florence Price's Symphony No.3 was first performed on November 6th, 1940. It was Ms. Price's third symphony, following her lost Symphony No. 2",
|
||||
'event_time' => '15:00:00',
|
||||
'event_endtime' => '16:00:00',
|
||||
'event_link' => 'https://www.youtube.com/watch?v=1jgJ1OkjnaI&list=OLAK5uy_lKldgbFTYBDa7WN6jf2ubB595wncDU7yc&index=2',
|
||||
'event_recur' => 'S1',
|
||||
'event_image' => plugins_url( '/.wordpress-org/banner-772x250.jpg', ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_FILE ),
|
||||
'event_access' => '',
|
||||
'event_tickets' => '',
|
||||
'event_registration' => '',
|
||||
'event_repeats' => '',
|
||||
// Begin integers.
|
||||
'event_author' => wp_get_current_user()->ID,
|
||||
'event_category' => 1,
|
||||
'event_link_expires' => 0,
|
||||
'event_zoom' => 16,
|
||||
'event_approved' => 1,
|
||||
'event_host' => wp_get_current_user()->ID,
|
||||
'event_flagged' => 0,
|
||||
'event_fifth_week' => 0,
|
||||
'event_holiday' => 0,
|
||||
'event_group_id' => 1,
|
||||
'event_span' => 0,
|
||||
'event_hide_end' => 0,
|
||||
// Array: removed before DB insertion.
|
||||
'event_categories' => array( 1 ),
|
||||
);
|
||||
|
||||
$access = array( 1, 2, 3, 4, 6, 8, 9 );
|
||||
|
||||
$this->mockup_location = array(
|
||||
'location_label' => 'Demo: Minnesota Orchestra',
|
||||
'location_street' => '1111 Nicollet Mall',
|
||||
'location_street2' => '',
|
||||
'location_city' => 'Minneapolis',
|
||||
'location_state' => 'MN',
|
||||
'location_postcode' => '55403',
|
||||
'location_region' => '',
|
||||
'location_country' => 'United States',
|
||||
'location_url' => 'https://www.minnesotaorchestra.org',
|
||||
'location_latitude' => '44.9722',
|
||||
'location_longitude' => '-93.2749',
|
||||
'location_zoom' => 16,
|
||||
'location_phone' => '612-371-5600',
|
||||
'location_phone2' => '',
|
||||
'location_access' => serialize( $access ),
|
||||
);
|
||||
|
||||
$this->mockup_category = array(
|
||||
'category_name' => 'General',
|
||||
'category_color' => '#243f82',
|
||||
'category_icon' => 'event.svg',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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( 'mc_get_event' ) ) {
|
||||
self::markTestSkipped( 'My Calendar plugin is not active.' );
|
||||
}
|
||||
|
||||
self::setUpMockupEvents();
|
||||
|
||||
// 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_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( 'mc-events', get_option( 'activitypub_support_post_types' ) );
|
||||
|
||||
// mc_create_category( $this->mockup_category );
|
||||
// $location = mc_insert_location( $this->mockup_location );
|
||||
// $location = apply_filters( 'mc_save_location', $location, $this->mockup_location, $this->mockup_location );
|
||||
// $event = array( true, false, $this->mockup_event, false, array() );
|
||||
// $event = my_calendar_save( 'add', $event );
|
||||
// mc_update_event( 'event_location', (int) $location, $event['event_id'] );
|
||||
|
||||
// Insert a category.
|
||||
mc_create_category(
|
||||
array(
|
||||
'category_name' => 'General',
|
||||
'category_color' => '#243f82',
|
||||
'category_icon' => 'event.svg',
|
||||
)
|
||||
);
|
||||
// Insert a location.
|
||||
$access = array( 1, 2, 3, 4, 6, 8, 9 );
|
||||
$add = array(
|
||||
'location_label' => 'Demo: Minnesota Orchestra',
|
||||
'location_street' => '1111 Nicollet Mall',
|
||||
'location_street2' => '',
|
||||
'location_city' => 'Minneapolis',
|
||||
'location_state' => 'MN',
|
||||
'location_postcode' => '55403',
|
||||
'location_region' => '',
|
||||
'location_country' => 'United States',
|
||||
'location_url' => 'https://www.minnesotaorchestra.org',
|
||||
'location_latitude' => '44.9722',
|
||||
'location_longitude' => '-93.2749',
|
||||
'location_zoom' => 16,
|
||||
'location_phone' => '612-371-5600',
|
||||
'location_phone2' => '',
|
||||
'location_access' => serialize( $access ),
|
||||
);
|
||||
$results = mc_insert_location( $add );
|
||||
/**
|
||||
* Executed an action when the demo location is saved at installation.
|
||||
*
|
||||
* @hook mc_save_location
|
||||
*
|
||||
* @param {int|false} $results Result of database insertion. Row ID or false.
|
||||
* @param {array} $add Array of location parameters to add.
|
||||
* @param {array} $add Demo location array.
|
||||
*/
|
||||
$results = apply_filters( 'mc_save_location', $results, $add, $add );
|
||||
// Insert an event.
|
||||
$submit = array(
|
||||
// Begin strings.
|
||||
'event_begin' => date( 'Y-m-d', strtotime( '+1 day' ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
'event_end' => date( 'Y-m-d', strtotime( '+1 day' ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
'event_title' => 'Demo: Florence Price: Symphony No. 3 in c minor',
|
||||
'event_desc' => "<p>Florence Price's <a href='https://en.wikipedia.org/wiki/Symphony_No._3_(Price)'>Symphony No. 3</a> was commissioned by the Works Progress Administration's <a href='https://en.wikipedia.org/wiki/Federal_Music_Project'>Federal Music Project</a> during the height of the Great Depression. It was first performed at the Detroit Institute of Arts on November 6, 1940, by the Detroit Civic Orchestra under the conductor Valter Poole.</p><p>The composition is Price's third symphony, following her Symphony in E minor—the first symphony by a black woman to be performed by a major American orchestra—and her lost Symphony No. 2.</p>",
|
||||
'event_short' => "Florence Price's Symphony No.3 was first performed on November 6th, 1940. It was Ms. Price's third symphony, following her lost Symphony No. 2",
|
||||
'event_time' => '19:30:00',
|
||||
'event_endtime' => '21:00:00',
|
||||
'event_link' => 'https://www.youtube.com/watch?v=1jgJ1OkjnaI&list=OLAK5uy_lKldgbFTYBDa7WN6jf2ubB595wncDU7yc&index=2',
|
||||
'event_recur' => 'S1',
|
||||
'event_image' => plugins_url( '/images/demo/event.jpg', __FILE__ ),
|
||||
'event_access' => '',
|
||||
'event_tickets' => '',
|
||||
'event_registration' => '',
|
||||
'event_repeats' => '',
|
||||
// Begin integers.
|
||||
'event_author' => wp_get_current_user()->ID,
|
||||
'event_category' => 1,
|
||||
'event_link_expires' => 0,
|
||||
'event_zoom' => 16,
|
||||
'event_approved' => 1,
|
||||
'event_host' => wp_get_current_user()->ID,
|
||||
'event_flagged' => 0,
|
||||
'event_fifth_week' => 0,
|
||||
'event_holiday' => 0,
|
||||
'event_group_id' => 1,
|
||||
'event_span' => 0,
|
||||
'event_hide_end' => 0,
|
||||
// Array: removed before DB insertion.
|
||||
'event_categories' => array( 1 ),
|
||||
);
|
||||
|
||||
$event = array( true, false, $submit, false, array() );
|
||||
$response = my_calendar_save( 'add', $event );
|
||||
$event_id = $response['event_id'];
|
||||
$r = mc_update_event( 'event_location', (int) $results, $event_id );
|
||||
|
||||
$e = mc_get_first_event( $event_id );
|
||||
$post_id = $e->event_post;
|
||||
$image = media_sideload_image( plugins_url( '/images/demo/event.jpg', __FILE__ ), $post_id, null, 'id' );
|
||||
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
set_post_thumbnail( $post_id, $image );
|
||||
}
|
||||
|
||||
$wp_object = get_post( $event['event_post'] );
|
||||
|
||||
// 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\My_Calendar::class, $transformer );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue