]> git.agnieray.net Git - galette.git/commitdiff
Factorize
authorJohan Cwiklinski <johan@x-tnd.be>
Sun, 17 Oct 2021 05:38:48 +0000 (07:38 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 17 Oct 2021 05:38:48 +0000 (07:38 +0200)
galette/lib/Galette/Core/Password.php
tests/Galette/Core/tests/units/History.php
tests/Galette/Core/tests/units/Links.php
tests/Galette/Core/tests/units/Password.php
tests/Galette/Entity/tests/units/Adherent.php
tests/Galette/Entity/tests/units/Contribution.php
tests/Galette/Entity/tests/units/Transaction.php
tests/GaletteTestCase.php

index 6fc4ea5b72d7c654d01c82b7c58aa123cc44b44d..1832e37bdd5ae024c9bbd4424d56c5d022408d5c 100644 (file)
@@ -255,7 +255,7 @@ class Password extends AbstractPassword
             }
         } catch (Throwable $e) {
             Analog::log(
-                'An error ocured attempting to delete used hash' .
+                'An error occurred attempting to delete used hash' .
                 $e->getMessage(),
                 Analog::WARNING
             );
index e275802f493243be8cd78b3c380540f9ea606260..497aebb36eab7d211e3ac4c5c5b4b06ff53bfec0 100644 (file)
@@ -72,7 +72,7 @@ class History extends GaletteTestCase
     public function testHistoryFlow()
     {
         $this->i18n->changeLanguage('en_US');
-        //nothing in the logs at the begining
+        //nothing in the logs at the beginning
         $list = $this->history->getHistory();
         $this->array($list)->hasSize(0);
 
@@ -123,10 +123,7 @@ class History extends GaletteTestCase
         $list = $this->history->getHistory();
         $this->array($list)->hasSize(1);
 
-        $this->zdb->db->query(
-            'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
-            \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
-        );
+        $this->cleanHistory();
     }
 
     /**
index b75e23dfdf1c11899c3786ad4e15b2a857168015..1b8202b160cb22544e35c538fd4e985415cb660d 100644 (file)
@@ -7,7 +7,7 @@
  *
  * PHP version 5
  *
- * Copyright © 2020 The Galette Team
+ * Copyright © 2020-2021 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 2020 The Galette Team
+ * @copyright 2020-2021 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     2020-03-15
@@ -45,7 +45,7 @@ use Galette\GaletteTestCase;
  * @name      Password
  * @package   GaletteTests
  * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2020 The Galette Team
+ * @copyright 2020-2021 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     2020-03-15
@@ -100,6 +100,8 @@ class Links extends GaletteTestCase
 
         $delete = $this->zdb->delete(\Galette\Core\Links::TABLE);
         $this->zdb->execute($delete);
+
+        $this->cleanHistory();
     }
 
     /**
index 2ffb7db11573ab546bb82ee36bb57bd0a0ae7836..2f9e605c382c5cfe7aa8979f59d3c88a8bdba07e 100644 (file)
@@ -255,7 +255,7 @@ class Password extends atoum
             throw new \LogicException('Error executing query!', 123);
         };
 
-        $pass = new \Galette\Core\Password($this->zdb);
+        $pass = new \Galette\Core\Password($this->zdb, true);
     }
 
     /**
index 37637f5d96e248b3a25c885ebe4ca9ef9fb323b7..58fb837712d11498ee7e4c0815bc87d279d84821 100644 (file)
@@ -73,6 +73,8 @@ class Adherent extends GaletteTestCase
         $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
         $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
         $this->zdb->execute($delete);
+
+        $this->cleanHistory();
     }
 
     /**
@@ -482,9 +484,7 @@ class Adherent extends GaletteTestCase
         $parent = new \Galette\Entity\Adherent($this->zdb, $this->adh->id);
         $this->checkMemberOneExpected($parent);
 
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $child_data = [
             'nom_adh'       => 'Doe',
@@ -543,9 +543,7 @@ class Adherent extends GaletteTestCase
         $this->boolean($member->canEdit($this->login))->isFalse();
 
         //Superadmin can fully change members
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $this->boolean($member->canShow($this->login))->isTrue();
         $this->boolean($member->canCreate($this->login))->isTrue();
@@ -587,9 +585,7 @@ class Adherent extends GaletteTestCase
         $mdata = $this->dataAdherentOne();
         global $login;
         $login = $this->login;
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $child_data = [
                 'nom_adh'       => 'Doe',
index b2b80fd8515255c8c45b5360345d54d0ebc292c9..2fcf0ebbdc43fd7b3678c79ab82e88f72e9a5ba3 100644 (file)
@@ -77,6 +77,8 @@ class Contribution extends GaletteTestCase
         $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
         $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
         $this->zdb->execute($delete);
+
+        $this->cleanHistory();
     }
 
     /**
@@ -502,9 +504,7 @@ class Contribution extends GaletteTestCase
         $this->boolean($contrib->canShow($this->login))->isFalse();
 
         //Superadmin can fully change contributions
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $this->boolean($contrib->canShow($this->login))->isTrue();
 
@@ -541,9 +541,7 @@ class Contribution extends GaletteTestCase
         $mdata = $this->dataAdherentOne();
         global $login;
         $login = $this->login;
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $child_data = [
             'nom_adh'       => 'Doe',
index 4aa84e9725b3fabf4cbdebcc4d97a5e2ab584fcc..91c04728f6293a8c9a7ffc6e8fdecb55ab265948 100644 (file)
@@ -87,6 +87,8 @@ class Transaction extends GaletteTestCase
         $delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
         $delete->where(['fingerprint' => 'FAKER' . $this->seed]);
         $this->zdb->execute($delete);
+
+        $this->cleanHistory();
     }
 
     /**
@@ -271,9 +273,7 @@ class Transaction extends GaletteTestCase
      */
     public function testRemove()
     {
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $this->getMemberOne();
         $this->createTransaction();
@@ -295,16 +295,14 @@ class Transaction extends GaletteTestCase
     public function testCan()
     {
         $this->getMemberOne();
-        //create contribution for member
+        //create transaction for member
         $this->createTransaction();
         $transaction = $this->transaction;
 
         $this->boolean($transaction->canShow($this->login))->isFalse();
 
         //Superadmin can fully change contributions
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $this->boolean($transaction->canShow($this->login))->isTrue();
 
@@ -341,9 +339,7 @@ class Transaction extends GaletteTestCase
         $mdata = $this->dataAdherentOne();
         global $login;
         $login = $this->login;
-        $this->login->logAdmin('superadmin', $this->preferences);
-        $this->boolean($this->login->isLogged())->isTrue();
-        $this->boolean($this->login->isSuperAdmin())->isTrue();
+        $this->logSuperAdmin();
 
         $child_data = [
             'nom_adh'       => 'Doe',
index 4378493019ea8be04b3bfa77eadd029f954601c2..141d56cad4534bcc4f3ba1a45816b19fb87e6043 100644 (file)
@@ -709,4 +709,29 @@ abstract class GaletteTestCase extends atoum
             $this->boolean($res)->isTrue();
         }
     }
+
+    /**
+     * Clean history
+     *
+     * @return void
+     */
+    protected function cleanHistory(): void
+    {
+        $this->zdb->db->query(
+            'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
+            \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
+        );
+    }
+
+    /**
+     * Log-in as super administrator
+     *
+     * @return void
+     */
+    protected function logSuperAdmin(): void
+    {
+        $this->login->logAdmin('superadmin', $this->preferences);
+        $this->boolean($this->login->isLogged())->isTrue();
+        $this->boolean($this->login->isSuperAdmin())->isTrue();
+    }
 }