Skip to content

Commit

Permalink
Test for empty form fields
Browse files Browse the repository at this point in the history
  • Loading branch information
trymebytes committed Dec 17, 2024
1 parent 26050fe commit 1371aa6
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/event/event-form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_form_name_is_invalid() {
}

public function test_invalid_permissions() {
$event_id = 9999;
$event_id = 9999;
$form_data_1 = $this->event_form_handler_factory->future_inactive_event_form_data( 'create_event', $this->now );
$response_1 = $this->event_form_handler->process_form( $form_data_1 );
$this->assertEquals( 'You do not have permissions to create events.', $response_1->get_error_message() );
Expand All @@ -67,4 +67,37 @@ public function test_invalid_nonce() {
$this->assertArrayHasKey( 'invalid_nonce', $response->error_data );
$this->assertEquals( 'Nonce verification failed.', $response->get_error_message() );
}

/**
* @dataProvider emptyFormDataProvider
*/
public function test_empty_form_fields( $action, $field, $error_key ) {
add_filter( 'gp_translation_events_can_crud_event', '__return_true' );
$form_data = $this->event_form_handler_factory->future_inactive_event_form_data( $action, $this->now );
$form_data[ $field ] = '';
$response = $this->event_form_handler->process_form( $form_data );

$this->assertArrayHasKey( $error_key, $response->error_data );

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that an array has the key 'invalid_title'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that an array has the key 'invalid_title'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that an array has the key 'invalid_start_date'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that an array has the key 'invalid_end_date'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that an array has the key 'invalid_timezone'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that an array has the key 'invalid event_attendance_mode'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that an array has the key 'invalid_title'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that an array has the key 'invalid_title'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that an array has the key 'invalid_start_date'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that an array has the key 'invalid_end_date'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that an array has the key 'invalid_timezone'.

Check failure on line 80 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that an array has the key 'invalid event_attendance_mode'.
}

/**
* Data provider for invalid form data test cases.
*/
public function emptyFormDataProvider() {
return array(
array( 'create_event', 'event_title', 'invalid_title' ),
array( 'create_event', 'event_description', 'invalid_title' ),
array( 'create_event', 'event_start', 'invalid_start_date' ),
array( 'create_event', 'event_end', 'invalid_end_date' ),
array( 'create_event', 'event_timezone', 'invalid_timezone' ),
array( 'create_event', 'event_attendance_mode', 'invalid event_attendance_mode' ),
array( 'edit_event', 'event_title', 'invalid_title' ),
array( 'edit_event', 'event_description', 'invalid_title' ),
array( 'edit_event', 'event_start', 'invalid_start_date' ),
array( 'edit_event', 'event_end', 'invalid_end_date' ),
array( 'edit_event', 'event_timezone', 'invalid_timezone' ),
array( 'edit_event', 'event_attendance_mode', 'invalid event_attendance_mode' ),
);
}

}

Check failure on line 103 in tests/event/event-form-handler.php

View workflow job for this annotation

GitHub Actions / phpcs

The closing brace for the class must go on the next line after the body

0 comments on commit 1371aa6

Please sign in to comment.