diff --git a/.gitattributes b/.gitattributes index 38f61995415f6754f73bff44b6e79e2207bfbba5..288fa2caec3426a16008f01a76097e2d2f055153 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6066,6 +6066,8 @@ tests/library/ZendAfi/View/Helper/HistoriqueRechercheTest.php -text tests/library/ZendAfi/View/Helper/IconeSupportTest.php -text tests/library/ZendAfi/View/Helper/IframeContainerTest.php -text tests/library/ZendAfi/View/Helper/Java/MenuImageTest.php -text +tests/library/ZendAfi/View/Helper/Notice/AvisTest.php -text +tests/library/ZendAfi/View/Helper/Notice/ExemplairesReservationTest.php -text tests/library/ZendAfi/View/Helper/Notice/FacettesTypeDocTest.php -text tests/library/ZendAfi/View/Helper/Notice/MurTest.php -text tests/library/ZendAfi/View/Helper/PageContextTest.php -text diff --git a/tests/library/ZendAfi/View/Helper/Notice/AvisTest.php b/tests/library/ZendAfi/View/Helper/Notice/AvisTest.php new file mode 100644 index 0000000000000000000000000000000000000000..350e748fd574b221f321e0a0523ef4b2763b806c --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/Notice/AvisTest.php @@ -0,0 +1,100 @@ +<?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 + */ + + +class ZendAfi_View_Helper_Notice_AvisTest extends ViewHelperTestCase { + protected $_html; + + public function setUp() { + parent::setUp(); + $this->_helper = new ZendAfi_View_Helper_Notice_Avis(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + + $this->_view = new ZendAfi_Controller_Action_Helper_View(); + + Class_Profil::setCurrentProfil(new Class_Profil()); + Zend_Registry::get('locale')->setLocale('fr'); + Zend_Registry::get('translate')->setLocale('fr'); + + $this->millenium = new Class_Notice(); + $this->millenium + ->setId(25); + + $this->avis = array("bib" => array("nombre" => 0), + "abonne" => array("nombre" => 0)); + + $this->avis_bib_seulement = new Class_AdminVar(); + $this + ->_generateLoaderFor('Class_AdminVar', array('find')) + ->expects($this->atLeastOnce()) + ->method('find') + ->with('AVIS_BIB_SEULEMENT') + ->will($this->returnValue($this->avis_bib_seulement)); + + + $account = new stdClass(); + $account->username = 'AutoTest' . time(); + $account->password = md5( 'password' ); + $account->ID_USER = 0; + $account->ROLE_LEVEL = 4; + $account->confirmed = true; + $account->enabled = true; + ZendAfi_Auth::getInstance()->getStorage()->write($account); + } + + public function testVisibleWithAdminAndAvisReaderAllowed() { + ZendAfi_Auth::getInstance()->getIdentity()->ROLE_LEVEL = 5; + $this->avis_bib_seulement->setValeur('0'); + + $html = $this->_helper->getAvis($this->millenium, $this->avis, $this->_view); + $this->assertTrue(strpos($html, 'Donnez ou modifiez votre avis') != false, $html); + } + + + public function testVisibleWithReaderAndAvisReaderAllowed() { + ZendAfi_Auth::getInstance()->getIdentity()->ROLE_LEVEL = 1; + $this->avis_bib_seulement->setValeur('0'); + + $html = $this->_helper->getAvis($this->millenium, $this->avis, $this->_view); + $this->assertTrue(strpos($html, 'Donnez ou modifiez votre avis') != false); + } + + + public function testVisibleWithAdminAndAvisReaderForbidden() { + ZendAfi_Auth::getInstance()->getIdentity()->ROLE_LEVEL = 5; + $this->avis_bib_seulement->setValeur('1'); + + $html = $this->_helper->getAvis($this->millenium, $this->avis, $this->_view); + $this->assertTrue(strpos($html, 'Donnez ou modifiez votre avis') != false); + } + + + public function testInvisibleWithReaderAndAvisReaderForbidden() { + ZendAfi_Auth::getInstance()->getIdentity()->ROLE_LEVEL = 1; + $this->avis_bib_seulement->setValeur('1'); + + $html = $this->_helper->getAvis($this->millenium, $this->avis, $this->_view); + $this->assertFalse(strpos($html, 'Donnez ou modifiez votre avis')); + } +} + + +?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/Notice/ExemplairesReservationTest.php b/tests/library/ZendAfi/View/Helper/Notice/ExemplairesReservationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..22e7a0f52278ff5c46621a7d0e5d48bc01f74550 --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/Notice/ExemplairesReservationTest.php @@ -0,0 +1,172 @@ +<?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 + */ + +abstract class ZendAfi_View_Helper_Notice_ExemplairesTestCase extends ViewHelperTestCase { + protected $_html; + + public function setUp() { + parent::setUp(); + $this->_helper = new ZendAfi_View_Helper_Notice_Exemplaires(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + } +} + + + + +class NoticeHtmlGetExemplairesEmptyTest extends ZendAfi_View_Helper_Notice_ExemplairesTestCase { + /** @test */ + function noticeHTMLShouldReturnEmptyString() { + $this->assertEquals('', $this->_helper->Notice_Exemplaires(array())); + } + +} + + + + +class NoticeHtmlGetExemplairesWithOneExemplaireNoWebServiceTest extends ZendAfi_View_Helper_Notice_ExemplairesTestCase { + public function setUp() { + parent::setUp(); + Class_Profil::setCurrentProfil(new Class_Profil()); + $exemplaire = array('id_bib' => -1, + 'id_notice' => '24765', + 'annexe' => 'MOUL', + 'count(*)' => 2, //??? + 'cote' => 'DSEM', + 'dispo' => "Disponible", + 'code_barres' => "12345"); + $this->html = $this->_helper->Notice_Exemplaires(array($exemplaire)); + } + + + /** @test */ + function noticeHTMLShouldDisplayTableHeader() { + $this->assertContains('table', $this->html); + } + + + /** @test */ + public function reservationLinkShouldNotBeVisible() { + $this->assertNotXPath($this->html, + '//a[@data-popup="true"]'); + } +} + + + + +abstract class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase extends ZendAfi_View_Helper_Notice_ExemplairesTestCase { + protected $exemplaire; + + public function setUp() { + parent::setUp(); + $_SESSION['id_profil'] = 4; + Class_Profil::setCurrentProfil( + Class_Profil::getLoader() + ->newInstanceWithId(4) + ->setCfgNotice(array('exemplaires' => array('grouper' => 1, + 'bib' => 1, + 'annexe' => 1, + 'section' => 1, + 'emplacement' => 1, + 'dispo' => 1, + 'date_retour' => 1, + 'localisation' => 1, + 'plan' => 1, + 'resa' => 1)))); + + + Class_IntBib::getLoader() + ->newInstanceWithId(1) + ->setCommSigb(Class_IntBib::COM_MICROBIB) + ->setCommParams(''); + + + Class_WebService_SIGB_Microbib::setService(Storm_Test_ObjectWrapper::on(new StdClass()) + ->whenCalled('getExemplaire') + ->answers(Class_WebService_SIGB_Exemplaire::newInstance() + ->setId(5) + ->setDisponibiliteEnPret() + ->setDateRetour('20/03/2012') + ->beReservable()) + ->whenCalled('isConnected') + ->answers(true) + ->getWrapper()); + + $this->exemplaire = array('id' => 12, + 'id_bib' => 1, + 'id_notice' => '24765', + 'id_origine' => '666', + 'annexe' => 'MOUL', + 'count(*)' => 2, //??? + 'cote' => 'DSEM', + 'dispo' => "Disponible", + 'code_barres' => "12345", + 'section' => 3, + 'emplacement' => 2); + } +} + + + + +class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTest + extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { + + public function setUp() { + parent::setUp(); + Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 0]); + $this->html = $this->_helper->Notice_Exemplaires(array($this->exemplaire)); + } + + + /** @test */ + public function reservationLinkShouldBePopup() { + $this->assertXPath($this->html, + '//a[@data-popup="true"][contains(@href, "recherche/reservation-pickup-ajax/id_bib/1/id_origine/12/code_annexe/MOUL")]'); + } +} + + + + +class NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceAndPickupActiveTest + extends NoticeHtmlGetExemplairesWithOneExemplaireAndWebServiceTestCase { + + + public function setUp() { + parent::setUp(); + Class_CosmoVar::newInstanceWithId('site_retrait_resa', ['valeur' => 1]); + + $this->html = $this->_helper->Notice_Exemplaires(array($this->exemplaire)); + } + + + + /** @test */ + public function reservationLinkShouldBePopup() { + $this->assertXPath($this->html, + '//a[@data-popup="true"][contains(@href, "recherche/reservation-pickup-ajax/id_bib/1/id_origine/12/code_annexe/MOUL")]'); + } +} + +?> \ No newline at end of file