From 1ac3d5146fe71bb0ed0bbbc73da3f3c7eb8c02cd Mon Sep 17 00:00:00 2001 From: gloas <gloas@git-test.afi-sa.fr> Date: Tue, 20 Aug 2013 13:54:10 +0000 Subject: [PATCH] ajout des tests + refacto class abonne cosmogramme avant rel #9357 --- .gitattributes | 2 + .../php/classes/AbonneIntegrationTest.php | 110 ++++++++++++++++++ cosmogramme/tests/php/classes/AbonneTest.php | 0 3 files changed, 112 insertions(+) create mode 100644 cosmogramme/tests/php/classes/AbonneIntegrationTest.php create mode 100644 cosmogramme/tests/php/classes/AbonneTest.php diff --git a/.gitattributes b/.gitattributes index f6774195713..83f3658b6b4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2170,6 +2170,8 @@ cosmogramme/sql/patch/patch_168.sql -text cosmogramme/sql/patch/patch_169.sql -text cosmogramme/storm_init.php -text cosmogramme/tests/bootstrap.php -text +cosmogramme/tests/php/classes/AbonneIntegrationTest.php -text +cosmogramme/tests/php/classes/AbonneTest.php -text cosmogramme/tests/php/classes/IndexationTest.php -text cosmogramme/tests/php/classes/Iso2709RecordTest.php -text cosmogramme/tests/php/classes/ModelTestCase.php -text diff --git a/cosmogramme/tests/php/classes/AbonneIntegrationTest.php b/cosmogramme/tests/php/classes/AbonneIntegrationTest.php new file mode 100644 index 00000000000..512eabb6290 --- /dev/null +++ b/cosmogramme/tests/php/classes/AbonneIntegrationTest.php @@ -0,0 +1,110 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +require_once 'classe_abonne.php'; +require_once 'ModelTestCase.php'; + + + +abstract class AbonneIntegrationTestCase extends ModelTestCase { + protected $abon_config; + protected $user_tom; + + public function setup(){ + parent::setup(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('save') + ->answers(true); + + $this->abon_config = new abonne(); + $this->abon_config->setIdBib(2); + $this->abon_config->setChamps(['IDABON','ID_SIGB','ORDREABON','NOM','PRENOM','PASSWORD','MAIL']); + + } +} + + + + +class AbonneIntegrationWithNoUsersInDbTest extends AbonneIntegrationTestCase { + + public function setup(){ + parent::setup(); + $champs_sigb = ['1234','12','2','Tom','paul','ici','tp@afi-sa.fr']; + $champs_sigb_ascii = implode(chr(9), $champs_sigb); + $this->abon_config->importFicheAscii($champs_sigb_ascii); + $this->user_tom = Class_Users::getFirstAttributeForLastCallOn('save'); + + } + + /** @test **/ + public function abonneSigbTomIdShouldBe1234() { + $this->assertEquals('1234', $this->user_tom->getIdabon()); + } + +} + + + + +class AbonneIntegrationWithRoutoInDbTest extends AbonneIntegrationTestCase { + + protected $user_routo; + protected $routo_after_import; + + public function setup(){ + parent::setup(); + $this->user_routo = Class_Users::newInstanceWithId(5,['nom'=>'Routo', + 'prenom'=>'Pierre', + 'login'=>'routop', + 'password'=>'old']); + + Class_Users::whenCalled('findFirstBy') + ->with(['login'=>'55', + 'id_site'=>2]) + ->answers($this->user_routo); + + $champs_sigb_ascii = implode(chr(9), ['55', + '12', + '2', + 'Routo', + 'Pierre', + 'la', + 'rp@afi-sa.fr']); + + $this->abon_config->importFicheAscii($champs_sigb_ascii); + + $this->routo_after_import = Class_Users::getFirstAttributeForLastCallOn('save'); + } + + /** @test **/ + public function withRoutoInDbImportShouldUpdateRoutoWithIdabon55() { + $this->assertEquals('55',$this->routo_after_import->getIdabon()); + } + + + /** @test **/ + public function routoInDbAndRoutoAfterImportShouldBeTheSame() { + $this->assertSame($this->user_routo, $this->routo_after_import); + } + +} \ No newline at end of file diff --git a/cosmogramme/tests/php/classes/AbonneTest.php b/cosmogramme/tests/php/classes/AbonneTest.php new file mode 100644 index 00000000000..e69de29bb2d -- GitLab