From a550ba927d481b57a9b4fc2cb88b98346036643e Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Wed, 4 Feb 2015 12:02:18 +0100 Subject: [PATCH] hotline_#18504_pergame_exemplaire_same_id_origine_between_album_and_sigb fix test failures --- library/Class/Pret.php | 8 +- library/Class/Reservation.php | 5 +- library/Class/WebService/SIGB/Emprunteur.php | 10 +- .../Class/WebService/SIGB/Pergame/Service.php | 27 ++- library/Class/WebService/SIGB/Reservation.php | 13 +- .../View/Helper/TagFormationVodeclic.php | 7 +- scripts/emacs/phafi-mode.el | 2 +- .../Class/WebService/SIGB/PergameTest.php | 215 ++++++++---------- 8 files changed, 137 insertions(+), 150 deletions(-) diff --git a/library/Class/Pret.php b/library/Class/Pret.php index 8429c49a87c..55547cf96b4 100644 --- a/library/Class/Pret.php +++ b/library/Class/Pret.php @@ -16,12 +16,12 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Pret extends Storm_Model_Abstract { protected $_table_name = 'prets'; - protected $_table_primary = 'id_pret'; + protected $_table_primary = 'id_pret'; protected $_belongs_to = array('bib' => array('model' => 'Class_Bib', 'referenced_in' => 'id_site')); @@ -32,8 +32,8 @@ class Class_Pret extends Storm_Model_Abstract { public function getExemplaire() { - return Class_Exemplaire::getLoader()->findFirstBy(array('id_bib' => $this->getIdSite(), - 'code_barres' => $this->getCodeBarres())); + return Class_Exemplaire::findFirstBy(['id_bib' => $this->getIdSite(), + 'code_barres' => $this->getCodeBarres()]);$item; } } diff --git a/library/Class/Reservation.php b/library/Class/Reservation.php index 63a62441585..1f76954e597 100644 --- a/library/Class/Reservation.php +++ b/library/Class/Reservation.php @@ -42,8 +42,8 @@ class Class_Reservation extends Storm_Model_Abstract { public function getRang() { - return 1 + $this->getLoader()->countBy(array('ID_NOTICE_ORIGINE' => $this->getIdNoticeOrigine(), - 'where' => sprintf('DATE_RESA<"%s"', $this->getDateResa()))); + return 1 + Class_Reservation::getLoader()->countBy(['ID_NOTICE_ORIGINE' => $this->getIdNoticeOrigine(), + 'where' => sprintf('DATE_RESA<"%s"', $this->getDateResa())]); } @@ -55,5 +55,4 @@ class Class_Reservation extends Storm_Model_Abstract { return "Réservé"; } } - ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Emprunteur.php b/library/Class/WebService/SIGB/Emprunteur.php index 2b38b4808bc..48fe7286a04 100644 --- a/library/Class/WebService/SIGB/Emprunteur.php +++ b/library/Class/WebService/SIGB/Emprunteur.php @@ -16,11 +16,11 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_SIGB_Emprunteur { - protected + protected $_id, $_name, $_emprunts, @@ -44,7 +44,7 @@ class Class_WebService_SIGB_Emprunteur { $_date_naissance, $_is_contact_email= 0, $_is_contact_sms= 0; - + public function __sleep() { $this->getEmprunts(); @@ -551,7 +551,7 @@ class Class_WebService_SIGB_Emprunteur { public function getEndDate() { return $this->_end_date; } - + /** * @param Class_WebService_SIGB_AbstractService $service @@ -615,7 +615,7 @@ class Class_WebService_SIGB_Emprunteur { return $this; } - + /** * @return boolean */ diff --git a/library/Class/WebService/SIGB/Pergame/Service.php b/library/Class/WebService/SIGB/Pergame/Service.php index 14053507de7..40fadf007a9 100644 --- a/library/Class/WebService/SIGB/Pergame/Service.php +++ b/library/Class/WebService/SIGB/Pergame/Service.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_AbstractService { @@ -63,16 +63,15 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra } - public function getEmpruntsOf($emprunteur) - { - $params = Class_IntBib::getLoader()->find($this->_id_bib)->getCommParamsAsArray(); + public function getEmpruntsOf($emprunteur) { + $params = Class_IntBib::find($this->_id_bib)->getCommParamsAsArray(); $renouvelable = isset($params['Autoriser_prolongations']) ? $params['Autoriser_prolongations'] : false; - - $user = Class_Users::getLoader()->find($emprunteur->getId()); - $prets = Class_Pret::getLoader()->findAllBy(array('IDABON' => $user->getIdabon(), - 'ORDREABON' => $user->getOrdreabon(), - 'EN_COURS' => 1)); - $emprunts = array(); + + $user = Class_Users::find($emprunteur->getId()); + $prets = Class_Pret::findAllBy(['IDABON' => $user->getIdabon(), + 'ORDREABON' => $user->getOrdreabon(), + 'EN_COURS' => 1]); + $emprunts = []; foreach($prets as $pret) { $emprunts []= Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() @@ -90,7 +89,7 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra $user = Class_Users::find($emprunteur->getId()); $reservations_db = Class_Reservation::findAllBy(['IDABON' => $user->getIdabon(), 'ORDREABON' => $user->getOrdreabon()]); - $reservations = array(); + $reservations = []; foreach($reservations_db as $reservation) { $bib = Class_Bib::find($reservation->getIdSite()); @@ -107,8 +106,8 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra public function reserverExemplaire($user, $exemplaire, $code_annexe) { - return $this->getLegacyService()->reserverExemplairePergame($this->_id_bib, - $exemplaire, + return $this->getLegacyService()->reserverExemplairePergame($this->_id_bib, + $exemplaire, $code_annexe); } @@ -122,7 +121,7 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra return $this->getLegacyService()->prolongerPret($pret_id); } - + public function getNotice($id){ if (!$exemplaire = Class_Exemplaire::getLoader()->findFirstBy(array('id_origine' => $id, 'id_bib' => $this->_id_bib))) diff --git a/library/Class/WebService/SIGB/Reservation.php b/library/Class/WebService/SIGB/Reservation.php index ff8d5be1901..8626b0d7884 100644 --- a/library/Class/WebService/SIGB/Reservation.php +++ b/library/Class/WebService/SIGB/Reservation.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_SIGB_Reservation extends Class_WebService_SIGB_ExemplaireOperation { @@ -24,6 +24,7 @@ class Class_WebService_SIGB_Reservation extends Class_WebService_SIGB_Exemplaire protected $etat; protected $pickup_location_label; + public function getRang() { if (!isset($this->rang)) $this->rang=1; return $this->rang; @@ -32,7 +33,7 @@ class Class_WebService_SIGB_Reservation extends Class_WebService_SIGB_Exemplaire public function setRang($rang) { $this->rang = (int)$rang; - if ($this->rang == 0) + if ($this->rang == 0) $this->rang = 1; return $this; } @@ -48,14 +49,17 @@ class Class_WebService_SIGB_Reservation extends Class_WebService_SIGB_Exemplaire return $this->etat; } + public function setPickupLocationLabel($pickup_location_label) { $this->pickup_location_label = $pickup_location_label; } + public function getPickupLocationLabel() { return $this->pickup_location_label; } + public function onParseAttributes() { $this->setRang($this->getAttribute('Rang')); $this->setEtat($this->getAttribute('Etat')); @@ -66,12 +70,11 @@ class Class_WebService_SIGB_Reservation extends Class_WebService_SIGB_Exemplaire if ($annexe = Class_CodifAnnexe::getLoader()->findFirstBy(array('code' => $code_annexe))) $this->setBibliotheque($annexe->getLibelle()); } - + /** @codeCoverageIgnore */ public function __toString(){ return parent::__toString().", Rang:".$this->getRang(); } } - -?> \ No newline at end of file +?> diff --git a/library/ZendAfi/View/Helper/TagFormationVodeclic.php b/library/ZendAfi/View/Helper/TagFormationVodeclic.php index d75f49994b9..ccc890efcba 100644 --- a/library/ZendAfi/View/Helper/TagFormationVodeclic.php +++ b/library/ZendAfi/View/Helper/TagFormationVodeclic.php @@ -16,14 +16,13 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_TagFormationVodeclic extends ZendAfi_View_Helper_TagRessourceNumerique { use Trait_Translator; - + public function tagFormationVodeclic($album) { - xdebug_break(); $current_user = Class_Users::getIdentity(); if (!$this->canAccessRessourceNumerique()) return '<p>'.$this->_('Vous devez être connecté sous un compte avec abonnement valide pour pouvoir accéder à la formation').'</p>'; @@ -47,7 +46,7 @@ class ZendAfi_View_Helper_TagFormationVodeclic extends ZendAfi_View_Helper_TagRe "img_patience.hide();". "},5000);". "})"); - + return '<button class="vodeclic_link">Accéder à la formation</button>'. '<img style="display:none" src="'.URL_ADMIN_IMG.'patience.gif">'; } diff --git a/scripts/emacs/phafi-mode.el b/scripts/emacs/phafi-mode.el index c54f4c6cf25..3d0b35b7ff8 100644 --- a/scripts/emacs/phafi-mode.el +++ b/scripts/emacs/phafi-mode.el @@ -93,7 +93,7 @@ (setq ac-sources '(ac-source-gtags ac-source-words-in-buffer ac-source-php-auto-yasnippets)) (imenu-add-menubar-index) (phafi-init-menu) - (phafi-enable-autotest) +;;(phafi-enable-autotest) (setq magit-diff-options '("-w") flymake-mode t diff --git a/tests/library/Class/WebService/SIGB/PergameTest.php b/tests/library/Class/WebService/SIGB/PergameTest.php index 4f217a8d1e5..a8999ac69be 100644 --- a/tests/library/Class/WebService/SIGB/PergameTest.php +++ b/tests/library/Class/WebService/SIGB/PergameTest.php @@ -16,131 +16,117 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ abstract class PergameServiceTestCase extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - $this->notice_potter = Class_Notice::getLoader() - ->newInstanceWithId(1) - ->setTitrePrincipal('Harry Potter') - ->setAuteurPrincipal('JK Rowling'); - - $this->potter_annecy = Class_Exemplaire::getLoader() - ->newInstanceWithId(23) - ->setIdNotice(1) - ->setCodeBarres('A-23') - ->setIdOrigine('1HP') - ->setActivite('En rayon - Discotheque') - ->setIdBib(1); - - $this->potter_cran_prete = Class_Exemplaire::getLoader() - ->newInstanceWithId(24) - ->setIdNotice(1) - ->setCodeBarres('C-24') - ->setIdOrigine('1HP') - ->setActivite('En rayon') - ->setIdBib(2); - - $this->potter_cran_reserve = Class_Exemplaire::getLoader() - ->newInstanceWithId(25) - ->setIdNotice(1) - ->setCodeBarres('C-25') - ->setIdOrigine('1HP') - ->setActivite('En rayon') - ->setIdBib(2); - - $this->potter_cran_dispo = Class_Exemplaire::getLoader() - ->newInstanceWithId(26) - ->setIdNotice(1) - ->setCodeBarres('C-26') - ->setIdOrigine('1HP') - ->setActivite('En rayon') - ->setIdBib(2); - - - Class_IntBib::getLoader() - ->newInstanceWithId(1) - ->setCommParams(serialize(array("Autoriser_docs_disponibles" => 1))); - - Class_IntBib::getLoader() - ->newInstanceWithId(2) - ->setCommParams(serialize(array("Autoriser_docs_disponibles" => 0))); - - Class_Bib::getLoader() - ->newInstanceWithId(2) - ->setLibelle('Cran-Gevrier'); - - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire') - ->whenCalled('findFirstBy') - ->with(array('id_bib' => 2, 'code_barres' => 'C-24')) - ->answers($this->potter_cran_prete) - - ->whenCalled('findFirstBy') - ->with(array('id_origine' => '1HP')) - ->answers($this->potter_annecy); - + $this->notice_potter = $this->fixture('Class_Notice', + ['id' => 1, + 'titre_principal' => 'Harry Potter', + 'auteur_principal' => 'JK Rowling']); + + $this->potter_annecy = $this->fixture('Class_Exemplaire', + ['id' => 23, + 'id_notice' => 1, + 'code_barres' => 'A-23', + 'id_origine' => '1HP', + 'activite' => 'En rayon - Discotheque', + 'id_bib' => 1]); + + $this->potter_cran_prete = $this->fixture('Class_Exemplaire', + ['id' => 24, + 'id_notice' => 1, + 'code_barres' => 'C-24', + 'id_origine' => '1HP', + 'activite' => 'En rayon', + 'id_bib' => 2]); + + $this->potter_cran_reserve = $this->fixture('Class_Exemplaire', + ['id' => 25, + 'id_notice' => 1, + 'code_barres' => 'C-25', + 'id_origine' => '1HP', + 'activite' => 'En rayon', + 'id_bib' => 2]); + + $this->potter_cran_dispo = $this->fixture('Class_Exemplaire', + ['id' => 26, + 'id_notice' => 1, + 'code_barres' => 'C-26', + 'id_origine' => '1HP', + 'activite' => 'En rayon', + 'id_bib' => 2]); + + $this->fixture('Class_IntBib', + ['id' => 1]) + ->setCommParams(serialize(["Autoriser_docs_disponibles" => 1])) + ->save(); + + $this->fixture('Class_IntBib', + ['id' => 2]) + ->setCommParams(serialize(['Autoriser_docs_disponibles' => 0])) + ->save(); + + $this->fixture('Class_Bib', + ['id' => 2, + 'libelle' => 'Cran-Gevrier']); $this->_service_cran = Class_WebService_SIGB_Pergame_Service::getService(2); } } + class PergameServiceGetEmprunteurTest extends PergameServiceTestCase { public function setUp() { parent::setUp(); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Pret') - ->whenCalled('findAllBy') - ->with(array('IDABON' => 23, 'ORDREABON' => 2, 'EN_COURS' => 1)) - ->answers(array(Class_Pret::getLoader() - ->newInstanceWithId(59) - ->setCodeBarres('C-24') - ->setIdNoticeOrigine(1) - ->setIdPergame('1HP') - ->setEnCours(1) - ->setDateRetour('2010-09-07') - ->setIdSite(2) - ->setIdabon(23) - ->setOrdreabon(2))) - - ->whenCalled('countBy') - ->with(array('ID_NOTICE_ORIGINE' => 1, - 'EN_COURS' => 1)) - ->answers(2); + Class_Notice::beVolatile(); + + $this->fixture('Class_Pret', + ['id' => 59, + 'code_barres' => 'C-24', + 'id_notice_origine' => 1, + 'id_pergame' => '1HP', + 'en_cours' => 1, + 'date_retour' => '2010-09-07', + 'id_site' => 2, + 'idabon' => 23, + 'ordreabon' => 2]); + + $this->fixture('Class_Reservation', + ['id' => 76, + 'id_notice_origine' => '1HP', + 'id_pergame' => '1HP', + 'date_resa' => '2011-12-25', + 'id_site' => 2, + 'idabon' => 23, + 'ordreabon' => 2]); + + $this->fixture('Class_Reservation', + ['id' => 77, + 'id_notice_origine' => '3HP', + 'id_pergame' => '3HP', + 'date_resa' => '2011-12-25', + 'id_site' => 0, + 'idabon' => 23, + 'ordreabon' => 2]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Reservation') - ->whenCalled('findAllBy') - ->with(['IDABON' => 23, 'ORDREABON' => 2]) - ->answers([ - Class_Reservation::newInstanceWithId(76, - ['id_notice_origine' => '1HP', - 'id_pergame' => '1HP', - 'date_resa' => '2011-12-25', - 'id_site' => 2, - 'idabon' => 23, - 'ordreabon' => 2]), - - Class_Reservation::newInstanceWithId(77, - ['id_notice_origine' => '3HP', - 'id_pergame' => '3HP', - 'date_resa' => '2011-12-25', - 'id_site' => 0, - 'idabon' => 23, - 'ordreabon' => 2]), - ]) ->whenCalled('countBy') - ->with(['ID_NOTICE_ORIGINE' => 1, + ->with(['ID_NOTICE_ORIGINE' => 1, 'where' => sprintf('DATE_RESA<"%s"', '2011-12-25')]) ->answers(2); - $jc = Class_Users::newInstanceWithId(23, - ['login' => 'jc', - 'idabon' => 23, - 'ordreabon' => 2]); + $jc = $this->fixture('Class_Users', + ['id' => 23, + 'login' => 'jc', + 'password' => 'jc', + 'idabon' => 23, + 'ordreabon' => 2]); $this->emprunteur_jc = $this->_service_cran->getEmprunteur($jc); $this->_first_emprunt = array_first($this->emprunteur_jc->getEmprunts()); @@ -199,7 +185,7 @@ class PergameServiceGetEmprunteurTest extends PergameServiceTestCase { /** @test */ public function firstReservationIdShouldBe76() { $this->assertEquals(76, $this->_first_reservation->getId()); - } + } /** @test */ @@ -231,6 +217,7 @@ class PergameServiceGetEmprunteurTest extends PergameServiceTestCase { $this->assertEquals('Cran-Gevrier', $this->_first_reservation->getBibliotheque()); } + /** @test */ public function secondeReservationBibliothequeShouldBeEmpty() { $resa = $this->emprunteur_jc->getReservations()[1]; @@ -247,19 +234,19 @@ class PergameServiceGetExemplairePotterTest extends PergameServiceTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire') ->whenCalled('findAllBy') - ->with(array('role' => 'notice', + ->with(array('role' => 'notice', 'model' => $this->notice_potter)) - ->answers(array($this->potter_annecy, - $this->potter_cran_prete, + ->answers(array($this->potter_annecy, + $this->potter_cran_prete, $this->potter_cran_reserve, $this->potter_cran_dispo)) ->whenCalled('findFirstBy') - ->with(array('id_origine' => '1HP', + ->with(array('id_origine' => '1HP', 'id_bib' => 1)) ->answers($this->potter_annecy) ->whenCalled('findFirstBy') - ->with(array('id_origine' => '1HP', + ->with(array('id_origine' => '1HP', 'id_bib' => 2)) ->answers($this->potter_cran_prete); @@ -269,9 +256,9 @@ class PergameServiceGetExemplairePotterTest extends PergameServiceTestCase { ->answers(null) ->whenCalled('findFirstBy') - ->with(array('id_site' => 2, - 'id_notice_origine' => '1HP', - 'code_barres' => 'C-24', + ->with(array('id_site' => 2, + 'id_notice_origine' => '1HP', + 'code_barres' => 'C-24', 'EN_COURS' => 1)) ->answers(Class_Pret::getLoader() ->newInstanceWithId(59) @@ -414,8 +401,8 @@ class PergameServiceDelegateLegacyTest extends PergameServiceTestCase { ->answers(['statut' => 0, 'erreur' => '']) ->beStrict(); - $result = $this->_service_cran->reserverExemplaire(Class_Users::getIdentity(), - $this->potter_cran_prete, + $result = $this->_service_cran->reserverExemplaire(Class_Users::getIdentity(), + $this->potter_cran_prete, 'CRAN'); $this->assertEquals(['statut' => 0, 'erreur' => ''], $result); } -- GitLab