From 94c8a5258c72be6b66eac41e342d56e9b1271c58 Mon Sep 17 00:00:00 2001 From: Tosin Oguntuyi Date: Wed, 11 Dec 2024 01:55:13 +0100 Subject: [PATCH] Add test for non-logged in user --- tests/event/event-form-handler.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/event/event-form-handler.php b/tests/event/event-form-handler.php index b81386c2..2bc67fa9 100644 --- a/tests/event/event-form-handler.php +++ b/tests/event/event-form-handler.php @@ -6,18 +6,32 @@ use Wporg\TranslationEvents\Attendee\Attendee_Repository; use Wporg\TranslationEvents\Event\Event_Repository; use Wporg\TranslationEvents\Event\Event_Form_Handler; - - +use Wporg\TranslationEvents\Tests\Event_Form_Handler_Factory; class Event_Form_Handler_Test extends Base_Test { private Event_Repository $event_repository; private Attendee_Repository $attendee_repository; - private $event_form_handler; + private Event_Form_Handler $event_form_handler; + private Event_Form_Handler_Factory $event_form_handler_factory; public function setUp(): void { parent::setUp(); - $this->attendee_repository = new Attendee_Repository(); - $this->event_repository = new Event_Repository( $this->now, $this->attendee_repository ); - $this->event_form_handler = new Event_Form_Handler( $this->now, $this->event_repository ); + $this->attendee_repository = new Attendee_Repository(); + $this->event_repository = new Event_Repository( $this->now, $this->attendee_repository ); + $this->event_form_handler = new Event_Form_Handler( $this->now, $this->event_repository ); + $this->event_form_handler_factory = new Event_Form_Handler_Factory(); + } + + /** + * Test that the user must be logged in to create an event. + * + * @return void + */ + public function test_user_is_not_logged_in() { + wp_set_current_user( 0 ); + $form_data = $this->event_form_handler_factory->future_inactive_event_form_data( 'create_event', $this->now ); + $response = $this->event_form_handler->handle( $form_data ); + + $this->assertEquals( '{"success":false,"data":"The user must be logged in."}', $response ); } }