Skip to content

Commit

Permalink
Add required fields and validation checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronGilMartinez committed Dec 10, 2024
1 parent 7df65bf commit f2d2235
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/src/Functional/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,39 @@ public function testSettingsForm(): void {
// Check the values in fields.
$this->drupalGet(Url::fromRoute('collabora-online.settings'));
$assert_session->fieldValueEquals('Collabora Online server URL', 'http://collaboraserver.com/');
// Slash is removed at the end of Wopi URL.
$assert_session->fieldValueEquals('WOPI host URL', 'http://wopihost.com');
$assert_session->fieldValueEquals('JWT private key ID', 'a_random_token');
$assert_session->fieldValueEquals('Access Token Expiration (in seconds)', '3600');
$assert_session->fieldValueEquals('Disable TLS certificate check for COOL.', '1');
$assert_session->fieldValueEquals('Allow COOL to use fullscreen mode.', '');

// Check required fields, set empty values and check errors displayed.
$this->drupalGet(Url::fromRoute('collabora-online.settings'));
$assert_session->fieldExists('Collabora Online server URL')->setValue('');
$assert_session->fieldExists('WOPI host URL')->setValue('');
$assert_session->fieldExists('JWT private key ID')->setValue('');
$assert_session->fieldExists('Access Token Expiration (in seconds)')->setValue('');
$assert_session->fieldExists('Disable TLS certificate check for COOL.')->uncheck();
$assert_session->fieldExists('Allow COOL to use fullscreen mode.')->uncheck();
$assert_session->buttonExists('Save configuration')->press();
$assert_session->statusMessageContains('Collabora Online server URL field is required.', 'error');
$assert_session->statusMessageContains('WOPI host URL field is required.', 'error');
$assert_session->statusMessageContains('JWT private key ID field is required.', 'error');
$assert_session->statusMessageContains('Access Token Expiration (in seconds) field is required.', 'error');
$assert_session->statusMessageNotContains('The configuration options have been saved.', 'status');

// Check validation for fields.
$this->drupalGet(Url::fromRoute('collabora-online.settings'));
// Set invalid value for URL fields.
$assert_session->fieldExists('Collabora Online server URL')->setValue('/internal');
$assert_session->fieldExists('WOPI host URL')->setValue('any-other-value');
// Set invalid values for numeric field.
$assert_session->fieldExists('Access Token Expiration (in seconds)')->setValue('text');
$assert_session->buttonExists('Save configuration')->press();
$assert_session->statusMessageContains('The URL /internal is not valid.', 'error');
$assert_session->statusMessageContains('The URL any-other-value is not valid.', 'error');
$assert_session->statusMessageNotContains('Access Token Expiration (in seconds) must be a number.', 'status');
}

}

0 comments on commit f2d2235

Please sign in to comment.