]> git.agnieray.net Git - galette.git/commitdiff
Check website URL is valid; closes #1789
authorJohan Cwiklinski <johan@x-tnd.be>
Sat, 17 Feb 2024 21:04:32 +0000 (22:04 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sat, 17 Feb 2024 21:48:10 +0000 (22:48 +0100)
galette/lib/Galette/Core/Preferences.php
tests/Galette/Core/tests/units/Preferences.php

index 03c4f17c93c8352878672a92f1bec045d18b8583..9fdb84615347b480fb19e13b9e16641be3e565f2 100644 (file)
@@ -768,6 +768,11 @@ class Preferences
             case 'pref_footer':
                 $value = $this->cleanHtmlValue($value);
                 break;
+            case 'pref_website':
+                if (!isValidWebUrl($value)) {
+                    $this->errors[] = _T("- Invalid website URL.");
+                }
+                break;
         }
 
         return $value;
index f5a492cc030b14206529dc7910abaa70beb8d556..5b92752ef4acf36b309c09c12691f50ddb3c773a 100644 (file)
@@ -657,4 +657,30 @@ class Preferences extends TestCase
             $legend['socials']['patterns']['asso_social_mynewtype']
         );
     }
+
+    /**
+     * Test website URL
+     *
+     * @return void
+     */
+    public function testWebsiteURL(): void
+    {
+        $preferences = [];
+        foreach ($this->preferences->getDefaults() as $key => $value) {
+            $preferences[$key] = $value;
+        }
+
+        $post = array_merge($preferences, ['pref_website' => 'https://galette.eu']);
+        $this->assertTrue(
+            $this->preferences->check($post, $this->login),
+            print_r($this->preferences->getErrors(), true)
+        );
+
+        $post = array_merge($preferences, ['pref_website' => 'galette.eu']);
+        $this->assertFalse(
+            $this->preferences->check($post, $this->login),
+            print_r($this->preferences->getErrors(), true)
+        );
+        $this->assertSame(['- Invalid website URL.'], $this->preferences->getErrors());
+    }
 }