From e21fe036adbfbfa402a49b4c862a15c43f6eeeed Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@afi-sa.fr> Date: Tue, 12 Sep 2017 11:56:52 +0200 Subject: [PATCH] hotline #64605 : fix visibility check of orphaned ratings --- VERSIONS_HOTLINE/64605 | 1 + library/Trait/Avis.php | 8 +- .../controllers/NoticeAjaxControllerTest.php | 115 ++++++++++++++---- 3 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 VERSIONS_HOTLINE/64605 diff --git a/VERSIONS_HOTLINE/64605 b/VERSIONS_HOTLINE/64605 new file mode 100644 index 00000000000..41bf75a1955 --- /dev/null +++ b/VERSIONS_HOTLINE/64605 @@ -0,0 +1 @@ + - ticket #64605 : Avis sur les notices : Correction de l'affichage des avis en attente de modération \ No newline at end of file diff --git a/library/Trait/Avis.php b/library/Trait/Avis.php index 9cce4a6f6a7..89ab32c6ec4 100644 --- a/library/Trait/Avis.php +++ b/library/Trait/Avis.php @@ -68,10 +68,12 @@ trait Trait_Avis { public function isVisibleForUser($user) { - if ($this->getUser() == null || ($user && ($this->getIdUser() == $user->ID_USER))) - return true; + if (!$this->getUser()) + return !$this->isWaitingForModeration(); - return $this->isWaitingForModeration() == false; + return ($user && ($this->getIdUser() == $user->ID_USER)) + ? true + : !$this->isWaitingForModeration(); } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index 1fea64ff4d3..b69eb4b43f9 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -1419,56 +1419,127 @@ class NoticeAjaxControllerDisponibiliteNoticeTest extends AbstractControllerTest -abstract class NoticeAjaxControllerNoticeWithAvisTestCase extends AbstractControllerTestCase { +abstract class NoticeAjaxControllerNoticeWithAvisTestCase + extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; public function setup() { parent::setup(); - Class_AdminVar::newInstanceWithId('AVIS_BIB_SEULEMENT')->setValeur(0); + Class_AdminVar::set('AVIS_BIB_SEULEMENT', 0); + Class_AdminVar::set('AVIS_MIN_SAISIE', 1); + Class_AdminVar::set('AVIS_MAX_SAISIE', 10000); - $avis_de_paul = Class_AvisNotice::newInstanceWithId(23,['entete'=>'Tres Bien', - 'note'=>'4', - 'user'=>Class_Users::newInstanceWithId(15,['login'=>'polo'])->beAbonneSIGB(), - 'avis'=>'de la balle', - 'date_avis'=>'15/03/2013', - 'clef_oeuvre'=>'potter', - 'abon_ou_bib'=>'0']) - ->setModerationOk(); + $paul = $this->fixture('Class_Users', + ['id' => 15, + 'login' => 'polo', + 'password' => 'secret']) + ->beAbonneSIGB(); - $avis_de_francois = Class_AvisNotice::newInstanceWithId(24,['entete'=>'Cool', - 'note'=>'4', - 'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(), - 'avis'=>'tres bien', - 'date_avis'=>'16/02/2013', - 'clef_oeuvre'=>'potter', - 'abon_ou_bib'=>'1']) + $avis_de_paul = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'Tres Bien', + 'note' => '4', + 'user' => $paul, + 'avis' => 'de la balle', + 'date_avis' => '15/03/2013', + 'clef_oeuvre' => 'potter', + 'abon_ou_bib' => '0', + 'statut' => 1, + ]); + + $avis_de_francois = Class_AvisNotice::newInstanceWithId(24, + ['entete'=>'Cool', + 'note'=>'4', + 'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(), + 'avis'=>'tres bien', + 'date_avis'=>'16/02/2013', + 'clef_oeuvre'=>'potter', + 'abon_ou_bib'=>'1']) ->setModerationOk(); - Class_Notice::newInstanceWithId(34,['titre_principal'=>'Potter', - 'clef_oeuvre'=>'potter', - 'avis' => [$avis_de_paul, $avis_de_francois]]); + Class_Notice::newInstanceWithId(34, + ['titre_principal'=>'Potter', + 'clef_oeuvre'=>'potter', + 'avis' => [$avis_de_paul, + $avis_de_francois]]); } } -class NoticeAjaxControllerNoticeWithAvisEditLinkNotLoggedTest extends NoticeAjaxControllerNoticeWithAvisTestCase { +class NoticeAjaxControllerNoticeWithAvisEditLinkNotLoggedTest + extends NoticeAjaxControllerNoticeWithAvisTestCase { /** * parent::_login setup an admin account by default -> do not log at all in this test */ protected function _login() {} + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); + } + + /** @test */ public function editLinkShouldNotBePresent() { - $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); $this->assertNotXPath('//a[contains(@href, "abonne/editavisnotice")]'); } } +/** @see http://forge.afi-sa.fr/issues/64605 */ +class NoticeAjaxControllerNoticeWithAvisWithModerationAndAuthorLostNotLoggedTest + extends AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + /** + * parent::_login setup an admin account by default -> do not log at all in this test + */ + protected function _login() {} + + public function setup() { + parent::setup(); + + Class_AdminVar::set('AVIS_BIB_SEULEMENT', 0); + Class_AdminVar::set('AVIS_MIN_SAISIE', 1); + Class_AdminVar::set('AVIS_MAX_SAISIE', 10000); + Class_AdminVar::set('MODO_AVIS', 1); + + $avis_orphelin = $this->fixture('Class_AvisNotice', + ['id' => 23, + 'entete' => 'Tres Bien', + 'note' => '4', + 'id_user' => 24, + 'avis' => 'de la balle', + 'date_avis' => '15/03/2013', + 'clef_oeuvre' => 'potter', + 'abon_ou_bib' => '0', + 'statut' => 0, + ]); + + Class_Notice::newInstanceWithId(34, + ['titre_principal'=>'Potter', + 'clef_oeuvre'=>'potter', + 'avis' => [$avis_orphelin]]); + + $this->dispatch('/opac/noticeajax/avis/id_notice/34/page/0/onglet/bloc', true); + } + + + /** @test */ + public function notValidatedShouldNotBePresent() { + $this->assertNotXPathContentContains('//a[contains(@href, "/viewavis/")][contains(@href, "/id/23")]', + 'Tres Bien', + $this->_response->getBody()); + } +} + + class NoticeAjaxControllerNoticeWithAvisEditLinkGuestLoggedTest extends NoticeAjaxControllerNoticeWithAvisTestCase { protected function _loginHook($account) { -- GitLab