Skip to content
Snippets Groups Projects
Commit f2dd2247 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline_#23975_cut_rating_comments' into 'stable'

Hotline #23975 cut rating comments

See merge request !993
parents 0ec01f5b 539a4d84
2 merge requests!999Master,!998Stable
- ticket #23975 : correction de la prise en compte du paramètre 'nombre de mots' des boîtes de critiques.
\ No newline at end of file
...@@ -256,8 +256,7 @@ class RssController extends Zend_Controller_Action ...@@ -256,8 +256,7 @@ class RssController extends Zend_Controller_Action
public function critiquesAction() { public function critiquesAction() {
$id_profil = $this->_getParam('id_profil'); $profil = Class_Profil::find($this->_getParam('id_profil'));
$profil = Class_Profil::find($id_profil);
$id_module = $this->_getParam('id_module'); $id_module = $this->_getParam('id_module');
$preferences = $profil->getModuleAccueilPreferences($id_module, 'CRITIQUES'); $preferences = $profil->getModuleAccueilPreferences($id_module, 'CRITIQUES');
$liste_avis = Class_AvisNotice::getAvisFromPreferences($preferences); $liste_avis = Class_AvisNotice::getAvisFromPreferences($preferences);
...@@ -277,10 +276,10 @@ class RssController extends Zend_Controller_Action ...@@ -277,10 +276,10 @@ class RssController extends Zend_Controller_Action
$desc = $avis_helper->avis($avis, 0, $vignette_link_to_avis = true); $desc = $avis_helper->avis($avis, 0, $vignette_link_to_avis = true);
$entry = array("titre" => $avis->getEntete(), $entry = ['titre' => $avis->getEntete(),
"lien" => $this->view->absoluteUrl('/blog/viewavis/id/'.$avis->getFirstNotice()->getId().'-'.$avis->getIdUser()), 'lien' => $this->view->absoluteUrl('/blog/viewavis/id/'.$avis->getFirstNotice()->getId().'-'.$avis->getIdUser()),
"desc" => '<![CDATA['.$this->filtreNews($desc).']]>'); 'desc' => '<![CDATA['.$this->filtreNews($desc).']]>'];
$data_rss["items"][] = $entry; $data_rss['items'][] = $entry;
} }
$this->getHelper('ViewRenderer')->setNoRender(); $this->getHelper('ViewRenderer')->setNoRender();
...@@ -330,13 +329,11 @@ class RssController extends Zend_Controller_Action ...@@ -330,13 +329,11 @@ class RssController extends Zend_Controller_Action
} }
protected function filtreNews($contenu_news) {
function filtreNews($contenu_news)
{
$contenu = preg_replace('/ src="/',' src="http://'.$_SERVER['SERVER_NAME'].'/',$contenu_news); $contenu = preg_replace('/ src="/',' src="http://'.$_SERVER['SERVER_NAME'].'/',$contenu_news);
$contenu = preg_replace('/ src=\'\//',' src=\'http://'.$_SERVER['SERVER_NAME'].'/',$contenu_news); $contenu = preg_replace('/ src=\'\//',' src=\'http://'.$_SERVER['SERVER_NAME'].'/',$contenu_news);
$contenu = preg_replace('^{FIN}^','',$contenu); $contenu = preg_replace('^{FIN}^','',$contenu);
return($contenu); return $contenu;
} }
......
...@@ -716,7 +716,6 @@ class Class_AdminVar extends Storm_Model_Abstract { ...@@ -716,7 +716,6 @@ class Class_AdminVar extends Storm_Model_Abstract {
public function validate() { public function validate() {
xdebug_break();
$this->getMeta()->validate($this); $this->getMeta()->validate($this);
} }
......
...@@ -116,7 +116,7 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper { ...@@ -116,7 +116,7 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
public function contenu_avis($avis) { public function contenu_avis($avis) {
$url_avis = $this->_getUrlAvis($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']; $text_avis = $format_text_avis['text_avis'];
$lire_la_suite = ''; $lire_la_suite = '';
...@@ -283,35 +283,21 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper { ...@@ -283,35 +283,21 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
} }
protected function _formatTextAvis($avis) { protected function _formatWithTruncate($avis) {
return $avis->getAbonOuBib() ? if ($this->_limit_nb_word == 0)
$this->_formatAdminText($avis) : return $this->_avisContentAsArray($avis);
$this->_formatWithTruncate($this->view->escape($avis->getAvis()));
}
protected function _formatAdminText($avis) {
$value = $avis->getAvis();
if ($this->_is_html($value) && $this->_limit_nb_word) {
$value = str_replace(['<br>', '<br/>', '<br />'], "\n", $value);
return $this->_formatWithTruncate(strip_tags($value));
}
return ['text_avis' => nl2br($value), 'lire_la_suite' => false];
}
$avis_for_truncate = $this->view->escape(strip_tags(str_replace(['<br>', '<br/>', '<br />'], "\n", $avis)));
protected function _formatWithTruncate($txt_avis) { if(count($words = explode(' ', $avis_for_truncate)) <= $this->_limit_nb_word)
if (($this->_limit_nb_word <= 0) return $this->_avisContentAsArray($avis_for_truncate);
|| 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 $this->_avisContentAsArray(implode(' ', array_slice($words, 0, $this->_limit_nb_word)) . ' [...]', true);
return ['text_avis' => nl2br($txt_avis) . ' [...]', 'lire_la_suite' => true];
} }
protected function _is_html($value) { protected function _avisContentAsArray($content, $read_link = false) {
return preg_match('/<[^<]+>/', $value); return ['text_avis' => nl2br($content),
'lire_la_suite' => $read_link];
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software * along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
class ZendAfi_View_Helper_RenderRss extends Zend_View_Helper_Abstract { class ZendAfi_View_Helper_RenderRss extends Zend_View_Helper_Abstract {
public function renderRss($data) { public function renderRss($data) {
...@@ -64,7 +64,8 @@ class ZendAfi_View_Helper_RenderRss extends Zend_View_Helper_Abstract { ...@@ -64,7 +64,8 @@ class ZendAfi_View_Helper_RenderRss extends Zend_View_Helper_Abstract {
$media_contents = []; $media_contents = [];
if (preg_match('/<img/', $description)) { if (preg_match('/<img/', $description)) {
$description = preg_replace('/<!\[CDATA\[(.*)\]\]>/s', '$1', $description); $description = trim(preg_replace('/<!\[CDATA\[(.*)\]\]>/s', '$1', $description));
$description = trim(preg_replace('/<p>(.*)\<\/p>/s', '$1', $description));
$doc = new DOMDocument(); $doc = new DOMDocument();
$doc->loadHTML($description); $doc->loadHTML($description);
$imgs = $doc->getElementsByTagName('img'); $imgs = $doc->getElementsByTagName('img');
......
...@@ -56,7 +56,7 @@ abstract class AbonneControllerAvisTestCase extends AbonneFlorenceIsLoggedContro ...@@ -56,7 +56,7 @@ abstract class AbonneControllerAvisTestCase extends AbonneFlorenceIsLoggedContro
parent::setUp(); parent::setUp();
$this->potter = Class_Notice::newInstanceWithId(53, $this->potter = Class_Notice::newInstanceWithId(53,
['clef_oeuvre' =>'POTTER']); ['clef_oeuvre' =>'POTTER']);
$this->potter->save(); $this->potter->save();
} }
} }
...@@ -124,8 +124,8 @@ class AbonneControllerAvisInvalidNoticeAvisSaveTest extends AbonneControllerAvi ...@@ -124,8 +124,8 @@ class AbonneControllerAvisInvalidNoticeAvisSaveTest extends AbonneControllerAvi
'avisSignature' => 'FloCouv']; 'avisSignature' => 'FloCouv'];
$this->xpath = new Storm_Test_XPath(); $this->xpath = new Storm_Test_XPath();
$this->getRequest() $this->getRequest()
->setMethod('POST') ->setMethod('POST')
->setPost($data); ->setPost($data);
$this->dispatch('/opac/abonne/avis/id_notice/53'); $this->dispatch('/opac/abonne/avis/id_notice/53');
$this->json = json_decode($this->_response->getbody()); $this->json = json_decode($this->_response->getbody());
$this->assertController('abonne'); $this->assertController('abonne');
...@@ -142,8 +142,8 @@ class AbonneControllerAvisInvalidNoticeAvisSaveTest extends AbonneControllerAvi ...@@ -142,8 +142,8 @@ class AbonneControllerAvisInvalidNoticeAvisSaveTest extends AbonneControllerAvi
'avisSignature' => ''); 'avisSignature' => '');
$this->xpath = new Storm_Test_XPath(); $this->xpath = new Storm_Test_XPath();
$this->getRequest() $this->getRequest()
->setMethod('POST') ->setMethod('POST')
->setPost($data); ->setPost($data);
$this->dispatch('/opac/abonne/avis/id_notice/53'); $this->dispatch('/opac/abonne/avis/id_notice/53');
$this->json = json_decode($this->_response->getbody()); $this->json = json_decode($this->_response->getbody());
$this->assertController('abonne'); $this->assertController('abonne');
...@@ -172,13 +172,13 @@ class AbonneControllerAvisNoticeAvisSaveTest extends AbonneControllerAvisTestCa ...@@ -172,13 +172,13 @@ class AbonneControllerAvisNoticeAvisSaveTest extends AbonneControllerAvisTestCa
public function postAndAssertAvisIsSaved($expected_avis) { public function postAndAssertAvisIsSaved($expected_avis) {
$data = ['avisEntete' => 'Sorcellerie', $data = ['avisEntete' => 'Sorcellerie',
'avisTexte' => 'On adore la magie', 'avisTexte' => 'On adore la magie',
'avisNote' => 5, 'avisNote' => 5,
'avisSignature' => 'FloCouv']; 'avisSignature' => 'FloCouv'];
$this->getRequest() $this->getRequest()
->setMethod('POST') ->setMethod('POST')
->setPost($data); ->setPost($data);
$this->dispatch('/opac/abonne/avis/id_notice/53'); $this->dispatch('/opac/abonne/avis/id_notice/53');
$this->assertEquals('FloCouv', $this->florence->getPseudo()); $this->assertEquals('FloCouv', $this->florence->getPseudo());
...@@ -277,29 +277,29 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon ...@@ -277,29 +277,29 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon
'auteur_principal' => 'Stieg Larsson', 'auteur_principal' => 'Stieg Larsson',
'url_vignette' => '', 'url_vignette' => '',
'url_image' => '' 'url_image' => ''
] ]
); );
$this->millenium->save(); $this->millenium->save();
$this->millenium_with_vignette = Class_Notice::newInstanceWithId(817, ['titre_principal' => 'Millenium', $this->millenium_with_vignette = Class_Notice::newInstanceWithId(817, ['titre_principal' => 'Millenium',
'clef_alpha' => 'MILLENIUM', 'clef_alpha' => 'MILLENIUM',
'auteur_principal' => 'Stieg Larsson', 'auteur_principal' => 'Stieg Larsson',
'url_vignette' => 'http://amazon.com/vignette_millenium.png' 'url_vignette' => 'http://amazon.com/vignette_millenium.png'
] ]
); );
$this->millenium_with_vignette->save(); $this->millenium_with_vignette->save();
$this->avis_millenium = Class_AvisNotice::newInstanceWithId(13, [ $this->avis_millenium = Class_AvisNotice::newInstanceWithId(13, [
'entete' => "J'adore", 'entete' => "J'adore",
'avis' => "Suspense intense", 'avis' => '<div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul></div>',
'note' => 5, 'note' => 5,
'date_avis' => '2011-03-18 13:00:00', 'date_avis' => '2011-03-18 13:00:00',
'user' => $this->florence, 'user' => $this->florence,
'statut' => 0, 'statut' => 0,
'abon_ou_bib'=>1 , 'abon_ou_bib'=>1 ,
'notices' => [$this->millenium, 'notices' => [$this->millenium,
$this->millenium_with_vignette] ]); $this->millenium_with_vignette] ]);
$this->avis_millenium->save(); $this->avis_millenium->save();
$this->potter = Class_Notice::newInstance(); $this->potter = Class_Notice::newInstance();
...@@ -324,10 +324,10 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon ...@@ -324,10 +324,10 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon
['entete' =>"C'est perdu", ['entete' =>"C'est perdu",
'avis' =>"Plus de notice, ni d'utilisateur", 'avis' =>"Plus de notice, ni d'utilisateur",
'note' => 4, 'note' => 4,
'date_avis' => '2008-10-12 10:00:00', 'date_avis' => '2008-10-12 10:00:00',
'user'=>null, 'user'=>null,
'statut' => 1, 'statut' => 1,
'abon_out_bib' => 1, 'abon_out_bib' => 1,
'notices' => []]); 'notices' => []]);
$this->avis_lost->save(); $this->avis_lost->save();
...@@ -446,6 +446,12 @@ class AbonneControllerAvisViewAvisActionTest extends AvisControllersFixturesTest ...@@ -446,6 +446,12 @@ class AbonneControllerAvisViewAvisActionTest extends AvisControllersFixturesTest
} }
/** @test */
public function allAvisContentShouldBeDisplay() {
$this->assertContains('<p><div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul></div></p>', $this->_response->getBody());
}
public function testDeleteMilleniumButtonPresent() { public function testDeleteMilleniumButtonPresent() {
$this->assertXPath("//a[contains(@href, '/abonne/delavisnotice/id/13')]"); $this->assertXPath("//a[contains(@href, '/abonne/delavisnotice/id/13')]");
} }
...@@ -573,26 +579,29 @@ class AbonneControllerAvisBlogControllerDeleteAvisTest extends AvisControllersFi ...@@ -573,26 +579,29 @@ class AbonneControllerAvisBlogControllerDeleteAvisTest extends AvisControllersFi
class AbonneControllerAvisBlogControllerLastCritiquesTest extends AvisControllersFixturesTestCase { class AbonneControllerAvisBlogControllerLastCritiquesTest extends AvisControllersFixturesTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->dispatch('/opac/blog/lastcritique/nb/10');
}
public function testPageIsRendered() { $this->fixture('Class_AdminVar',
$this->assertController('blog'); ['id' => 'MODO_AVIS',
$this->assertAction('lastcritique'); 'VALEUR' => 1]);
$this->dispatch('/opac/blog/lastcritique/nb/10', true);
} }
public function testMilleniumIsHere() { /** @test */
public function milleniumRatingShouldBeTheFirst() {
$this->assertXPathContentContains("//div[@class='critique'][1]//h2", 'Millenium (Stieg Larsson)'); $this->assertXPathContentContains("//div[@class='critique'][1]//h2", 'Millenium (Stieg Larsson)');
} }
public function testPotterIsBeforeMillenium() { /** @test */
$this->assertXPathContentContains("//div[@class='critique'][2]//h2", 'Potter et la chambre des secrets',$this->_response->getBody()); public function potterShouldBeTheSecondRating() {
$this->assertXPathContentContains("//div[@class='critique'][2]//h2", 'Potter et la chambre des secrets', $this->_response->getBody());
} }
public function testAvisLostShouldDisplayOeuvreNonTrouvee() { /** @test */
public function lostRratingShouldBeAtThirdPlace() {
$this->assertXPathContentContains("//div[@class='critique'][3]//h2", 'Oeuvre non trouvée'); $this->assertXPathContentContains("//div[@class='critique'][3]//h2", 'Oeuvre non trouvée');
} }
} }
...@@ -611,11 +620,11 @@ abstract class ModuleSelectionCritiquesTestCase extends AvisControllersFixturesT ...@@ -611,11 +620,11 @@ abstract class ModuleSelectionCritiquesTestCase extends AvisControllersFixturesT
->setCfgAccueil($preferences); ->setCfgAccueil($preferences);
$this->_generateLoaderFor('Class_AvisNotice', array('getAvisFromPreferences')) $this->_generateLoaderFor('Class_AvisNotice', array('getAvisFromPreferences'))
->expects($this->once()) ->expects($this->once())
->method('getAvisFromPreferences') ->method('getAvisFromPreferences')
->will($this->returnValue([$this->avis_millenium, ->will($this->returnValue([$this->avis_millenium,
$this->avis_potter, $this->avis_potter,
$this->avis_lost])); $this->avis_lost]));
} }
} }
...@@ -659,18 +668,19 @@ class AbonneControllerAvisBlogControllerViewCritiquesWithoutModuleTest extends M ...@@ -659,18 +668,19 @@ class AbonneControllerAvisBlogControllerViewCritiquesWithoutModuleTest extends M
class AbonneControllerAvisRssControllerLastCritiquesTest extends ModuleSelectionCritiquesTestCase { class AbonneControllerAvisRssControllerLastCritiquesTest extends ModuleSelectionCritiquesTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->dispatch('/opac/rss/critiques/id_profil/2/id_module/3', true); $this->dispatch('/opac/rss/critiques/id_profil/2/id_module/3', true);
$this->body = $this->getResponse()->getBody();
} }
public function testMilleniumIsHere() {
$this->assertNotEquals(false, strpos($this->body, 'Millenium')); /** @test */
public function milleniumShouldBePresent() {
$this->assertContains('Millenium', $this->_response->getBody());
} }
public function testPotterIsHere() {
$this->assertNotEquals(false, strpos($this->body, 'Potter')); /** @test */
public function potterShouldBePresent() {
$this->assertContains('Potter', $this->_response->getBody());
} }
} }
......
...@@ -74,6 +74,12 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase { ...@@ -74,6 +74,12 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase {
'password' => 'il l\'a ?', 'password' => 'il l\'a ?',
'pseudo' => 'Lolo']); 'pseudo' => 'Lolo']);
$super_lolo = $this->fixture('Class_Users',
['id' => 999,
'login' => 'suplo',
'password' => 'cutcomments',
'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL]);
$millenium = $this->fixture('Class_Notice', $millenium = $this->fixture('Class_Notice',
['id' => 9867, ['id' => 9867,
'titre_principal' => 'Millenium (Stieg Larsson)', 'titre_principal' => 'Millenium (Stieg Larsson)',
...@@ -83,13 +89,33 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase { ...@@ -83,13 +89,33 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase {
$avis_millenium = $this->fixture('Class_AvisNotice', $avis_millenium = $this->fixture('Class_AvisNotice',
['id' => 23, ['id' => 23,
'entete' => 'J\'adore', 'entete' => 'J\'adore',
'avis' => 'Suspense intense', 'avis' => 'Suspense intense tout au long de ce livre',
'note' => 5, 'note' => 5,
'date_avis' => '2010-03-18 13:00:00', 'date_avis' => '2010-03-18 13:00:00',
'user' => $lolo, 'user' => $lolo,
'statut' => 1, 'statut' => 1,
'notices' => [$millenium]]); 'notices' => [$millenium]]);
$avis_millenium_from_suplo = $this->fixture('Class_AvisNotice',
['id' => 234,
'entete' => 'Excellent !',
'avis' => 'Tout au long de ce livre, le suspense est intense.',
'note' => 5,
'date_avis' => '2010-03-18 13:00:00',
'user' => $super_lolo,
'statut' => 1,
'notices' => [$millenium]]);
$avis_millenium_from_suplo_with_html = $this->fixture('Class_AvisNotice',
['id' => 2342,
'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,
'statut' => 1,
'notices' => [$millenium]]);
$avis_orphan = $this->fixture('Class_AvisNotice', $avis_orphan = $this->fixture('Class_AvisNotice',
['id' => 34, ['id' => 34,
'entete' => 'J\'ai oublié', 'entete' => 'J\'ai oublié',
...@@ -130,11 +156,33 @@ class CritiquesWithVignettesTest extends CritiquesAvisTestCase { ...@@ -130,11 +156,33 @@ class CritiquesWithVignettesTest extends CritiquesAvisTestCase {
'only_img' => 1, 'only_img' => 1,
'display_order' => 'Random', 'display_order' => 'Random',
'titre' => 'Livres préférés', 'titre' => 'Livres préférés',
'nb_aff_avis' => '3', 'nb_aff_avis' => 5,
'nb_words' => 20, 'nb_words' => 2,
'abon_ou_bib' => 'all',
'boite' => 'boite_de_la_division_droite']]; 'boite' => 'boite_de_la_division_droite']];
/** @test */
public function superLoloCommentShouldBeCutAfterToutAu() {
$this->assertXPathContentContains($this->html,
'//p', "Tout au [...]");
}
/** @test */
public function superLoloCommentWithHtmlShouldBeCutAfterTresBien() {
$this->assertXPathContentContains($this->html, '//p', '
Très bien [...]');
}
/** @test */
public function loloCommentShouldBeCutAfterSuspenceIntence() {
$this->assertXPathContentContains($this->html,
'//p', 'Suspense intense [...]');
}
/** @test */ /** @test */
public function milleniumShouldBePresent() { public function milleniumShouldBePresent() {
$this->assertQueryContentContains($this->html, 'div.critique h2', 'Millenium'); $this->assertQueryContentContains($this->html, 'div.critique h2', 'Millenium');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment