Skip to content
Snippets Groups Projects
AbonneControllerPretsTest.php 9.23 KiB
Newer Older
llaffont's avatar
llaffont committed
<?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 'AbstractControllerTestCase.php';

abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerTestCase {
llaffont's avatar
llaffont committed
	protected function _loginHook($account) {
		$account->ROLE = "abonne_sigb";
		$account->ROLE_LEVEL = 2;
		$account->ID_USER = '123456';
		$account->PSEUDO = "Florence";
		$this->account = $account;
	}

llaffont's avatar
llaffont committed
	public function setUp() {
		parent::setUp();

		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users')->whenCalled('save')->answers(true);
		$this->florence = Class_Users::getLoader()->newInstanceWithId('123456');

gloas's avatar
gloas committed
		$this->zend_cache = Storm_Test_ObjectWrapper::mock();
		Storm_Cache::setDefaultZendCache($this->zend_cache);
		$this->zend_cache
			->whenCalled('remove')
			->answers(true);
	}

	
	public function assertUserRemovedFromEmprunteurCache($user) {
llaffont's avatar
llaffont committed
		$user_key = md5(serialize(['local', 
															 Class_WebService_SIGB_EmprunteurCache::newInstance()->keyFor($user)]));
		$this->assertTrue($this->zend_cache
											->methodHasBeenCalledWithParams('remove', array($user_key)));		
llaffont's avatar
llaffont committed
class AbonneControllerPretsListTwoPretsTest extends AbstractAbonneControllerPretsTestCase {
	public function setUp() {
		parent::setUp();

		$potter = new Class_WebService_SIGB_Emprunt('12', new Class_WebService_SIGB_Exemplaire(123));
		$potter->getExemplaire()->setTitre('Potter');
		$potter->parseExtraAttributes(['Dateretourprevue' => '29/10/2022',
																	 'Section' => 'Espace jeunesse',
																	 'Auteur' => 'JK Rowling',
																	 'Bibliotheque' => 'Astrolabe',
																	 'N° de notice' => '1234',
																	 'Type' => 'P1']);
llaffont's avatar
llaffont committed

		$alice = new Class_WebService_SIGB_Emprunt('13', new Class_WebService_SIGB_Exemplaire(456));
		$alice->getExemplaire()->setTitre('Alice');
		$alice->parseExtraAttributes(array(
																			 'Dateretourprevue' => '21/10/2010',
																			 'Section' => 'Espace jeunesse',
																			 'Auteur' => 'Lewis Caroll',
																			 'Bibliotheque' => 'Almont',
																			 'N° de notice' => '5678'));

		$exemplaire_alice = Class_Exemplaire::newInstanceWithId(918, ['id_origine' => 5678,
																																	'notice' => Class_Notice::newInstanceWithId(827,
																																																							['titre_principal' => 'Alice'])]);
		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire')
			->whenCalled('findFirstBy')
			->with(['id_origine' => 5678])
			->answers($exemplaire_alice);


llaffont's avatar
llaffont committed
		$emprunteur = new Class_WebService_SIGB_Emprunteur('1234', 'Florence');
		$emprunteur->empruntsAddAll(array($potter, $alice));

		$fiche_sigb = array('type_comm' => 2, //OPSYS
												'fiche' => $emprunteur,
												'message' => '',
												'erreur' => '',
												'nom_aff' => 'FloFlo');

		$this->florence->setFicheSigb($fiche_sigb)
									->setPseudo('FloFlo');

		$this->dispatch('/opac/abonne/prets');
	}


	public function testPageIsRendered() {
		$this->assertController('abonne');
		$this->assertAction('prets');
	}


	/** @test */
	public function cacheShouldHaveBeenCleared() {
		$this->assertUserRemovedFromEmprunteurCache($this->florence);
	}


llaffont's avatar
llaffont committed
	public function testNomAffiche() {
		$this->assertQueryContentContains("div.abonneTitre", 'FloFlo');
	}

llaffont's avatar
llaffont committed

	/** @test */
	public function tableShouldHaveClassTableSorter() {
		$this->assertXPath('//table[@class="tablesorter"]');
	}


	/** @test */
	public function tableSorterShouldBeLoaded() {
		$this->assertXPath('//script[contains(@src, "tablesorter.min")]');
		$this->assertXPath('//link[contains(@href, "tablesorter/themes/blue/style.css")]');
		$this->assertXPathContentContains('//script', '$(".tablesorter").tablesorter()');
	}

llaffont's avatar
llaffont committed
	public function testViewTitreAlice() {
		$this->assertXPathContentContains("//tbody/tr[1][@class=\"pret_en_retard\"]//td//a[contains(@href, '/recherche/viewnotice/id/827/retour_abonne/prets')]", 
																			'Alice');
llaffont's avatar
llaffont committed
	}

	public function testViewBibAliceIsAlmont() {
		$this->assertXPathContentContains("//tbody/tr[1]//td", 'Almont');
llaffont's avatar
llaffont committed
	}

	public function testViewAuteurAliceIsLewisCaroll() {
		$this->assertXPathContentContains("//tbody/tr[1]//td", 'Lewis Caroll');
llaffont's avatar
llaffont committed
	}

	public function testViewDateRetourAliceIsTwentyOneOctober() {
		$this->assertXPathContentContains("//tbody/tr[1]//td", '21/10/2010');
llaffont's avatar
llaffont committed
	}

	public function testLinkProlongerForAlice() {
		$this->assertXPathContentContains("//tbody/tr[1]//td//a[@href='/abonne/prolongerPret/id_pret/13']",
llaffont's avatar
llaffont committed
																			'Prolonger');
	}

	public function testViewTitrePotter() {
		$this->assertXPathContentContains("//tbody/tr[2]//td", 'Potter', $this->_response->getBody());
llaffont's avatar
llaffont committed
	}

	public function testViewBibPotterIsAstrolabe() {
		$this->assertXPathContentContains("//tbody/tr[2]//td", 'Astrolabe');
llaffont's avatar
llaffont committed
	}

	public function testViewAuteurPotterIsJKRolling() {
		$this->assertXPathContentContains("//tbody/tr[2]//td", 'JK Rowling');
llaffont's avatar
llaffont committed
	public function testViewDateRetourPotterIsTwentyNineOctober2022() {
		$this->assertXPathContentContains("//tbody/tr[2][not(@class)]//td", '29/10/2022');
llaffont's avatar
llaffont committed
	}

	public function testLinkProlongerForPotter() {
		$this->assertXPathContentContains("//tbody/tr[2]//td//a[@href='/abonne/prolongerPret/id_pret/12']",
llaffont's avatar
llaffont committed
																			'Prolonger');
	}

	/** @test **/
	public function colonneInformationShouldBeDisplay(){
		$this->assertXPathContentContains('//thead//th','Informations');
	}


	/** @test **/
	public function colonneInformationShouldContainsP1(){
		$this->assertXPathContentContains('//tbody//td','P1', $this->_response->getBody());
	}

llaffont's avatar
llaffont committed
class AbonneControllerPretsListReservationTest extends AbstractAbonneControllerPretsTestCase {
	public function setUp() {
		parent::setUp();

		$potter = new Class_WebService_SIGB_Reservation('12', new Class_WebService_SIGB_Exemplaire(123));
		$potter->getExemplaire()->setTitre('Potter');
llaffont's avatar
llaffont committed
		$potter->parseExtraAttributes(array('Etat' => 'Réservation émise',
																				'Rang' => '2',
																				'Bibliotheque' => 'Tombouctou',
																				'N° de notice' => 564));

		$exemplaire_potter = Class_Exemplaire::newInstanceWithId(918, ['id_origine' => 564,
																																	 'notice' => Class_Notice::newInstanceWithId(823,
																																																							['titre_principal' => 'Potter'])]);
		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire')
			->whenCalled('findFirstBy')
			->with(['id_origine' => 564])
			->answers($exemplaire_potter);

llaffont's avatar
llaffont committed

		$emprunteur = new Class_WebService_SIGB_Emprunteur('1234', 'Florence');
		$emprunteur->reservationsAddAll(array($potter));

		$fiche_sigb = array('type_comm' => 2, //OPSYS
												'fiche' => $emprunteur,
												'message' => '',
												'erreur' => '',
												'nom_aff' => 'FloFlo');

		$this->florence->setFicheSigb($fiche_sigb)
									->setPseudo('FloFlo');

		$this->dispatch('/opac/abonne/reservations');
	}


pbarroca's avatar
pbarroca committed
	/** @test */
	public function controllerShouldBeAbonne() {
llaffont's avatar
llaffont committed
		$this->assertController('abonne');
	/** @test */
	public function cacheShouldHaveBeenCleared() {
		$this->assertUserRemovedFromEmprunteurCache($this->florence);
	}


pbarroca's avatar
pbarroca committed
	/** @test */
	public function actionShouldBeReservations() {
llaffont's avatar
llaffont committed
		$this->assertAction('reservations');
	}


pbarroca's avatar
pbarroca committed
	/** @test */
	public function nomShouldBeFloFlo() {
		$this->assertQueryContentContains('div.abonneTitre', 'FloFlo');
pbarroca's avatar
pbarroca committed

llaffont's avatar
llaffont committed
	/** @test */
	public function tableShouldHaveClassTableSorter() {
		$this->assertXPath('//table[@class="tablesorter"]');
	}


	/** @test */
	public function tableSorterShouldBeLoaded() {
		$this->assertXPath('//script[contains(@src, "tablesorter.min")]');
	}


pbarroca's avatar
pbarroca committed
	/** @test */
	public function titreShouldBePotterAndLinkToNotice() {
		$this->assertXPathContentContains('//tbody/tr[1]//td//a[contains(@href, "recherche/viewnotice/id/823/retour_abonne/reservations")]', 
																			'Potter',
																			$this->_response->getBody());
pbarroca's avatar
pbarroca committed

	/** @test */
	public function etatShouldBeReservationEmise() {
		$this->assertXPathContentContains('//tbody/tr[1]//td', 'Réservation émise');
pbarroca's avatar
pbarroca committed

	/** @test */
	public function rangShouldBeTwo() {
		$this->assertXPathContentContains('//tbody/tr[1]//td', '2');
pbarroca's avatar
pbarroca committed

	/** @test */
	public function linkToDeleteShouldBeAsExpected() {
		$this->assertXPath("//tbody/tr[1]//td//a[@href='/abonne/reservations/id_delete/12']");


	/** @test */
	public function bibliothequeShouldBeTombouctou() {
		$this->assertXPathContentContains('//tbody/tr[1]//td', 'Tombouctou', $this->_response->getBody());