Add options for summary #80
5 changed files with 231 additions and 14 deletions
|
@ -75,6 +75,12 @@ jobs:
|
|||
if: steps.cache-wordpress.outputs.cache-hit != 'false'
|
||||
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wordpress-version }} false true true true
|
||||
|
||||
|
||||
- name: Run General Tests
|
||||
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=activitypub_event_bridge
|
||||
env:
|
||||
PHP_VERSION: ${{ matrix.php-version }}
|
||||
|
||||
- name: Run Integration tests for The Events Calendar
|
||||
run: cd /workspace/Event-Federation/wordpress-activitypub-event-bridge/ && ./vendor/bin/phpunit --filter=the_events_calendar
|
||||
env:
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
],
|
||||
"test-debug": [
|
||||
"@prepare-test",
|
||||
"@test-gatherpress"
|
||||
"@test-activitypub-event-bridge-shortcodes"
|
||||
],
|
||||
"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-activitypub-event-bridge-shortcodes": "phpunit --filter=activitypub_event_bridge_shortcodes",
|
||||
"test-all": "phpunit"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,13 +245,13 @@ abstract class Event extends Post {
|
|||
$args = shortcode_atts(
|
||||
array(
|
||||
'icon' => 'true',
|
||||
'title' => 'true',
|
||||
'label' => 'true',
|
||||
),
|
||||
$atts
|
||||
);
|
||||
|
||||
$args['icon'] = filter_var( $args['icon'], FILTER_VALIDATE_BOOLEAN );
|
||||
$args['title'] = filter_var( $args['title'], FILTER_VALIDATE_BOOLEAN );
|
||||
$args['label'] = filter_var( $args['label'], FILTER_VALIDATE_BOOLEAN );
|
||||
|
||||
$output = array();
|
||||
|
||||
|
@ -259,7 +259,7 @@ abstract class Event extends Post {
|
|||
$output[] = $icon;
|
||||
}
|
||||
|
||||
if ( $args['title'] ) {
|
||||
if ( $args['label'] ) {
|
||||
$output[] = $label . ':';
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ abstract class Event extends Post {
|
|||
$args = shortcode_atts(
|
||||
array(
|
||||
'icon' => 'true',
|
||||
'title' => 'true',
|
||||
'label' => 'true',
|
||||
'country' => 'true',
|
||||
'zip' => 'true',
|
||||
'city' => 'true',
|
||||
|
@ -306,7 +306,7 @@ abstract class Event extends Post {
|
|||
if ( $args['icon'] ) {
|
||||
$output[] = '📍';
|
||||
}
|
||||
if ( $args['title'] ) {
|
||||
if ( $args['label'] ) {
|
||||
$output[] = esc_html__( 'Location', 'activitypub-event-bridge' ) . ':';
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,10 @@ abstract class Event extends Post {
|
|||
$start_time = $this->get_start_time();
|
||||
$end_time = $this->get_end_time();
|
||||
$address = $this->format_address( $this->get_location() );
|
||||
$time_atts = array( 'icon' => true, 'label' => true);
|
||||
$time_atts = array(
|
||||
'icon' => true,
|
||||
'label' => true,
|
||||
);
|
||||
|
||||
$formatted_items = array();
|
||||
if ( ! empty( $category ) ) {
|
||||
|
|
|
@ -25,6 +25,21 @@ if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
|
|||
// Give access to tests_add_filter() function.
|
||||
require_once "{$_tests_dir}/includes/functions.php";
|
||||
|
||||
/**
|
||||
* Function to manually load an event plugin.
|
||||
*
|
||||
* @param string $plugin_file The main plugin file of the event plugin.
|
||||
*/
|
||||
function _manually_load_event_plugin( $plugin_file ) {
|
||||
$plugin_dir = ABSPATH . '/wp-content/plugins/';
|
||||
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 );
|
||||
update_option( 'active_plugins', $current );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually load the plugin being tested and its integrations.
|
||||
*/
|
||||
|
@ -74,13 +89,12 @@ 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 );
|
||||
update_option( 'active_plugins', $current );
|
||||
_manually_load_event_plugin( $plugin_file );
|
||||
} else {
|
||||
// For all other tests we mainly use the Events Calendar as a reference.
|
||||
_manually_load_event_plugin( 'the-events-calendar/the-events-calendar.php' );
|
||||
_manually_load_event_plugin( 'very-simple-event-list/vsel.php' );
|
||||
|
||||
}
|
||||
|
||||
// Hot fix that allows using Events Manager within unit tests, because the em_init() is later not run as admin.
|
||||
|
|
193
tests/test-class-activitypub-event-bridge-shortcodes.php
Normal file
193
tests/test-class-activitypub-event-bridge-shortcodes.php
Normal file
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
/**
|
||||
* Test file for Activitypub Shortcodes.
|
||||
*
|
||||
* @package ActivityPub_Event_Bridge
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use Activitypub\Shortcodes;
|
||||
|
||||
/**
|
||||
* Test class for Activitypub Shortcodes.
|
||||
*
|
||||
* @coversDefaultClass \Activitypub\Shortcodes
|
||||
*/
|
||||
class Test_Activitypub_Event_Bridge_Shortcodes 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 ( ! class_exists( '\Tribe__Events__Main' ) ) {
|
||||
self::markTestSkipped( 'The Events Calendar plugin is needed to test Event Shortcodes' );
|
||||
}
|
||||
|
||||
// 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 the shortcode for rendering the events start time.
|
||||
*/
|
||||
public function test_start_time() {
|
||||
// Create a The Events Calendar Event without content.
|
||||
$wp_object = tribe_events()
|
||||
->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] )
|
||||
->create();
|
||||
|
||||
// Call the transformer Factory.
|
||||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$transformer->register_shortcodes();
|
||||
|
||||
$summary = '[ap_start_time]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( '🗓️ Start: December 1, 2024 3:00 pm', $summary );
|
||||
|
||||
$summary = '[ap_start_time icon="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( 'Start: December 1, 2024 3:00 pm', $summary );
|
||||
|
||||
$summary = '[ap_start_time icon="false" label="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( 'December 1, 2024 3:00 pm', $summary );
|
||||
|
||||
$transformer->unregister_shortcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the shortcode for rendering the events end time.
|
||||
*/
|
||||
public function test_end_time() {
|
||||
// Create a The Events Calendar Event without content.
|
||||
$wp_object = tribe_events()
|
||||
->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] )
|
||||
->create();
|
||||
|
||||
// Call the transformer Factory.
|
||||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$transformer->register_shortcodes();
|
||||
|
||||
$summary = '[ap_end_time]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( '⏳ End: December 1, 2024 4:00 pm', $summary );
|
||||
|
||||
$summary = '[ap_end_time icon="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( 'End: December 1, 2024 4:00 pm', $summary );
|
||||
|
||||
$summary = '[ap_end_time icon="false" label="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( 'December 1, 2024 4:00 pm', $summary );
|
||||
|
||||
$transformer->unregister_shortcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the shortcode for rendering the events location when no location is set.
|
||||
*/
|
||||
public function test_location_when_no_location_is_set() {
|
||||
// Create a The Events Calendar Event without content.
|
||||
$wp_object = tribe_events()
|
||||
->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['minimal_event'] )
|
||||
->create();
|
||||
|
||||
// Call the transformer Factory.
|
||||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$transformer->register_shortcodes();
|
||||
|
||||
$summary = '[ap_location]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( '', $summary );
|
||||
|
||||
$transformer->unregister_shortcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the shortcode for rendering the events location when location is set.
|
||||
*/
|
||||
public function test_location_when_location_is_set() {
|
||||
// Create Venue.
|
||||
$venue = tribe_venues()->set_args( Test_The_Events_Calendar::MOCKUP_VENUS['minimal_venue'] )->create();
|
||||
// Create a The Events Calendar Event.
|
||||
$wp_object = tribe_events()
|
||||
->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['complex_event'] )
|
||||
->set( 'venue', $venue->ID )
|
||||
->create();
|
||||
|
||||
// Call the transformer Factory.
|
||||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$transformer->register_shortcodes();
|
||||
|
||||
$summary = '[ap_location]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( '📍 Location: Minimal Venue', $summary );
|
||||
|
||||
$summary = '[ap_location icon="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( 'Location: Minimal Venue', $summary );
|
||||
|
||||
$summary = '[ap_location icon="false" label="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( 'Minimal Venue', $summary );
|
||||
|
||||
$transformer->unregister_shortcodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the shortcode for rendering the events location when location with detailed address is set.
|
||||
*/
|
||||
public function test_location_when_detailed_location_is_set() {
|
||||
// Create Venue.
|
||||
$venue = tribe_venues()->set_args( Test_The_Events_Calendar::MOCKUP_VENUS['complex_venue'] )->create();
|
||||
// Create a The Events Calendar Event.
|
||||
$wp_object = tribe_events()
|
||||
->set_args( Test_The_Events_Calendar::MOCKUP_EVENTS['complex_event'] )
|
||||
->set( 'venue', $venue->ID )
|
||||
->create();
|
||||
|
||||
// Call the transformer Factory.
|
||||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
if ( ! $transformer instanceof \ActivityPub_Event_Bridge\Activitypub\Transformer\Event ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$transformer->register_shortcodes();
|
||||
|
||||
$summary = '[ap_location]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( '📍 Location: Complex Venue, Venue address, Venue zip, Venue city, Venue country', $summary );
|
||||
|
||||
$summary = '[ap_location country="false"]';
|
||||
$summary = do_shortcode( $summary );
|
||||
$this->assertEquals( '📍 Location: Complex Venue, Venue address, Venue zip, Venue city', $summary );
|
||||
|
||||
$transformer->unregister_shortcodes();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue