]> git.agnieray.net Git - galette.git/blobdiff - tests/Galette/Core/tests/units/Preferences.php
Add pre_footer in replacements; closes #1808
[galette.git] / tests / Galette / Core / tests / units / Preferences.php
index 43196c286c15dae6fc51d1bc86eeb8d6bbc8021a..ba6fa8fc7b14a523b468ad79bf1b84b1e03c1428 100644 (file)
@@ -7,7 +7,7 @@
  *
  * PHP version 5
  *
- * Copyright © 2013-2023 The Galette Team
+ * Copyright © 2013-2024 The Galette Team
  *
  * This file is part of Galette (http://galette.tuxfamily.org).
  *
@@ -28,7 +28,7 @@
  * @package   GaletteTests
  *
  * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2013-2023 The Galette Team
+ * @copyright 2013-2024 The Galette Team
  * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
  * @link      http://galette.tuxfamily.org
  * @since     2013-10-19
@@ -36,6 +36,7 @@
 
 namespace Galette\Core\test\units;
 
+use PHPMailer\PHPMailer\PHPMailer;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -45,7 +46,7 @@ use PHPUnit\Framework\TestCase;
  * @name      Preferences
  * @package   GaletteTests
  * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2013-2023 The Galette Team
+ * @copyright 2013-2024 The Galette Team
  * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
  * @link      http://galette.tuxfamily.org
  * @since     2013-01-13
@@ -563,14 +564,21 @@ class Preferences extends TestCase
      */
     public function testGetMailSignature()
     {
-        $this->assertSame("\r\n-- \r\nGalette\r\n\r\n", $this->preferences->getMailSignature());
+        $mail = new PHPMailer();
+        $this->assertSame("\r\n-- \r\nGalette", $this->preferences->getMailSignature($mail));
 
         $this->preferences->pref_website = 'https://galette.eu';
-        $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu", $this->preferences->getMailSignature());
+        $this->assertSame(
+            "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu",
+            $this->preferences->getMailSignature($mail)
+        );
 
         //with legacy values
-        $this->preferences->pref_mailsign = "NAME}\r\n\r\n{WEBSITE}\r\n{GOOGLEPLUS}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}";
-        $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu", $this->preferences->getMailSignature());
+        $this->preferences->pref_mail_sign = "{NAME}\r\n\r\n{WEBSITE}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}";
+        $this->assertSame(
+            "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu",
+            $this->preferences->getMailSignature($mail)
+        );
 
         $social = new \Galette\Entity\Social($this->zdb);
         $this->assertTrue(
@@ -586,7 +594,10 @@ class Preferences extends TestCase
         );
 
         $this->preferences->pref_mail_sign = "{ASSO_NAME}\r\n\r\n{ASSO_WEBSITE} - {ASSO_SOCIAL_MASTODON}";
-        $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette", $this->preferences->getMailSignature());
+        $this->assertSame(
+            "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette",
+            $this->preferences->getMailSignature($mail)
+        );
 
         $social = new \Galette\Entity\Social($this->zdb);
         $this->assertTrue(
@@ -600,7 +611,10 @@ class Preferences extends TestCase
             2,
             \Galette\Entity\Social::getListForMember(null, \Galette\Entity\Social::MASTODON)
         );
-        $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette, Galette mastodon URL - the return", $this->preferences->getMailSignature());
+        $this->assertSame(
+            "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette, Galette mastodon URL - the return",
+            $this->preferences->getMailSignature($mail)
+        );
     }
 
     /**
@@ -612,8 +626,8 @@ class Preferences extends TestCase
     {
         $legend = $this->preferences->getLegend();
         $this->assertCount(2, $legend);
-        $this->assertCount(8, $legend['main']['patterns']);
-        $this->assertCount(9, $legend['socials']['patterns']);
+        $this->assertCount(9, $legend['main']['patterns']);
+        $this->assertCount(10, $legend['socials']['patterns']);
         $this->assertSame(
             [
             'title' => __('Mastodon'),
@@ -633,7 +647,7 @@ class Preferences extends TestCase
 
         $legend = $this->preferences->getLegend();
         $this->assertCount(2, $legend);
-        $this->assertCount(10, $legend['socials']['patterns']);
+        $this->assertCount(11, $legend['socials']['patterns']);
         $this->assertTrue(isset($legend['socials']['patterns']['asso_social_mynewtype']));
         $this->assertSame(
             [
@@ -643,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());
+    }
 }