]> git.agnieray.net Git - galette.git/blobdiff - tests/GaletteTestCase.php
Add unit tests
[galette.git] / tests / GaletteTestCase.php
index 31da38260027d409bb0127581140c17294de9f04..17d2396c5c7549b77e3b24cdd09116d4e7e10650 100644 (file)
@@ -247,17 +247,23 @@ abstract class GaletteTestCase extends atoum
      */
     public function createMember(array $data)
     {
-        $adh = $this->adh;
-        $check = $adh->check($data, [], []);
+        $this->adh = new \Galette\Entity\Adherent($this->zdb);
+        $this->adh->setDependencies(
+            $this->preferences,
+            $this->members_fields,
+            $this->history
+        );
+
+        $check = $this->adh->check($data, [], []);
         if (is_array($check)) {
             var_dump($check);
         }
         $this->boolean($check)->isTrue();
 
-        $store = $adh->store();
+        $store = $this->adh->store();
         $this->boolean($store)->isTrue();
 
-        return $adh;
+        return $this->adh;
     }
 
     /**
@@ -479,8 +485,38 @@ abstract class GaletteTestCase extends atoum
      */
     protected function adhOneExists()
     {
+        $mdata = $this->dataAdherentOne();
         $select = $this->zdb->select(\Galette\Entity\Adherent::TABLE, 'a');
-        $select->where(array('a.fingerprint' => 'FAKER' . $this->seed));
+        $select->where(
+            array(
+                'a.fingerprint' => 'FAKER' . $this->seed,
+                'a.login_adh' => $mdata['login_adh']
+            )
+        );
+
+        $results = $this->zdb->execute($select);
+        if ($results->count() === 0) {
+            return false;
+        } else {
+            return $results;
+        }
+    }
+
+    /**
+     * Look in database if test member already exists
+     *
+     * @return false|ResultSet
+     */
+    protected function adhTwoExists()
+    {
+        $mdata = $this->dataAdherentTwo();
+        $select = $this->zdb->select(\Galette\Entity\Adherent::TABLE, 'a');
+        $select->where(
+            array(
+                'a.fingerprint' => 'FAKER' . $this->seed,
+                'a.login_adh' => $mdata['login_adh']
+            )
+        );
 
         $results = $this->zdb->execute($select);
         if ($results->count() === 0) {
@@ -512,7 +548,7 @@ abstract class GaletteTestCase extends atoum
      */
     protected function getMemberTwo()
     {
-        $rs = $this->adhOneExists();
+        $rs = $this->adhTwoExists();
         if ($rs === false) {
             $this->createMember($this->dataAdherentTwo());
         } else {