From 51b108ca70a2d4045c9d7834ca870fbb95f3ea10 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Tue, 7 Jul 2015 17:23:20 +0200 Subject: [PATCH] hotline #23975 fix avis --- library/ZendAfi/View/Helper/Avis.php | 26 ++++--- .../controllers/AbonneControllerAvisTest.php | 74 +++++++++---------- .../View/Helper/Accueil/CritiquesTest.php | 13 ++-- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/library/ZendAfi/View/Helper/Avis.php b/library/ZendAfi/View/Helper/Avis.php index 5a93253f3ed..762b4aa094d 100644 --- a/library/ZendAfi/View/Helper/Avis.php +++ b/library/ZendAfi/View/Helper/Avis.php @@ -116,7 +116,7 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper { public function contenu_avis($avis) { $url_avis = $this->_getUrlAvis($avis); - $format_text_avis = $this->_formatTextAvis($avis); + $format_text_avis = $this->_formatWithTruncate($avis->getAvis()); $text_avis = $format_text_avis['text_avis']; $lire_la_suite = ''; @@ -283,19 +283,21 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper { } - protected function _formatTextAvis($avis) { - return $this->_formatWithTruncate($this->view->escape(strip_tags(str_replace(['<br>', '<br/>', '<br />'], "\n", $avis->getAvis())))); - } + protected function _formatWithTruncate($avis) { + if ($this->_limit_nb_word == 0) + return $this->_avisContentAsArray($avis); + + $avis_for_truncate = $this->view->escape(strip_tags(str_replace(['<br>', '<br/>', '<br />'], "\n", $avis))); + if(count($words = explode(' ', $avis_for_truncate)) <= $this->_limit_nb_word) + return $this->_avisContentAsArray($avis_for_truncate); + + return $this->_avisContentAsArray(implode(' ', array_slice($words, 0, $this->_limit_nb_word)) . ' [...]', true); + } - protected function _formatWithTruncate($txt_avis) { - if (($this->_limit_nb_word <= 0) - || count($words = explode(' ', $txt_avis)) <= $this->_limit_nb_word) - return ['text_avis' => nl2br($txt_avis), - 'lire_la_suite' => false]; - $txt_avis = implode(' ', array_slice($words, 0, $this->_limit_nb_word)); - return ['text_avis' => nl2br($txt_avis) . ' [...]', - 'lire_la_suite' => true]; + protected function _avisContentAsArray($content, $read_link = false) { + return ['text_avis' => nl2br($content), + 'lire_la_suite' => $read_link]; } } \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php index 46ed05e796a..639717fc256 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php @@ -56,7 +56,7 @@ abstract class AbonneControllerAvisTestCase extends AbonneFlorenceIsLoggedContro parent::setUp(); $this->potter = Class_Notice::newInstanceWithId(53, - ['clef_oeuvre' =>'POTTER']); + ['clef_oeuvre' =>'POTTER']); $this->potter->save(); } } @@ -124,8 +124,8 @@ class AbonneControllerAvisInvalidNoticeAvisSaveTest extends AbonneControllerAvi 'avisSignature' => 'FloCouv']; $this->xpath = new Storm_Test_XPath(); $this->getRequest() - ->setMethod('POST') - ->setPost($data); + ->setMethod('POST') + ->setPost($data); $this->dispatch('/opac/abonne/avis/id_notice/53'); $this->json = json_decode($this->_response->getbody()); $this->assertController('abonne'); @@ -142,8 +142,8 @@ class AbonneControllerAvisInvalidNoticeAvisSaveTest extends AbonneControllerAvi 'avisSignature' => ''); $this->xpath = new Storm_Test_XPath(); $this->getRequest() - ->setMethod('POST') - ->setPost($data); + ->setMethod('POST') + ->setPost($data); $this->dispatch('/opac/abonne/avis/id_notice/53'); $this->json = json_decode($this->_response->getbody()); $this->assertController('abonne'); @@ -172,13 +172,13 @@ class AbonneControllerAvisNoticeAvisSaveTest extends AbonneControllerAvisTestCa public function postAndAssertAvisIsSaved($expected_avis) { $data = ['avisEntete' => 'Sorcellerie', - 'avisTexte' => 'On adore la magie', - 'avisNote' => 5, - 'avisSignature' => 'FloCouv']; + 'avisTexte' => 'On adore la magie', + 'avisNote' => 5, + 'avisSignature' => 'FloCouv']; $this->getRequest() - ->setMethod('POST') - ->setPost($data); + ->setMethod('POST') + ->setPost($data); $this->dispatch('/opac/abonne/avis/id_notice/53'); $this->assertEquals('FloCouv', $this->florence->getPseudo()); @@ -277,29 +277,29 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon 'auteur_principal' => 'Stieg Larsson', 'url_vignette' => '', 'url_image' => '' - ] - ); + ] + ); $this->millenium->save(); $this->millenium_with_vignette = Class_Notice::newInstanceWithId(817, ['titre_principal' => 'Millenium', - 'clef_alpha' => 'MILLENIUM', - 'auteur_principal' => 'Stieg Larsson', - 'url_vignette' => 'http://amazon.com/vignette_millenium.png' - ] - ); + 'clef_alpha' => 'MILLENIUM', + 'auteur_principal' => 'Stieg Larsson', + 'url_vignette' => 'http://amazon.com/vignette_millenium.png' + ] + ); $this->millenium_with_vignette->save(); $this->avis_millenium = Class_AvisNotice::newInstanceWithId(13, [ - 'entete' => "J'adore", - 'avis' => "<div><ul><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li><li>Suspense Instence !</li></ul><div>", - 'note' => 5, - 'date_avis' => '2011-03-18 13:00:00', - 'user' => $this->florence, - 'statut' => 0, - 'abon_ou_bib'=>1 , - 'notices' => [$this->millenium, - $this->millenium_with_vignette] ]); + 'entete' => "J'adore", + 'avis' => '<div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul><div>', + 'note' => 5, + 'date_avis' => '2011-03-18 13:00:00', + 'user' => $this->florence, + 'statut' => 0, + 'abon_ou_bib'=>1 , + 'notices' => [$this->millenium, + $this->millenium_with_vignette] ]); $this->avis_millenium->save(); $this->potter = Class_Notice::newInstance(); @@ -324,10 +324,10 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon ['entete' =>"C'est perdu", 'avis' =>"Plus de notice, ni d'utilisateur", 'note' => 4, - 'date_avis' => '2008-10-12 10:00:00', - 'user'=>null, - 'statut' => 1, - 'abon_out_bib' => 1, + 'date_avis' => '2008-10-12 10:00:00', + 'user'=>null, + 'statut' => 1, + 'abon_out_bib' => 1, 'notices' => []]); $this->avis_lost->save(); @@ -448,8 +448,8 @@ class AbonneControllerAvisViewAvisActionTest extends AvisControllersFixturesTest /** @test */ public function allAvisContentShouldBeDisplay() { - $this->assertXPathContentCOntains('//p', 'Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !Suspense Instence !'); - } + $this->assertContains('<p><div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul><div></p>', $this->_response->getBody()); + } public function testDeleteMilleniumButtonPresent() { @@ -617,11 +617,11 @@ abstract class ModuleSelectionCritiquesTestCase extends AvisControllersFixturesT ->setCfgAccueil($preferences); $this->_generateLoaderFor('Class_AvisNotice', array('getAvisFromPreferences')) - ->expects($this->once()) - ->method('getAvisFromPreferences') - ->will($this->returnValue([$this->avis_millenium, - $this->avis_potter, - $this->avis_lost])); + ->expects($this->once()) + ->method('getAvisFromPreferences') + ->will($this->returnValue([$this->avis_millenium, + $this->avis_potter, + $this->avis_lost])); } } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php index a83ac6a2d7c..c876001600f 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php @@ -108,8 +108,8 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase { $avis_millenium_from_suplo_with_html = $this->fixture('Class_AvisNotice', ['id' => 2342, - 'entete' => 'Excellent<br> !', - 'avis' => '<div class="should not be present"><br>Tout au long de ce livre<br>, le suspense est intense.</div>', + 'entete' => 'Excellent ce livre!', + 'avis' => '<div class="should not be present"><br>Très bien ce livre<br>, le suspense est intense.</div>', 'note' => 5, 'date_avis' => '2010-03-18 13:00:00', 'user' => $super_lolo, @@ -156,7 +156,7 @@ class CritiquesWithVignettesTest extends CritiquesAvisTestCase { 'only_img' => 1, 'display_order' => 'Random', 'titre' => 'Livres préférés', - 'nb_aff_avis' => 3, + 'nb_aff_avis' => 5, 'nb_words' => 2, 'abon_ou_bib' => 'all', 'boite' => 'boite_de_la_division_droite']]; @@ -170,10 +170,9 @@ class CritiquesWithVignettesTest extends CritiquesAvisTestCase { /** @test */ - public function superLoloCommentWithHtmlShouldBeCutAfterToutAu() { - $this->assertXPathContentContains($this->html, - '//p', ' -Tout au [...]'); + public function superLoloCommentWithHtmlShouldBeCutAfterTresBien() { + $this->assertXPathContentContains($this->html, '//p', ' +Très bien [...]'); } -- GitLab