]> git.agnieray.net Git - galette.git/commitdiff
Add tests on parents feature
authorJohan Cwiklinski <johan@x-tnd.be>
Sun, 21 Jun 2020 07:18:36 +0000 (09:18 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 22 Jun 2020 15:39:56 +0000 (17:39 +0200)
tests/Galette/Entity/tests/units/Adherent.php

index 0c4e5493630a5763ba6c41d57240ced721aab598..7f491ace54d77c2324a6cb55099389e7435041b7 100644 (file)
@@ -164,11 +164,11 @@ class Adherent extends atoum
     }
 
     /**
-     * Create test user in database
+     * Get Faker data for one member
      *
-     * @return void
+     * @return array
      */
-    private function createAdherent()
+    private function dataAdherent(): array
     {
         $fakedata = new \Galette\Util\FakeData($this->zdb, $this->i18n);
         $fakedata
@@ -181,7 +181,17 @@ class Adherent extends atoum
             );
 
         $data = $fakedata->fakeMember();
-        $this->createMember($data);
+        return $data;
+    }
+
+    /**
+     * Create test user in database
+     *
+     * @return void
+     */
+    private function createAdherent()
+    {
+        $this->createMember($this->dataAdherent());
     }
 
     /**
@@ -194,6 +204,11 @@ class Adherent extends atoum
     private function loadAdherent($id)
     {
         $this->adh = new \Galette\Entity\Adherent($this->zdb, (int)$id);
+        $this->adh->setDependencies(
+            $this->preferences,
+            $this->members_fields,
+            $this->history
+        );
     }
 
     /**
@@ -262,6 +277,7 @@ class Adherent extends atoum
         $this->boolean($store)->isTrue();
 
         $this->ids[] = $adh->id;
+        return $adh;
     }
 
     /**
@@ -656,4 +672,43 @@ class Adherent extends atoum
         $this->variable($adh->birthdate)->isNull();
         $this->variable($adh->surname)->isNull();
     }
+
+    /**
+     * Test parents
+     *
+     * @return void
+     */
+    public function testParents()
+    {
+        $rs = $this->adhExists();
+        if ($rs === false) {
+            $this->createAdherent();
+        } else {
+            $this->loadAdherent($rs->current()->id_adh);
+        }
+        $this->checkMemberExpected();
+
+        //load member from db
+        $parent = new \Galette\Entity\Adherent($this->zdb, $this->adh->id);
+        $this->checkMemberExpected($parent);
+
+        $child_data = $this->dataAdherent() + [
+            'nom_adh'       => 'Doe',
+            'prenom_adh'    => 'Johny',
+            'parent_id'     => $parent->id,
+        ];
+        $child = $this->createMember($child_data);
+
+        $this->string($child->name)->isIdenticalTo($child_data['nom_adh']);
+        $this->object($child->parent)->isInstanceOf('\Galette\Entity\Adherent');
+        $this->integer($child->parent->id)->isIdenticalTo($parent->id);
+
+        $check = $child->check(['detach_parent' => true], [], []);
+        if (is_array($check)) {
+            var_dump($check);
+        }
+        $this->boolean($check)->isTrue();
+        $this->boolean($child->store())->isTrue();
+        $this->variable($child->parent)->isNull();
+    }
 }