From f2d22357c565483285887c0226094d3f649e0e4b Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 10 Dec 2024 12:57:20 +0100 Subject: [PATCH] Add required fields and validation checks. --- tests/src/Functional/SettingsTest.php | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/src/Functional/SettingsTest.php b/tests/src/Functional/SettingsTest.php index ed83c8dd..6958b28c 100644 --- a/tests/src/Functional/SettingsTest.php +++ b/tests/src/Functional/SettingsTest.php @@ -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'); } }