diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 0bc78b5d31c4c38d758ebac40d175ffcc2b6e7a5..13914be635907d95ea96fb89ee15eb183a769e46 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -901,12 +901,16 @@ class AbonneController extends ZendAfi_Controller_Action { $suggestion = $form->newBuySuggest($post); if ($form->isValid($suggestion)) { + + // $suggestion->save(); always return true without considering webservice answers. UX choice ? $suggestion->save(); + try { $suggestion->sendMail('noreply@'.$this->_request->getHttpHost()); } catch (Zend_Mail_Exception $e) { $this->_helper->notify($this->_('Aucun courriel envoyé, erreur: ').$this->_($e->getMessage())); } + $this->_helper->notify($this->_('Suggestion d\'achat enregistrée')); $this->_redirect('/opac/abonne/suggestion-achat'); } @@ -923,7 +927,7 @@ class AbonneController extends ZendAfi_Controller_Action { return; } } - + public function suggestionAchatInactiveAction() {} diff --git a/library/Class/Users.php b/library/Class/Users.php index 19ffa1450c22bfd04a213900f5fbd0b6457f88c6..2c5c098be0148f9e08a8c12e6afafbfb853a58a3 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -1551,7 +1551,6 @@ class Class_Users extends Storm_Model_Abstract { public function getSuggestionAchat() { - xdebug_break(); return (($sigb_com = $this->getSIGBComm()) && $sigb_com->providesSuggestions()) ? $sigb_com->suggestionsOf($this) : parent::_get('suggestion_achat'); diff --git a/library/Class/WebService/SIGB/Nanook/BuySuggestForm.php b/library/Class/WebService/SIGB/Nanook/BuySuggestForm.php index ae290af59a5e6a68ca8032c42849a213ba03fbaf..02bf8b2291d6da8cebac9a6e7cf4e85fe4fa841b 100644 --- a/library/Class/WebService/SIGB/Nanook/BuySuggestForm.php +++ b/library/Class/WebService/SIGB/Nanook/BuySuggestForm.php @@ -32,43 +32,43 @@ class Class_WebService_SIGB_Nanook_BuySuggestForm extends ZendAfi_Form_Suggestio parent::init(); $this - ->addElement('text', 'title', ['label' => $this->_('Titre').' *', + ->addElement('text', 'Title', ['label' => $this->_('Titre').' *', 'placeholder' => $this->_('ex: Harry Potter à l\'école des sorciers'), 'size' => 80, 'required' => true, 'allowEmpty' => false]) - ->addElement('text', 'author', ['label' => $this->_('Auteur').' *', + ->addElement('text', 'Author', ['label' => $this->_('Auteur').' *', 'placeholder' => 'ex: Joanne Kathleen Rowling', 'size' => 80, 'required' => true, 'allowEmpty' => false]) - ->addElement('text', 'isbn', ['label' => $this->_('Code-barres / ISBN'), + ->addElement('text', 'Isbn', ['label' => $this->_('Code-barres / ISBN'), 'placeholder' => 'ex: 2-07-054127-4', 'size' => 17]) - ->addElement('url', 'url', ['label' => $this->_('URL'), + ->addElement('url', 'Url', ['label' => $this->_('URL'), 'placeholder' => 'http://www...', 'size' => 80]) - ->addElement('textarea', 'comment', ['label' => '', + ->addElement('textarea', 'Comment', ['label' => '', 'cols' => 70, 'rows' => 10]) - ->addElement('text', 'site', ['label' => $this->_('Site'), + ->addElement('text', 'Site', ['label' => $this->_('Site'), 'value' => Class_Users::getIdentity()->getLibelleBib(), 'disabled' => true]) - ->addDisplayGroup(['title', - 'author', - 'isbn', - 'site'], + ->addDisplayGroup(['Title', + 'Author', + 'Isbn', + 'Site'], 'suggestion', ['legend' => $this->_('Informations sur le document')]) - ->addDisplayGroup(['url', - 'comment'], + ->addDisplayGroup(['Url', + 'Comment'], 'notes_group', ['legend' => $this->_('Notes')]) diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index c2a306bfe5a65e9de94b2009623c79e820260aac..14470fa42dfabaa7efbe5c836384626ee2b03298 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -70,6 +70,23 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac } + + // This method is call in Class_Suggestion->save(); + // Class_Suggestion->save() always return true without considering webservice answers. + // Looks like a UX choice ? So no return statement is needed ... + public function suggest($suggestion) { + $xml = $this->getWebClient() + ->postData($this->buildQueryURL(['service' => 'CreateSuggest', + 'patronId' => $suggestion->getUser()->getIdSigb()]), + ['site' => $suggestion->getSite(), + 'title' => $suggestion->getTitle(), + 'author' => $suggestion->getAuthor(), + 'isbnean' => $suggestion->getIsbn(), + 'desclink' => $suggestion->getUrl(), + 'comment' => $suggestion->getComment()]); + } + + /** * @param Class_Users $user * @param int $notice_id diff --git a/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php b/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php index fd75c75632dd509c11e0c64fb51df20dbae0178a..ac4c97c386a4921ed6cfef3e4bf227823a515705 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php @@ -53,6 +53,7 @@ abstract class AbstractAbonneControllerSuggestionAchatNanookTestCase extends Abs $sigb_conf->setIdBib(12); $this->_francis = $this->fixture('Class_Users', ['id' => 3, + 'id_sigb' => '187', 'login' => 'francis', 'password' => 'test', 'int_bib' => $sigb_conf]); @@ -69,6 +70,26 @@ abstract class AbstractAbonneControllerSuggestionAchatNanookTestCase extends Abs ->with('http://nanookService/service/GetPatronInfo/patronId/187') ->answers(NanookFixtures::albatorPatronInfoResponse()) + ->whenCalled('postData') + ->with('http://nanookService/service/CreateSuggest/patronId/187', + ['site' => '12', + 'title' => 'fu', + 'author' => 'mf', + 'isbnean' => '2-07-0541 27_4', + 'desclink' => '', + 'comment' => 'no']) + ->answers(NanookFixtures::createSuggestFuSucces()) + + ->whenCalled('postData') + ->with('http://nanookService/service/CreateSuggest/patronId/187', + ['site' => '12', + 'title' => 'fu', + 'author' => 'Ye', + 'isbnean' => '2-07-0541 27_4', + 'desclink' => '', + 'comment' => 'no']) + ->answers(NanookFixtures::createSuggestFuError()) + ->beStrict(); $sigb_comm = Class_IntBib::find(3)->getSIGBComm(); @@ -146,16 +167,59 @@ class AbonneControllerSuggestionAchatNanookAddPostTest extends AbstractAbonneCon public function setUp() { parent::setUp(); - $this->postDispatch('/opac/abonne/suggestion-achat-add', ['titre' => 'fu', - 'auteur' => 'mf', - 'isbn' => '2-07-0541 27_4', - 'description_url' => 'bokeh-kibrary-portail.org', - 'commentaire' => 'no']); + + $mock_transport = new MockMailTransport(); + Zend_Mail::setDefaultTransport($mock_transport); + + $this->postDispatch('/opac/abonne/suggestion-achat-add', ['Site' => '12', + 'Title' => 'fu', + 'Author' => 'mf', + 'Isbn' => '2-07-0541 27_4', + 'Url' => '', + 'Comment' => 'no']); } /** @test */ public function suggestionShouldHaveBeenSend() { - $this->assertContains([0], $this->_francis->getSuggestionAchat()); + $this->assertFlashMessengerContains(['notification' => ['message' => 'Suggestion d\'achat enregistrée']]); + } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); + } +} + + + +class AbonneControllerSuggestionAchatNanookAddPostErrorsTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $mock_transport = new MockMailTransport(); + Zend_Mail::setDefaultTransport($mock_transport); + + $this->postDispatch('/opac/abonne/suggestion-achat-add', ['Site' => '12', + 'Title' => 'fu', + 'Author' => 'Ye', + 'Isbn' => '2-07-0541 27_4', + 'Url' => '', + 'Comment' => 'no']); + } + + + /** @test */ + public function suggestionShouldHaveBeenSend() { + $this->assertFlashMessengerContains(['notification' => ['message' => 'Suggestion d\'achat enregistrée']]); + } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); } } diff --git a/tests/fixtures/NanookFixtures.php b/tests/fixtures/NanookFixtures.php index af02437b0d96a97caec8550481ca06ada0466958..e5f38aa693e880a1c41f9998b8fcb194afedeab1 100644 --- a/tests/fixtures/NanookFixtures.php +++ b/tests/fixtures/NanookFixtures.php @@ -464,5 +464,81 @@ class NanookFixtures { public static function albatorAuthenticatePatronResponse() { return '<AuthenticatePatron><patronId>187</patronId></AuthenticatePatron>'; } + + + public static function createSuggestFuSucces() { + return ' <getpatroninfo> + <patronid> + 3358 + </patronid> + <barcode> + 01 + </barcode> + <lastname> + ALBATOR + </lastname> + <firstname> + Lucien + </firstname> + <displayorder> + 1 + </displayorder> + <birthdate> + 1950-01-01 + </birthdate> + <phonenumber></phonenumber> + <town></town> + <zipcode></zipcode> + <address></address> + <enddate> + 2020-10-05 + </enddate> + <mail></mail> + <loans></loans> + <holds></holds> + <suggests> + <suggest> + <site> + 12 + </site> + <status> + En attente + </status> + <title> + Purple for the win + </title> + <author> + albator + </author> + <isbnean></isbnean> + <desclink></desclink> + <comment></comment> + </suggest> + <suggest> + <site> + 12 + </site> + <status> + En attente + </status> + <title> + fu + </title> + <author> + albator + </author> + <isbnean></isbnean> + <desclink></desclink> + <comment></comment> + </suggest> + </suggests> + </getpatroninfo> +'; + } + + + public static function createSuggestFuError() { + return '<CreateSuggest><error>CreateSuggestError</error></CreateSuggest>'; + } } ?> \ No newline at end of file