From 729a8017c32419ddb177216f8999c7160123af37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Fri, 11 Jan 2013 17:13:37 +0100 Subject: [PATCH 1/2] Added test for Adherent class functions setUserId and setThirdPartyId --- test/phpunit/AdherentTest.php | 103 ++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 5 deletions(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index e6ed5ebdddb..1a613fe4845 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -139,7 +139,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase /** * testAdherentFetch * - * @param int $id Id of object to fecth + * @param int $id Id of object to fetch * @return object Fetched object * * @depends testAdherentCreate @@ -225,6 +225,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertEquals($localobject->town, $newobject->town); $this->assertEquals($localobject->country_id, $newobject->country_id); $this->assertEquals('BE', $newobject->country_code); + $this->assertEquals('Belgium', $newobject->country); $this->assertEquals($localobject->statut, $newobject->statut); $this->assertEquals($localobject->phone, $newobject->phone); $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); @@ -233,7 +234,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertEquals($localobject->naiss, $timestamp); $this->assertEquals($localobject->morphy, $newobject->morphy); - return $localobject; + //We return newobject because of new values + return $newobject; } /** @@ -258,8 +260,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase '%NOM%,%SOCIETE%,%ADRESSE%,%CP%,%VILLE%,%PAYS%'; $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',0,New firstname,New name,New firstname New name,'. - 'New company,New address,New zip,New town,,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. - 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,'; + 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. + 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; $result = $localobject->makeSubstitution($template); print __METHOD__." result=".$result."\n"; @@ -268,13 +270,104 @@ class AdherentTest extends PHPUnit_Framework_TestCase return $localobject; } + /** + * testAdherentSetUserId + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentMakeSubstitution + * The depends says test is run only if previous is ok + */ + public function testAdherentSetUserId(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //We associate member with user + $result = $localobject->setUserId($user->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); + + //We update user object + $user->fetch($user->id); + print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; + + $this->assertEquals($user->fk_member, $localobject->id); + + //We remove association with user + $result = $localobject->setUserId(0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); + + //We update user object + $user->fetch($user->id); + print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; + + $this->assertNull($user->fk_member); + + return $localobject; + } + + /** + * testAdherentSetThirdPartyId + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentSetUserId + * The depends says test is run only if previous is ok + */ + public function testAdherentSetThirdPartyId(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //Create a Third Party + $thirdparty = new Societe($db); + $thirdparty->initAsSpecimen(); + $result = $thirdparty->create($user); + print __METHOD__." id=".$localobject->id." third party id=".$thirdparty->id." result=".$result."\n"; + $this->assertTrue($result > 0); + + //Set Third Party ID + $result = $localobject->setThirdPartyId($thirdparty->id); + $this->assertEquals($result, 1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + + //Adherent is updated with new data + $localobject->fetch($localobject->id); + $this->assertEquals($localobject->fk_soc, $thirdparty->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + + //We remove the third party association + $result = $localobject->setThirdPartyId(0); + $this->assertEquals($result, 1); + + //And check if it has been updated + $localobject->fetch($localobject->id); + $this->assertNull($localobject->fk_soc); + + //Now we remove the third party + $result = $thirdparty->delete($thirdparty->id); + $this->assertEquals($result, 1); + + return $localobject; + } + /** * testAdherentValid * * @param Adherent $localobject Member instance * @return Adherent * - * @depends testAdherentMakeSubstitution + * @depends testAdherentSetThirdPartyId * The depends says test is run only if previous is ok */ public function testAdherentValid(Adherent $localobject) From aff96e50503a00f081f72a670333f8313d042629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Sat, 12 Jan 2013 14:14:36 +0100 Subject: [PATCH 2/2] Added test for functions fetch_login and resiliate --- test/phpunit/AdherentTest.php | 84 ++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 1a613fe4845..493783ae2eb 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -161,13 +161,38 @@ class AdherentTest extends PHPUnit_Framework_TestCase return $localobject; } + /** + * testAdherentFetchLogin + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentFetch + * The depends says test is run only if previous is ok + */ + public function testAdherentFetchLogin(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $newobject = new Adherent($this->savdb); + $result = $newobject->fetch_login($localobject->login); + + $this->assertEquals($newobject, $localobject); + + return $localobject; + } + /** * testAdherentUpdate * * @param Adherent $localobject Member instance * @return Adherent * - * @depends testAdherentFetch + * @depends testAdherentFetchLogin * The depends says test is run only if previous is ok */ public function testAdherentUpdate(Adherent $localobject) @@ -259,7 +284,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase '%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%,%EMAIL%,%NAISS%,%PHOTO%,%LOGIN%,%PASSWORD%,%PRENOM%,'. '%NOM%,%SOCIETE%,%ADRESSE%,%CP%,%VILLE%,%PAYS%'; - $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',0,New firstname,New name,New firstname New name,'. + $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',,New firstname,New name,New firstname New name,'. 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; @@ -370,7 +395,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase * @depends testAdherentSetThirdPartyId * The depends says test is run only if previous is ok */ - public function testAdherentValid(Adherent $localobject) + public function testAdherentValidate(Adherent $localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -391,7 +416,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase * @param Adherent $localobject Member instance * @return int Id of object * - * @depends testAdherentValid + * @depends testAdherentValidate * The depends says test is run only if previous is ok */ public function testAdherentOther(Adherent $localobject) @@ -411,19 +436,56 @@ class AdherentTest extends PHPUnit_Framework_TestCase print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; + return $localobject; + } + + /** + * testAdherentResiliate + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentOther + * The depends says test is run only if previous is ok + */ + public function testAdherentResiliate(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + //Let's resilie un adherent + $result = $localobject->resiliate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); + + //Is statut updated? + $this->assertEquals($localobject->statut, 0); + + //We update the object and let's check if it was updated on DB + $localobject->fetch($localobject->id); + $this->assertEquals($localobject->statut, 0); + + //Now that status=0, resiliate should return 0 + $result = $localobject->resiliate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 0); + + return $localobject; } /** * testAdherentDelete * - * @param int $id Id of object to delete + * @param Adherent $localobject Member instance * @return void * - * @depends testAdherentOther + * @depends testAdherentResiliate * The depends says test is run only if previous is ok */ - public function testAdherentDelete($id) + public function testAdherentDelete($localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -431,10 +493,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $localobject=new Adherent($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($id); - print __METHOD__." id=".$id." result=".$result."\n"; + $result=$localobject->delete($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result;