From 6ad9b852304fc1359453d9907d5f5d31f35b84cc Mon Sep 17 00:00:00 2001 From: Matthias Meusburger <matthias.meusburger@biblibre.com> Date: Wed, 30 Sep 2015 17:34:54 +0200 Subject: [PATCH] hotline #23808 : Fix and add tests. --- library/Class/AvisNotice.php | 4 +- .../ProfilOptionsControllerTest.php | 2 +- tests/library/Class/AvisNoticeTest.php | 84 ++++++++++--------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/library/Class/AvisNotice.php b/library/Class/AvisNotice.php index af516d044ec..7a002534f4b 100644 --- a/library/Class/AvisNotice.php +++ b/library/Class/AvisNotice.php @@ -198,7 +198,6 @@ class Class_AvisNotice extends Storm_Model_Abstract { * oeuvre à été mis à jour dans le SIGB, essaye de retrouver la notice et réaffecte l'avis */ public function findNoticesByClefOeuvre() { - if ($notices = Class_Notice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()])) return $notices; @@ -213,10 +212,9 @@ class Class_AvisNotice extends Storm_Model_Abstract { $this ->setClefOeuvre($clef_oeuvre) - ->setModerationNOK() ->save(); } - + $this->_notices=$notices; return $notices; } diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index 2bc1c704ac2..b790369443e 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -31,7 +31,7 @@ abstract class ProfilOptionsControllerWithProfilAdulteTestCase extends AbstractC parent::setUp(); Class_Loan_Pnb::beVolatile(); - Class_AvisNotice::beVolatile(); + $this->fixture('Class_AdminVar',['id'=>'MENU_BOITE', 'valeur' => 1]); Class_Systeme_ModulesMenu::reset(); $this->admin_var=$this->fixture('Class_AdminVar',['id' => 'FORMATIONS', diff --git a/tests/library/Class/AvisNoticeTest.php b/tests/library/Class/AvisNoticeTest.php index 07fe72d3418..78ae7c8d2fc 100644 --- a/tests/library/Class/AvisNoticeTest.php +++ b/tests/library/Class/AvisNoticeTest.php @@ -370,36 +370,31 @@ class NoticeTestHasManyAvisTest extends Storm_Test_ModelTestCase { $this->millenium = Class_Notice::newInstanceWithId(34, ['clef_oeuvre' => 'MILLENIUM--LARSSON']); $this->steve = Class_Users::newInstanceWithId(5, ['prenom' => 'Steve']); - $this->avis_millenium_steve = Class_AvisNotice::newInstanceWithId(12, - ['user' => $this->steve, - 'entete' => 'ça fait peur', - 'avis' => "c'est glauque", - 'clef_oeuvre' => 'MILLENIUM--LARSSON', - 'note' => 2]); - - $this->bryan = Class_Users::newInstanceWithId(6, ['prenom' => 'Bryan']); - $this->avis_millenium_lost_bryan = Class_AvisNotice::newInstanceWithId(15, - ['user' => $this->bryan, - 'entete' => 'perdu', - 'avis' => "perdu sniff sniff", - 'clef_oeuvre' => 'MILLENIUM--SLARSSON', - 'note' => 5]); - - - $this->avis_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice'); - $this->avis_loader->whenCalled('save')->answers(true); + $this->avis_millenium_steve = $this->fixture('Class_AvisNotice', ['id' => 12, + 'user' => $this->steve, + 'entete' => 'ça fait peur', + 'avis' => "c'est glauque", + 'clef_oeuvre' => 'MILLENIUM--LARSSON', + 'note' => 2]); + + $this->bryan = $this->fixture('Class_Users' , ['id' =>6, 'login' => 'bryan', 'password' => 'toto', 'prenom' => 'Bryan']); + $this->avis_millenium_lost_bryan = $this->fixture('Class_AvisNotice', ['id' =>15, + 'user' => $this->bryan, + 'entete' => 'perdu', + 'avis' => "perdu sniff sniff", + 'clef_oeuvre' => 'MILLENIUM--SLARSSON', + 'note' => 5]); + + + //$this->avis_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice'); + // $this->avis_loader->whenCalled('save')->answers(true); $this->notice_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice'); + } /** @test */ public function noticeMilleniumGetAvisForUserSteveShouldReturnAvisSteve() { - $this->avis_loader - ->whenCalled('findAllBy') - ->with(['clef_oeuvre' => 'MILLENIUM--LARSSON', - 'id_user' => 5]) - ->answers([$this->avis_millenium_steve]); - $found_avis = $this->millenium->getAvisByUser($this->steve); $this->assertEquals([$this->avis_millenium_steve], $found_avis); @@ -408,28 +403,21 @@ class NoticeTestHasManyAvisTest extends Storm_Test_ModelTestCase { /** @test */ public function noticeMilleniumGetAvisShouldReturnAllAvisOnClefOeuvre() { - $avis_millenium_robert = new Class_AvisNotice(); - - $this->avis_loader - ->whenCalled('findAllBy') - ->with(['clef_oeuvre' => 'MILLENIUM--LARSSON']) - ->answers([$this->avis_millenium_steve, - $avis_millenium_robert]); - $found_avis = $this->millenium->getAvis(); - $this->assertEquals([$this->avis_millenium_steve, - $avis_millenium_robert], + $this->assertEquals([$this->avis_millenium_steve + ], $found_avis); } + /** @test */ public function avisMilleniumSteveGetNoticesShouldReturnNoticeMillenium() { $this->notice_loader ->whenCalled('findAllBy') ->with(['clef_oeuvre' => 'MILLENIUM--LARSSON']) ->answers([$this->millenium]); - + $this->avis_millenium_steve->findNoticesByClefOeuvre(); $notices_found = $this->avis_millenium_steve->getNotices(); $this->assertEquals(array($this->millenium), $notices_found); @@ -447,13 +435,23 @@ class NoticeTestHasManyAvisTest extends Storm_Test_ModelTestCase { ->with(['where' => 'clef_oeuvre like "MILLENIUM-%"']) ->answers([$this->millenium]) ->beStrict(); - + $this->avis_millenium_lost_bryan->setStatut(1); + $this->avis_millenium_lost_bryan->findNoticesByClefOeuvre(); $this->assertEquals([$this->millenium], $this->avis_millenium_lost_bryan->getNotices()); - return $this->avis_loader->getFirstAttributeForLastCallOn('save'); + return $this->avis_millenium_lost_bryan; + } + + /** + * @test + * @depends lostAvisMilleniumGetNoticesShouldSearchNoticeOnTitleClefOeuvre + */ + public function ModerationShouldNotBeReset($saved_avis) { + $this->assertEquals(1, $saved_avis->getStatut()); } + /** * @test * @depends lostAvisMilleniumGetNoticesShouldSearchNoticeOnTitleClefOeuvre @@ -811,10 +809,6 @@ class AvisVisibilityTest extends ModelTestCase { } -class AvisNoticeReattachReviewsTest extends NoticeTestHasManyAvisTest { - -} - class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); @@ -867,9 +861,11 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], + 'flags' => '0', 'where' => '(STATUT=1 OR ABON_OU_BIB=1) AND (STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_bib_moderated, $this->_avis_abon_moderated]); + $this->assertEquals([$this->_avis_bib_moderated, $this->_avis_abon_moderated], Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1])); } @@ -882,6 +878,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], 'ABON_OU_BIB' => 0, + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=1) AND (STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_abon_moderated]); @@ -897,6 +894,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], 'ABON_OU_BIB' => 1, + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=1) AND (STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_bib_moderated]); @@ -914,6 +912,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], 'ABON_OU_BIB' => 0, + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_abon_moderated, $this->_avis_abon_not_moderated]); @@ -931,6 +930,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_bib_moderated, $this->_avis_abon_moderated, $this->_avis_abon_not_moderated]); @@ -950,6 +950,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=1)']) ->answers([$this->_avis_bib_moderated, $this->_avis_bib_not_moderated, $this->_avis_abon_moderated]); @@ -973,6 +974,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice') ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', + 'flags' => 0, 'id_notice' => -1]) ->answers([$this->_avis_bib_moderated, $this->_avis_bib_not_moderated, $this->_avis_abon_moderated]); -- GitLab