diff --git a/cosmogramme/php/classes/classe_abonne.php b/cosmogramme/php/classes/classe_abonne.php index b9eadd615cecc9573a193b3a5a6777e6dd51c57b..548e3be29b64c1945f0b15f9fbc02846f5e06c31 100644 --- a/cosmogramme/php/classes/classe_abonne.php +++ b/cosmogramme/php/classes/classe_abonne.php @@ -69,7 +69,6 @@ class abonne // ---------------------------------------------------------------- public function importFicheAscii($data) { - xdebug_break(); // Transco accents $data=$this->changeAccents($data); @@ -89,8 +88,7 @@ class abonne $enreg["IDABON"]=$enreg["NUM_CARTE"]; unset($enreg["NUM_CARTE"]); } - if((int)$enreg["ORDREABON"] <1 ) - $enreg["ORDREABON"]=1; + if(isset($enreg["NAISSANCE"]) && (strlen($enreg["NAISSANCE"]) == 10)) $enreg["NAISSANCE"]=rendDate($enreg["NAISSANCE"], 0); @@ -105,6 +103,7 @@ class abonne // Import d'une fiche en XML // ---------------------------------------------------------------- public function importFicheXml($data){ + xdebug_break(); // Transco accents $data=$this->changeAccents($data); @@ -118,19 +117,8 @@ class abonne } } - $enreg = $this->prepateData($enreg); - - // formattage des dates - $enreg["NAISSANCE"]=rendDate($enreg["NAISSANCE"], 0); - - // valeurs par défaut - if(!$enreg["ORDREABON"]) - $enreg["ORDREABON"]=1; - - // Ecrire - - - $this->saveOrUpdateInDB($id_user,$enreg); + $enreg = $this->prepareData($enreg); + $this->saveOrUpdateInDB($enreg); } @@ -142,6 +130,10 @@ class abonne $enreg["ROLE"]="abonne_sigb"; $enreg["ROLE_LEVEL"]=2; $enreg["STATUT"]=0; + + if(isset($enreg["ORDREABON"]) && ((int)$enreg["ORDREABON"] <1 )) + $enreg["ORDREABON"]=1; + return $enreg; } diff --git a/cosmogramme/tests/bootstrap.php b/cosmogramme/tests/bootstrap.php index ea78502a27d1461c70e4dd932ee092d179a80a7d..5b41b3a497b86fe779d606624e64e2b549d14aaf 100644 --- a/cosmogramme/tests/bootstrap.php +++ b/cosmogramme/tests/bootstrap.php @@ -1,7 +1,7 @@ <?php //error_reporting(E_ALL^E_DEPRECATED ^E_WARNING); -xberror_reporting(E_ERROR | E_PARSE | E_COMPILE_ERROR); +error_reporting(E_ERROR | E_PARSE | E_COMPILE_ERROR); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); diff --git a/cosmogramme/tests/php/classes/AbonneIntegrationTest.php b/cosmogramme/tests/php/classes/AbonneIntegrationTest.php index 512eabb6290c1731f4550011bf9b3274eabd4b76..dd318ac7259685da804fa6baa0f156f910d3f3a1 100644 --- a/cosmogramme/tests/php/classes/AbonneIntegrationTest.php +++ b/cosmogramme/tests/php/classes/AbonneIntegrationTest.php @@ -37,15 +37,45 @@ abstract class AbonneIntegrationTestCase extends ModelTestCase { $this->abon_config = new abonne(); $this->abon_config->setIdBib(2); - $this->abon_config->setChamps(['IDABON','ID_SIGB','ORDREABON','NOM','PRENOM','PASSWORD','MAIL']); + } +} + + + +abstract class AbonneIntegrationASCIITestCase extends AbonneIntegrationTestCase { + public function setup(){ + parent::setup(); + $this->abon_config->setChamps(['IDABON', + 'ID_SIGB', + 'ORDREABON', + 'NOM', + 'PRENOM', + 'PASSWORD', + 'MAIL']); + } +} + + + + +abstract class AbonneIntegrationXMLTestCase extends AbonneIntegrationTestCase { + public function setup(){ + parent::setup(); + $this->abon_config->setChamps(['IDABON'=>'LECTNUM', + 'ID_SIGB'=>'LECTNUM', + 'NOM' => 'LASTNAME', + 'PRENOM' => 'FIRSTNAME', + 'PASSWORD'=> 'MOT_DE_PASSE', + 'MAIL'=> 'EMAIL', + 'NAISSANCE'=>'DATEBIRTH']); } } -class AbonneIntegrationWithNoUsersInDbTest extends AbonneIntegrationTestCase { +class AbonneIntegrationASCIIWithNoUsersInDbTest extends AbonneIntegrationASCIITestCase { public function setup(){ parent::setup(); @@ -66,7 +96,7 @@ class AbonneIntegrationWithNoUsersInDbTest extends AbonneIntegrationTestCase { -class AbonneIntegrationWithRoutoInDbTest extends AbonneIntegrationTestCase { +class AbonneIntegrationASCIIWithRoutoInDbTest extends AbonneIntegrationASCIITestCase { protected $user_routo; protected $routo_after_import; @@ -107,4 +137,66 @@ class AbonneIntegrationWithRoutoInDbTest extends AbonneIntegrationTestCase { $this->assertSame($this->user_routo, $this->routo_after_import); } -} \ No newline at end of file +} + + + + +class AbonneIntegrationXMLWithNoUsersInDbTest extends AbonneIntegrationXMLTestCase { + + public function setup(){ + parent::setup(); + + $champs_sigb_xml = '<Item><TYPE_ABONNE>I</TYPE_ABONNE><LECTNUM>00003090</LECTNUM><LASTNAME>Pirly</LASTNAME><FIRSTNAME>Coco</FIRSTNAME><FULLNAME>Pirly, Coco</FULLNAME><DATEBIRTH>12/31/1982</DATEBIRTH><MOT_DE_PASSE>zoom</MOT_DE_PASSE></Item>'; + + $this->abon_config->importFicheXml($champs_sigb_xml); + $this->user_tom = Class_Users::getFirstAttributeForLastCallOn('save'); + + } + + /** @test **/ + public function abonneSigbTomIdShouldBe1234() { + $this->assertEquals('00003090', $this->user_tom->getIdabon()); + } + +} + + + + +class AbonneIntegrationXMLWithRoutoInDbTest extends AbonneIntegrationXMLTestCase { + + protected $user_zozio; + protected $zozio_after_import; + + public function setup(){ + parent::setup(); + $this->user_zozio = Class_Users::newInstanceWithId(5,['nom'=>'poirreau', + 'prenom'=>'Zozio', + 'login'=>'01003080', + 'password'=>'allez les bleus']); + + Class_Users::whenCalled('findFirstBy') + ->with(['login'=>'01003080', + 'id_site'=>2]) + ->answers($this->user_zozio); + + $champs_sigb_xml = '<Item><TYPE_ABONNE>I</TYPE_ABONNE><LECTNUM>01003080</LECTNUM><LASTNAME>poirreau</LASTNAME><FIRSTNAME>Zozio</FIRSTNAME><FULLNAME>Piou Piou</FULLNAME><DATEBIRTH>12/31/2012</DATEBIRTH><MOT_DE_PASSE>allez les bleus</MOT_DE_PASSE></Item>'; + + $this->abon_config->importFicheXml($champs_sigb_xml); + + $this->zozio_after_import = Class_Users::getFirstAttributeForLastCallOn('save'); + } + + /** @test **/ + public function withRoutoInDbImportShouldUpdateRoutoWithIdabon55() { + $this->assertEquals('01003080',$this->zozio_after_import->getIdabon()); + } + + + /** @test **/ + public function routoInDbAndRoutoAfterImportShouldBeTheSame() { + $this->assertSame($this->user_zozio, $this->zozio_after_import); + } + +}