diff --git a/VERSIONS_HOTLINE/125582 b/VERSIONS_HOTLINE/125582 new file mode 100644 index 0000000000000000000000000000000000000000..55cde2025d300a2665d40cfef780d7145f1445cd --- /dev/null +++ b/VERSIONS_HOTLINE/125582 @@ -0,0 +1 @@ + - ticket #125582 : Avis : L'utilisateur ne peut plus créer d'avis non valide (trop court, trop long ou sans titre). Il est notifié le cas échéant. \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index e94a952c3bfab6662f93fc61de415ef534b29544..7c711f8d51470cccbec94b8287fec40f9714031c 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -206,7 +206,9 @@ class AbonneController extends ZendAfi_Controller_Action { return $this->_redirectClose($this->_getReferer()); } - $this->view->message = implode('.', $avis->getErrors()); + $this->view->message = implode('. ', $avis->getErrors()); + + $this->_helper->notify(implode('. ', $avis->getErrors())); } if ($avis != null) { @@ -241,6 +243,7 @@ class AbonneController extends ZendAfi_Controller_Action { public function editavisnoticeAction() { $user = Class_Users::getIdentity(); + if (!$user->isBibliothecaire() || (!$avis = Class_AvisNotice::find((int)$this->_getParam('id')))) { $this->_javascriptRedirectToReferrer(); @@ -276,7 +279,8 @@ class AbonneController extends ZendAfi_Controller_Action { $this->_javascriptRedirectToReferrer(); return; } - $form->addModelErrors($avis); + + $this->_helper->notify(implode('. ', $avis->getErrors())); } $this->view->form = $form; diff --git a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php index 07955802c1f1bbfb089e72328d2247eb81e9190e..60a28aacdee681fa785abb06027c79347d971efd 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php @@ -887,6 +887,119 @@ class AbonneControllerEditAvisNoticeNotFoundActionTest extends AbstractControlle +class AbonneControllerAddAvisNotAdminLoggedErrorActionTest extends AbstractControllerTestCase { + protected function _loginHook($account) { + $account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::INVITE; + $account->ROLE = 'invite'; + } + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Notice', ['id' => 1190178, + 'titre' => 'GARCONNIERE', + 'clef_oeuvre' => 'GARCONNIERELA--GREMILLONH-', + 'clef_alpha' => 'GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1', + 'type_doc' => Class_TypeDoc::LIVRE]); + + Class_AdminVar::set('AVIS_MIN_SAISIE', 15); + Class_AdminVar::set('AVIS_MAX_SAISIE', 42); + } + + + public function errorForAvis() { + $permalink = 'http://localhost/recherche/viewnotice/expressionRecherche/la+garconniere/tri/%2A/facette/T1/clef/GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1/id/1190178'; + return [[['avisEntete' => '', + 'avisTexte' => 'ceci n\'est pas le contenu', + 'avisNote' => 4, + 'url' => $permalink] + , 'Vous devez saisir un titre'], + + [['avisEntete' => 'trop court', + 'avisTexte' => 'court', + 'avisNote' => 4, + 'url' => $permalink], 'L\'avis doit avoir une longueur comprise entre 15 et 42 caractères' ], + + [['avisEntete' => 'trop long', + 'avisTexte' => 'ceci est un texte bien trop long pour être enregistré dans un avis', + 'avisNote' => 4, + 'url' => $permalink], 'L\'avis doit avoir une longueur comprise entre 15 et 42 caractères' ] + ]; + } + + /** + @test + @dataProvider errorForAvis + */ + public function withInvalidDataShouldDisplayError($avis,$error) { + $this->postDispatch('/opac/abonne/avis/id_notice/1190178/render/popup', + $avis, + true); + $this->assertFlashMessengerContentContains($error); + } +} + + + + +class AbonneControllerEditAvisNotAdminLoggedErrorActionTest extends AbstractControllerTestCase { + protected function _loginHook($account) { + $account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::MODO_BIB; + $account->ROLE = 'administrateur bibliothèque'; + } + + public function setUp() { + parent::setUp(); + + + $this->fixture('Class_Notice', ['id' => 1190178, + 'titre' => 'GARCONNIERE', + 'clef_oeuvre' => 'GARCONNIERELA--GREMILLONH-', + 'clef_alpha' => 'GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1', + 'type_doc' => Class_TypeDoc::LIVRE]); + + $this->fixture('Class_AvisNotice', ['id' => 12, + 'entete' => 'titre', + 'texte' => 'test', + 'note' => 4, + 'id_notice' => 1190178]); + + Class_AdminVar::set('AVIS_MIN_SAISIE', 15); + Class_AdminVar::set('AVIS_MAX_SAISIE', 42); + } + + + public function errorForAvis() { + $permalink = 'http://localhost/recherche/viewnotice/expressionRecherche/la+garconniere/tri/%2A/facette/T1/clef/GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1/id/1190178'; + return [ + [['entete' => 'trop court', + 'avis' => 'court', + 'note' => 3, + 'url' => $permalink], 'L\'avis doit avoir une longueur comprise entre 15 et 42 caractères' ], + + [['entete' => 'trop long', + 'avis' => 'ceci est un texte bien trop long pour être enregistré dans un avis', + 'note' => 3, + 'url' => $permalink], 'L\'avis doit avoir une longueur comprise entre 15 et 42 caractères' ] + ]; + } + + + /** + @test + @dataProvider errorForAvis + */ + public function withInvalidDataShouldDisplayError($avis,$error) { + $this->postDispatch('/opac/abonne/editavisnotice/id/12', + $avis, + true); + $this->assertFlashMessengerContentContains($error); + } +} + + + + class AbonneControllerEditAvisNoticeNotAdminLoggedActionTest extends AbstractControllerTestCase { protected function _loginHook($account) { $account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::INVITE;