add tests for venue and join mode is always external
This commit is contained in:
parent
893f1d3b7c
commit
1764a7b03f
3 changed files with 63 additions and 14 deletions
|
@ -72,6 +72,29 @@ class Event extends Post {
|
||||||
$this->wp_taxonomy = $wp_taxonomy;
|
$this->wp_taxonomy = $wp_taxonomy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the join mode.
|
||||||
|
*
|
||||||
|
* Currently we don't handle joins, we always mark events as external.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_join_mode() {
|
||||||
|
return 'external';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the external participation url.
|
||||||
|
*
|
||||||
|
* Currently we don't handle joins, we always mark events as external.
|
||||||
|
* We just link back to the events HTML representation on our WordPress site.
|
||||||
|
*
|
||||||
|
* @return string|null The external participation URL.
|
||||||
|
*/
|
||||||
|
public function get_external_participation_url(): string|null {
|
||||||
|
return 'external' === $this->get_join_mode() ? $this->get_url() : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the event category, via the mapping setting.
|
* Set the event category, via the mapping setting.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -96,17 +96,6 @@ final class The_Events_Calendar extends Event {
|
||||||
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
|
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the join mode.
|
|
||||||
*
|
|
||||||
* If the ticket sale is active set it to restricted.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function get_join_mode() {
|
|
||||||
return empty( $this->tribe_event->tickets ) ? 'free' : 'restricted';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the comments are enabled for the current event.
|
* Check if the comments are enabled for the current event.
|
||||||
*/
|
*/
|
||||||
|
@ -183,6 +172,9 @@ final class The_Events_Calendar extends Event {
|
||||||
if ( ! empty( $venue->address ) ) {
|
if ( ! empty( $venue->address ) ) {
|
||||||
$address['streetAddress'] = $venue->address;
|
$address['streetAddress'] = $venue->address;
|
||||||
}
|
}
|
||||||
|
if ( ! empty( $venue->post_title ) ) {
|
||||||
|
$address['name'] = $venue->post_title;
|
||||||
|
}
|
||||||
$address['type'] = 'PostalAddress';
|
$address['type'] = 'PostalAddress';
|
||||||
|
|
||||||
$location = new Place();
|
$location = new Place();
|
||||||
|
|
|
@ -114,7 +114,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase {
|
||||||
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
|
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
|
||||||
$this->assertTrue( $event_array['commentsEnabled'] );
|
$this->assertTrue( $event_array['commentsEnabled'] );
|
||||||
$this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] );
|
$this->assertEquals( 'allow_all', $event_array['repliesModerationOption'] );
|
||||||
$this->assertEquals( 'free', $event_array['joinMode'] );
|
$this->assertEquals( 'external', $event_array['joinMode'] );
|
||||||
$this->assertArrayNotHasKey( 'location', $event_array );
|
$this->assertArrayNotHasKey( 'location', $event_array );
|
||||||
$this->assertEquals( 'MEETING', $event_array['category'] );
|
$this->assertEquals( 'MEETING', $event_array['category'] );
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase {
|
||||||
$this->assertEquals( 'MUSIC', $event_array['category'] );
|
$this->assertEquals( 'MUSIC', $event_array['category'] );
|
||||||
|
|
||||||
// Set the post term theatre to the event.
|
// Set the post term theatre to the event.
|
||||||
wp_set_post_terms( $wp_object->ID, $category_id_theatre['term_id'], Tribe__Events__Main::TAXONOMY );
|
wp_set_post_terms( $wp_object->ID, $category_id_theatre['term_id'], Tribe__Events__Main::TAXONOMY, false );
|
||||||
// Call the transformer.
|
// Call the transformer.
|
||||||
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
|
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
|
||||||
// See if the default category mapping is applied.
|
// See if the default category mapping is applied.
|
||||||
|
@ -174,9 +174,43 @@ class Test_The_Events_Calendar extends WP_UnitTestCase {
|
||||||
$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 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( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
|
||||||
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] );
|
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] );
|
||||||
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
|
|
||||||
$this->assertArrayHasKey( 'location', $event_array );
|
$this->assertArrayHasKey( 'location', $event_array );
|
||||||
$this->assertEquals( 'Place', $event_array['location']['type'] );
|
$this->assertEquals( 'Place', $event_array['location']['type'] );
|
||||||
$this->assertEquals( self::MOCKUP_VENUS['minimal_venue']['venue'], $event_array['location']['name'] );
|
$this->assertEquals( self::MOCKUP_VENUS['minimal_venue']['venue'], $event_array['location']['name'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test transformation of minimal event with minimal venue.
|
||||||
|
*/
|
||||||
|
public function test_transform_of_minimal_event_with_address_venue() {
|
||||||
|
// Create Venue.
|
||||||
|
$venue = tribe_venues()->set_args( self::MOCKUP_VENUS['complex_venue'] )->create();
|
||||||
|
// Create a The Events Calendar Event.
|
||||||
|
$wp_object = tribe_events()
|
||||||
|
->set_args( self::MOCKUP_EVENTS['minimal_event'] )
|
||||||
|
->set( 'venue', $venue->ID )
|
||||||
|
->create();
|
||||||
|
|
||||||
|
// Call the transformer.
|
||||||
|
$event_array = \Activitypub\Transformer\Factory::get_transformer( $wp_object )->to_object()->to_array();
|
||||||
|
|
||||||
|
// Check that the event ActivityStreams representation contains everything as expected.
|
||||||
|
$this->assertEquals( 'Event', $event_array['type'] );
|
||||||
|
$this->assertEquals( 'My Event', $event_array['name'] );
|
||||||
|
$this->assertEquals( '', $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( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['commentsEnabled'] );
|
||||||
|
$this->assertEquals( gmdate( 'Y-m-d', strtotime( '+10 days 16:00:00' ) ) . 'T16:00:00Z', $event_array['endTime'] );
|
||||||
|
$this->assertArrayHasKey( 'location', $event_array );
|
||||||
|
$this->assertEquals( 'Place', $event_array['location']['type'] );
|
||||||
|
$this->assertEquals( 'PostalAddress', $event_array['location']['address']['type'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['venue'], $event_array['location']['name'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['venue'], $event_array['location']['address']['name'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['province'], $event_array['location']['address']['addressRegion'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['address'], $event_array['location']['address']['streetAddress'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['city'], $event_array['location']['address']['addressLocality'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['country'], $event_array['location']['address']['addressCountry'] );
|
||||||
|
$this->assertEquals( self::MOCKUP_VENUS['complex_venue']['zip'], $event_array['location']['address']['postalCode'] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue