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

This commit is contained in:
André Menrath 2024-10-12 20:20:17 +02:00
parent aaa0ffc026
commit 7151f186b9
2 changed files with 107 additions and 41 deletions

View file

@ -53,16 +53,14 @@ final class Eventin extends Event {
* Get the end time from the event object. * Get the end time from the event object.
*/ */
public function get_start_time(): string { public function get_start_time(): string {
$datetime = new DateTime( $this->event_model->get_start_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) ); return \gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $this->event_model->get_start_datetime() ) );
return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() );
} }
/** /**
* Get the end time from the event object. * Get the end time from the event object.
*/ */
public function get_end_time(): string { public function get_end_time(): string {
$datetime = new DateTime( $this->event_model->get_end_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) ); return \gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $this->event_model->get_end_datetime() ) );
return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() );
} }
/** /**

View file

@ -9,6 +9,22 @@
* Test cases for WP Event Solution. * Test cases for WP Event Solution.
*/ */
class Test_Eventin extends WP_UnitTestCase { 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. * Override the setup function, so that tests don't run if the Events Calendar is not active.
*/ */
@ -41,22 +57,11 @@ class Test_Eventin extends WP_UnitTestCase {
$this->assertContains( 'etn', get_option( 'activitypub_support_post_types' ) ); $this->assertContains( 'etn', get_option( 'activitypub_support_post_types' ) );
// Create a Eventin Event without content. // Create a Eventin Event without content.
$event_model = new \Etn\Core\Event\Event_Model(); $event = new \Etn\Core\Event\Event_Model();
$event_model->create( $event->create( $this->get_mockup_event() );
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 15:00:00' ) ),
'event_timezone' => 'Europe/Vienna',
)
);
// Call the transformer Factory. // Call the transformer Factory.
$transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event_model->id ) ); $transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) );
// Check that we got the right transformer. // Check that we got the right transformer.
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer ); $this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer );
@ -66,29 +71,9 @@ class Test_Eventin extends WP_UnitTestCase {
* Test that the right transformer gets applied. * Test that the right transformer gets applied.
*/ */
public function test_eventin_test_minimal_event() { public function test_eventin_test_minimal_event() {
// 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. // Create a Eventin Event without content.
$event = new \Etn\Core\Event\Event_Model(); $event = new \Etn\Core\Event\Event_Model();
$event->create( $event->create( $this->get_mockup_event() );
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' => '03:00 PM',
'etn_end_time' => '04:00 PM',
'event_timezone' => 'Europe/Vienna',
)
);
// Call the transformer Factory. // Call the transformer Factory.
$event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array(); $event_array = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) )->to_object()->to_array();
@ -96,12 +81,95 @@ class Test_Eventin extends WP_UnitTestCase {
$this->assertEquals( 'Event', $event_array['type'] ); $this->assertEquals( 'Event', $event_array['type'] );
$this->assertEquals( 'Eventin Test Event Title', $event_array['name'] ); $this->assertEquals( 'Eventin Test Event Title', $event_array['name'] );
$this->assertEquals( 'Eventin Test Event Description', wp_strip_all_tags( $event_array['content'] ) ); $this->assertEquals( 'Eventin Test Event 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\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 ), $event_array['commentsEnabled'] );
$this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] ); $this->assertEquals( comments_open( $event->id ) ? 'allow_all' : 'closed', $event_array['repliesModerationOption'] );
$this->assertEquals( 'external', $event_array['joinMode'] ); $this->assertEquals( 'external', $event_array['joinMode'] );
$this->assertArrayNotHasKey( 'location', $event_array ); $this->assertArrayNotHasKey( 'location', $event_array );
$this->assertArrayNotHasKey( 'endTime', $event_array );
$this->assertEquals( 'MEETING', $event_array['category'] ); $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'] );
} }
} }