Commit 6a62470a authored by lbrun's avatar lbrun
Browse files

dev#25892: add tests + refacto

parent 12eae328
......@@ -414,8 +414,7 @@ class AbonneController extends ZendAfi_Controller_Action {
Class_CommSigb::getInstance()->onPlaceConsultationCancelBooking(Class_Users::getIdentity(), $delete);
}
$this->view->consultations_reservations = Class_CommSigb::getInstance()
->getOnPlaceConsultationBookings(Class_Users::getIdentity());
$this->view->consultations_reservations = $this->_user->getConsultations();
$this->view->fiche = $this->_user->getFicheSigb();
$this->view->user = $this->_user;
Class_ScriptLoader::getInstance()->loadTableSorter();
......
......@@ -691,7 +691,7 @@ class RechercheController extends ZendAfi_Controller_Action {
return;
}
$form = new ZendAfi_Form_Pickup();
$form = new ZendAfi_Form_ConsultationPickup();
$radio = $form->getElement('location');
if (!$exemplaire = Class_Exemplaire::find($this->_getParam('copy_id')))
......
......@@ -196,6 +196,12 @@ class Class_CommSigb {
}
public function canConsult($user, $field) {
$sigb = $this->SIGBConnect($user);
return (is_array($sigb)) ? false : $sigb->canConsult($field);
}
/**
* @param Class_Users $user
* @param int $id_pret
......@@ -210,16 +216,22 @@ class Class_CommSigb {
}
public function withUserAndSIGBDo($std_user, $closure) {
$user = is_a($std_user, 'Class_Users') ? $std_user : Class_Users::find($std_user->ID_USER);
Class_WebService_SIGB_EmprunteurCache::newInstance()->remove($user);
public function SIGBConnect($user) {
if (null == $sigb = $user->getSIGBComm())
return ['erreur' => $this->_('Communication SIGB indisponible')];
if (!$sigb->isConnected())
return ['erreur' => $this->_("Une erreur de communication avec le serveur a fait échouer la requête. Merci de signaler ce problème à la bibliothèque.")];
return $closure($user, $sigb);
return $sigb;
}
public function withUserAndSIGBDo($std_user, $closure) {
$user = is_a($std_user, 'Class_Users') ? $std_user : Class_Users::find($std_user->ID_USER);
Class_WebService_SIGB_EmprunteurCache::newInstance()->remove($user);
$sigb = $this->SIGBConnect($user);
return (is_array($sigb)) ? $sigb : $closure($user, $sigb);
}
}
\ No newline at end of file
......@@ -20,7 +20,7 @@
*/
class Class_Exemplaire extends Storm_Model_Abstract {
// use Trait_CustomFields;
protected $_table_name = 'exemplaires';
protected $_table_primary = 'id';
protected $_group_count = 0;
......@@ -223,10 +223,12 @@ class Class_Exemplaire extends Storm_Model_Abstract {
return $sigbExemplaire->isReservable();
}
public function canConsult() {
return ($this->getSubfield('r') == 'PATIMP');
return Class_CommSigb::getInstance()->canConsult(Class_Users::getIdentity(), $this->getSubfield('r'));
}
public function getSubfield($id) {
$fields = $this->zone995toArray();
foreach($fields as $field)
......
......@@ -1151,6 +1151,19 @@ class Class_Users extends Storm_Model_Abstract {
}
public function getConsultations() {
$consultations = Class_CommSigb::getInstance()->getOnPlaceConsultationBookings($this);
if (isset($consulations['erreur']))
return [];
return $consultations;
}
public function getNbConsultations() {
return count($this->getConsultations());
}
public function countWaitingToBePulled() {
return count($this->getEmprunteur()->getHoldsWaitingToBePulled());
}
......
......@@ -287,4 +287,9 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic
protected function _getErrorFromCode($error_code, $default_message) {
return $this->_error($default_message);
}
public function canConsult() {
return false;
}
}
\ No newline at end of file
......@@ -22,6 +22,8 @@
class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_AbstractRESTService {
const MOULINS_POPUP_SERVER = '46.20.169.9/moulins';
const METAINSTITUTION = 'RES';
const CONSULTATION_TAG = 'PATIMP';
protected static $SOAP_CLIENT_CLASS='Class_WebService_MappedSoapClient';
protected $_soap_client;
......@@ -228,6 +230,11 @@ class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_Abstrac
}
public function canConsult($field) {
return $field == self::CONSULTATION_TAG;
}
public function getAvailableItems($id) {
$ids = explode('/', $id);
$xml = $this->httpGet(['fu' => 'GetASRItems',
......
......@@ -20,7 +20,7 @@
*/
class ZendAfi_Form_Pickup extends ZendAfi_Form {
class ZendAfi_Form_ConsultationPickup extends ZendAfi_Form {
public function init() {
parent::init();
......
......@@ -23,10 +23,7 @@ class ZendAfi_View_Helper_Abonne_Reservations extends ZendAfi_View_Helper_Abonne
if (!$user->isAbonne())
return '';
$nb_resas = $user->getNbReservations();
$consultation_resas = Class_CommSigb::getInstance()->getOnPlaceConsultationBookings(Class_Users::getIdentity());
if (!isset($consultation_resas['erreur']))
$nb_resas += count($consultation_resas);
$nb_resas = $user->getNbReservations() + $user->getNbConsultations();
$str_resas = $this->view->_plural($nb_resas,
"Vous n'avez aucune réservation en cours.",
......
......@@ -56,6 +56,7 @@ abstract class OnSiteConsultationTestCase extends AbstractControllerTestCase {
'emplacement' => 'emplacement de test',
'cote' => 'VOD-T-DLJ',
'dispo' => 'Disponible',
'zone995' => serialize([['clef' => 'r', 'valeur' => 'NBA']]),
'date_retour' => 'En mai',
'reservable' => true,
'code_barres' => '7777734343488'])]);
......@@ -92,7 +93,18 @@ abstract class OnSiteConsultationTestCase extends AbstractControllerTestCase {
$this->_mock_service = $this->mock()
->whenCalled('getExemplaire')
->answers($sigb_exemplaire);
->answers($sigb_exemplaire)
->whenCalled('isConnected')
->answers(true)
->whenCalled('canConsult')
->with('PATIMP')
->answers(true)
->whenCalled('canConsult')
->with('NBA')
->answers(false);
Class_WebService_SIGB_VSmart::setService($this->_mock_service);
}
......@@ -336,13 +348,12 @@ class OnSiteConsultationReservationsTableTest extends OnSiteConsultationTwoReser
class OnSiteConsultationAbonneReservationsTest extends OnSiteConsultationTwoReservationsTest {
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/fiche', true);
}
/** @test */
function aDivAbonneFicheShouldContainsVousAvezDeuxReservationsEnCours() {
$this->dispatch('/abonne/fiche', true);
$this->assertXPathContentContains('//div/a[contains(@href, "abonne/reservations")]',
'Vous avez 2 réservations en cours');
}
......
......@@ -918,9 +918,11 @@ class VSmartServiceGetConsultationRequestsTest extends VSmartServiceTestCase {
'auteurs' => 'Annie Brossard',
'exemplaire' => $exemplaires]);
$this->consultation = Class_WebService_SIGB_VSmart_Service::newInstance()
$this->vsmart = Class_WebService_SIGB_VSmart_Service::newInstance()
->setServerRoot('http://46.20.169.8/production')
->setWebClient($mock_web_client)
->setWebClient($mock_web_client);
$this->consultation = $this->vsmart
->getConsultationRequests('MCA000063');
}
......@@ -934,6 +936,17 @@ class VSmartServiceGetConsultationRequestsTest extends VSmartServiceTestCase {
public function recordAuthorShouldBeAnnieBrossard() {
$this->assertEquals('Annie Brossard',$this->consultation[0]->getRecord()->getAuteurs());
}
/** @test */
public function withPATIMPCanConsultShouldReturnTrue() {
$this->assertTrue($this->vsmart->canConsult('PATIMP'));
}
/** @test */
public function withoutPATIMPCanConsultShouldReturnFalse() {
$this->assertFalse($this->vsmart->canConsult('NBA'));
}
}
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment