diff --git a/VERSIONS_HOTLINE/153857 b/VERSIONS_HOTLINE/153857 new file mode 100644 index 0000000000000000000000000000000000000000..a82c3a62b90c3dd08d4c5b536be6430fe8eb1c57 --- /dev/null +++ b/VERSIONS_HOTLINE/153857 @@ -0,0 +1 @@ + - correctif #153857 : Lettres d'informations : Correction de la prise en charge du paramètre "nombre à afficher" dans l'onglets "notices". Désormais, la valeur 0 n'affiche plus de notice. \ No newline at end of file diff --git a/library/Class/Article/MailRenderer.php b/library/Class/Article/MailRenderer.php index ca891fe106b0800324290a08cec83e30a9596560..9646a5cf5cb3f68fb3fc4bf44c28cb8675b6f53d 100644 --- a/library/Class/Article/MailRenderer.php +++ b/library/Class/Article/MailRenderer.php @@ -23,23 +23,18 @@ class Class_Article_MailRenderer { use Trait_Translator; - public function renderTextInto($article, &$data) { - if (!$article) - return; - - $data[] = '- ' . $article->getLabel(); - $data[] = strip_tags($article->getFullContent()); - $data[] = $this->_('Lien: ') . Class_Url::absolute(['controller' => 'cms', - 'action' => 'viewarticle', - 'id' => $article->getId()], null, true); - $data[] = "\n"; + public function renderText(Class_Article $article) : string { + return '- ' . $article->getLabel() + . strip_tags($article->getFullContent()) + . $this->_('Lien: ') + . Class_Url::absolute(['controller' => 'cms', + 'action' => 'viewarticle', + 'id' => $article->getId()], null, true) + . "\n"; } - public function renderHtml($article) { - if (!$article) - return ''; - + public function renderHtml(Class_Article $article) : string { $transformer = new Class_CmsUrlTransformer(); return '<div style="padding:5px">' . diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 1f20cbae31e14935932e6300d700f364f9df92f6..d7cf3e35d013a4f1e1404c761a00f23f667c52af 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -137,7 +137,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $start= $nb_par_page * $numero_page; - $requete_ids = str_replace('LIMIT 5000', + $requete_ids = str_replace('LIMIT 0,5000', "limit ".$nb_par_page*$numero_page.','.$nb_par_page, $req['req_liste']); diff --git a/library/Class/Catalogue/Loader.php b/library/Class/Catalogue/Loader.php index 2c9fa5e516eecbf25b28fdb7bb6c7f695208063a..19ecbcd3c23f58b6b9d271729c9579888cd020cf 100644 --- a/library/Class/Catalogue/Loader.php +++ b/library/Class/Catalogue/Loader.php @@ -470,17 +470,21 @@ class Class_Catalogue_Loader extends Storm_Model_Loader { if ( $max_limited ) return ' LIMIT 5000'; - $start_limit = 0; - if (isset($preferences['start_limit'])) - $start_limit = (int) $preferences['start_limit']; - if ( isset($preferences["aleatoire"]) - && 1 == (int) $preferences["aleatoire"]) - return sprintf(' LIMIT %d,%d', $start_limit, (int) $preferences["nb_analyse"]); + $start_limit = (int) ($preferences['start_limit'] ?? 0); - if (isset($preferences['nb_notices']) && $preferences["nb_notices"]) - return sprintf(' LIMIT %d,%d', $start_limit, (int) $preferences["nb_notices"]); + $random = (int) ($preferences["aleatoire"] ?? 0); + $nb_analyse = (int) ($preferences["nb_analyse"] ?? 0); - return ' LIMIT 5000'; //LL: j'ai rajouté une limite max car explosion mémoire sur des catalogues mal définis + if ( 1 === $random) + return sprintf(' LIMIT %d,%d', + $start_limit, + $nb_analyse); + + $nb_notices = (int) ($preferences['nb_notices'] ?? 5000); + + return sprintf(' LIMIT %d,%d', + $start_limit, + $nb_notices); } diff --git a/library/Class/Newsletter.php b/library/Class/Newsletter.php index ac2142a831d13cb1c397e2b5ae7c6939136d43ef..6560eedbf1e172d488353b9b880796e2d4aa202b 100644 --- a/library/Class/Newsletter.php +++ b/library/Class/Newsletter.php @@ -82,7 +82,6 @@ class NewsletterLoader extends Storm_Model_Loader { class Class_Newsletter extends Storm_Model_Abstract { use Trait_TimeSource, Trait_Translator; - const URL_PLACEHOLDER = '{{URL}}'; protected $_table_name = 'newsletters'; protected $_loader_class = 'NewsletterLoader'; @@ -104,8 +103,6 @@ class Class_Newsletter extends Storm_Model_Abstract { 'user_groups' => ['through' => 'newsletter_group_subscriptions'], ]; - protected $_notices_finder; - protected $_recipent_size = 20; protected $_default_attribute_values = ['titre' => '', 'contenu' => '', 'draft' => 0, @@ -114,8 +111,26 @@ class Class_Newsletter extends Storm_Model_Abstract { 'articles_ids' => '', 'articles_categories_ids' => '', 'mail_subject' => '', + 'nb_notices' => 10, //patch_019.sql 'last_distribution_date' => '']; + protected + $_notices_finder, + $_recipent_size = 20, + $_template_helper_cache, + $_contenu_cache, + $_notices_cache = [], + $_articles_cache = []; + + + public function afterSave() { + $this->_contenu_cache = null; + $this->_template_helper_cache = null; + $this->_notices_cache = []; + $this->_articles_cache = []; + parent::afterSave(); + } + public function validate() { $this->checkAttribute('titre', @@ -169,19 +184,10 @@ class Class_Newsletter extends Storm_Model_Abstract { public function newTemplate() { - $template = new Class_Entity(); + if ( $this->_template_helper_cache) + return $this->_template_helper_cache; - $notices = $this->getNotices(); - $articles = $this->getArticles(); - - $template - ->setTitre($this->getTitre()) - ->setSubject($this->getMailSubject()) - ->setBodyText($this->_getBodyText($notices, $articles)) - ->setBodyHTML($this->_getBodyHTML($notices, $articles)) - ->setExpediteur($this->getExpediteur()); - - return $template; + return $this->_template_helper_cache = new Class_Newsletter_TemplateHelper($this); } @@ -262,8 +268,14 @@ class Class_Newsletter extends Storm_Model_Abstract { public function getNotices() { + if ( $this->_notices_cache) + return $this->_notices_cache; + + if ( 0 === ((int) ($nb_notices = $this->getNbNotices()))) + return $this->_notices_cache = []; + if (!$this->getIdPanier() and !$this->getIdCatalogue()) - return []; + return $this->_notices_cache = []; $preferences = ['id_catalogue' => $this->getIdCatalogue(), 'id_panier' => $this->getIdPanier(), @@ -272,21 +284,20 @@ class Class_Newsletter extends Storm_Model_Abstract { 'aleatoire' => 0, 'tri' => 1]; - return Class_Notice::getNoticesFromPreferences($preferences); + return $this->_notices_cache = Class_Notice::getNoticesFromPreferences($preferences); } public function getArticles() { - return $this->hasArticlesIds() || $this->hasArticlesCategoriesIds() - ? Class_Article::getArticlesByPreferences(['id_items' => $this->getArticlesIds(), - 'id_categorie' => $this->getArticlesCategoriesIds(), - 'display_order' => 'Selection']) - : []; - } + if ( $this->_articles_cache) + return $this->_articles_cache; - - protected function _htmlToText($html) { - return strip_tags(preg_replace('/<br[^>]*>/i', "\n", $html)); + return $this->_articles_cache = + ($this->hasArticlesIds() || $this->hasArticlesCategoriesIds() + ? Class_Article::getArticlesByPreferences(['id_items' => $this->getArticlesIds(), + 'id_categorie' => $this->getArticlesCategoriesIds(), + 'display_order' => 'Selection']) + : []); } @@ -299,65 +310,22 @@ class Class_Newsletter extends Storm_Model_Abstract { } - protected function _getUnsubscribeText() { - return str_replace(self::URL_PLACEHOLDER, $this->getUnsubscribeUrl(), - Class_AdminVar::getValueOrDefault('NEWSLETTER_UNSUBSCRIBE_TEXT')); - } - - - protected function _getUnsubscribeHTML() { - return '<br/><a href="' . $this->getUnsubscribeUrl() . '">' - . Class_AdminVar::getValueOrDefault('NEWSLETTER_UNSUBSCRIBE_HTML') - . '</a>'; - } - - - protected function _getBodyText($records, $articles) { - $lines = [$this->_htmlToText($this->getContenu())]; - - $renderer = new Class_Notice_MailRenderer(); - foreach($records as $record) - $renderer->renderTextInto($record, $lines); - - $renderer = new Class_Article_MailRenderer(); - foreach($articles as $article) - $renderer->renderTextInto($article, $lines); - - $lines[] = $this->_getUnsubscribeText(); - - return implode("\n", $lines); - } - /** * @return string */ public function getContenu() { - return (new Class_CmsUrlTransformer())->imgUrlRelativeToAbsolute(parent::getContenu()); - } + if ( $this->_contenu_cache) + return $this->_contenu_cache; + return $this->_contenu_cache = + (new Class_CmsUrlTransformer())->imgUrlRelativeToAbsolute(parent::getContenu()); + } - /** - * /!\ maybe in cli context : cannot rely on view helpers - * @see scripts/sendNewsletter.php - * - * @param array $records - * @return string - */ - protected function _getBodyHTML($records, $articles) { - $html = $this->getContenu(); - - $renderer = new Class_Notice_MailRenderer(); - foreach($records as $record) - $html .= $renderer->renderHtml($record); - - $renderer = new Class_Article_MailRenderer(); - foreach($articles as $article) - $html .= $renderer->renderHtml($article); - - $html .= $this->_getUnsubscribeHTML(); - return $html; + public function setContenu(string $contenu) : self { + $this->_contenu_cache = null; + return parent::setContenu($contenu); } @@ -476,7 +444,7 @@ class Class_Newsletter extends Storm_Model_Abstract { } - public function getFirstImageUrl() { + public function getFirstImageUrl() : string { $template = $this->newTemplate(); $text = $template->getBodyHTML(); diff --git a/library/Class/Newsletter/TemplateHelper.php b/library/Class/Newsletter/TemplateHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..0d6185198250cebe97844532ae0723311f897f51 --- /dev/null +++ b/library/Class/Newsletter/TemplateHelper.php @@ -0,0 +1,168 @@ +<?php +/** + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Newsletter_TemplateHelper { + + + const URL_PLACEHOLDER = '{{URL}}'; + + + protected Class_Newsletter $_newsletter; + protected string $_body_html_cache = ''; + protected string $_body_text_cache = ''; + protected string $_newsletter_contenu_cache = ''; + protected string $_newsletter_content_text_cache = ''; + protected array $_newsletter_articles_cache = []; + protected array $_newsletter_records_cache = []; + + + public function __construct(Class_Newsletter $newsletter) { + $this->_newsletter = $newsletter; + } + + + public function getTitre() : string { + return (string) $this->_newsletter->getTitle(); + } + + + public function getSubject() : string { + return (string) $this->_newsletter->getMailSubject(); + } + + + public function getExpediteur() : string { + return (string) $this->_newsletter->getExpediteur(); + } + + + public function getBodyText() : string { + if ( $this->_body_text_cache ) + return $this->_body_text_cache; + + return $this->_body_text_cache = + $this->_renderNewsletterWith('_getContentAsTEXT', + 'renderText', + '_getUnsubscribeText', + '_implodeWithNewLine'); + } + + + protected function _getContentAsTEXT() : string { + if ( $this->_newsletter_content_text_cache) + return $this->_newsletter_content_text_cache; + + return $this->_newsletter_content_text_cache = + $this->_htmlToText($this->_newsletter->getContenu()); + } + + + protected function _implodeWithNewLine(array $content) : string { + return implode("\n", $content); + } + + + /** + * /!\ maybe in cli context : cannot rely on view helpers + * @see scripts/sendNewsletter.php + */ + public function getBodyHTML() : string { + if ( $this->_body_html_cache ) + return $this->_body_html_cache; + + return $this->_body_html_cache = + $this->_renderNewsletterWith('_getContentAsHTML', + 'renderHtml', + '_getUnsubscribeHTML'); + } + + + protected function _renderNewsletterWith(string $mail_content_function, + string $mail_renderer_function, + string $unsubscribe_function, + string $implode_callback = '') : string { + $content = [call_user_func([$this, $mail_content_function])]; + $records = $this->_getRecords(); + $articles = $this->_getArticles(); + + + $renderer = new Class_Notice_MailRenderer; + foreach($records as $record) + $content [] = call_user_func([$renderer, $mail_renderer_function], $record); + + $renderer = new Class_Article_MailRenderer; + foreach($articles as $article) + $content [] = call_user_func([$renderer, $mail_renderer_function], $article); + + $content [] = call_user_func([$this, $unsubscribe_function]); + + return $implode_callback + ? call_user_func([$this, $implode_callback], $content) + : implode($content); + } + + + protected function _getContentAsHTML() : string { + if ( $this->_newsletter_contenu_cache) + return $this->_newsletter_contenu_cache; + + return $this->_newsletter_contenu_cache = + $this->_newsletter->getContenu(); + } + + + protected function _getRecords() : array { + if ( $this->_newsletter_records_cache) + return $this->_newsletter_records_cache; + + return $this->_newsletter_records_cache = + $this->_newsletter->getNotices(); + } + + + protected function _getArticles() : array { + if ( $this->_newsletter_articles_cache) + return $this->_newsletter_articles_cache; + + return $this->_newsletter_articles_cache = + $this->_newsletter->getArticles(); + } + + + protected function _getUnsubscribeText() : string { + return str_replace(self::URL_PLACEHOLDER, + $this->_newsletter->getUnsubscribeUrl(), + Class_AdminVar::getValueOrDefault('NEWSLETTER_UNSUBSCRIBE_TEXT')); + } + + + protected function _getUnsubscribeHTML() : string { + return '<br/><a href="' . $this->_newsletter->getUnsubscribeUrl() . '">' + . Class_AdminVar::getValueOrDefault('NEWSLETTER_UNSUBSCRIBE_HTML') + . '</a>'; + } + + + protected function _htmlToText(string $html) : string { + return strip_tags(preg_replace('/<br[^>]*>/i', "\n", $html)); + } +} diff --git a/library/Class/Notice/MailRenderer.php b/library/Class/Notice/MailRenderer.php index 0cef7cda15d8f52c5214bc8a315382df18f2495c..82cf0007e35cda4b95819943b780cb1fc52b4f6d 100644 --- a/library/Class/Notice/MailRenderer.php +++ b/library/Class/Notice/MailRenderer.php @@ -25,25 +25,18 @@ class Class_Notice_MailRenderer { protected $_record; - public function renderTextInto($record, &$data) { - if (!$record) - return; - - $data[] = '- ' . $this->_title($record); - $data[] = $record->getResume(); - $data[] = $this->_('Lien: ') . $this->_urlWithoutRouter($record); - $data[] = "\n"; - } - - public function renderText($record) { - $lines = []; - $this->renderTextInto($record, $lines); - return implode("\n", $lines); + public function renderText(Class_Notice $record) : string { + return + implode("\n", + ['- ' . $this->_title($record), + $record->getResume(), + $this->_('Lien: ') . $this->_urlWithoutRouter($record), + "\n"]); } - public function renderHtml($record) { + public function renderHtml(Class_Notice $record) : string { $title = $this->_title($record); $anchor = '<a href="' . $this->_urlWithoutRouter($record) . '">' @@ -57,15 +50,17 @@ class Class_Notice_MailRenderer { } - protected function _title($record) { + protected function _title(Class_Notice $record) : string { return $record->getTitrePrincipal() . $this->_infos($record); } - protected function _infos($record) { + protected function _infos(Class_Notice $record) : string { $infos = []; + if ($auteur = $record->getAuteurPrincipal()) $infos[] = $auteur; + if ($annee = $record->getAnnee()) $infos[] = $annee; @@ -75,12 +70,12 @@ class Class_Notice_MailRenderer { } - protected function _urlWithoutRouter($record) { + protected function _urlWithoutRouter(Class_Notice $record) : string { return (new Class_Notice_Permalink())->absoluteFor($record, null, true); } - protected function _thumbWithoutRouter($record) { + protected function _thumbWithoutRouter(Class_Notice $record) : string { return $record->hasVignette() ? '<img src="' . $record->getUrlVignette() . '" style="float:left;width:50px;vertical-align:top;padding:5px" alt="" />' : ''; diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php index 81e49d0e32d8b19ebd39ddc93b69282fd1032fcd..2404792a93927bc3a80a89ab05b908677e28e3c8 100644 --- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php +++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php @@ -299,7 +299,7 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba $this->_nombre_notices_par_page = $this->preferences['nb_notices']; $nombre_total_notices = 0; - $this->preferences['nb_notices'] = 0; + $this->preferences['nb_notices'] = null; $requetes = Class_Catalogue::getRequetes($this->preferences, ['id_notice']); $notices = []; diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php index 4998f22e17b6e79ceb9f6c5fa7b97161457339cd..d567bf90ab44e763c8e9942711b224ba25f6fe99 100644 --- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php +++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php @@ -1888,7 +1888,7 @@ class CatalogueControllerActionTesterWithResultsPageTwoTest extends CatalogueCon $this->_mock_sql ->whenCalled('fetchAllByColumn') - ->with('select notices.id_notice ' . $clauses . ' order by alpha_titre LIMIT 5000') + ->with('select notices.id_notice ' . $clauses . ' order by alpha_titre LIMIT 0,5000') ->answers(range(1, 22)) ->whenCalled('fetchOne') @@ -1914,7 +1914,7 @@ class CatalogueControllerActionTesterWithResultsPageTwoTest extends CatalogueCon 'url_vignette' => 'http://image.org/miles.jpg']); - $this->dispatch('admin/catalogue/tester/id_catalogue/6/page/2', true); + $this->dispatch('admin/catalogue/tester/id_catalogue/6/page/2'); } @@ -1999,7 +1999,7 @@ class CatalogueControllerSystemeControllerMakeCacheActionTesterWithResultsTest 'auteur_principal' => 'miles', 'url_vignette' => '']); - $this->_sql_query = 'select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\' +(B1) +( D78308*)\' IN BOOLEAN MODE) and notices.type_doc IN (\'1\', \'3\') and annee >= \'2012\' and annee <= \'2012\' and url_vignette=\'\') and type=1 order by alpha_titre LIMIT 5000'; + $this->_sql_query = 'select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\' +(B1) +( D78308*)\' IN BOOLEAN MODE) and notices.type_doc IN (\'1\', \'3\') and annee >= \'2012\' and annee <= \'2012\' and url_vignette=\'\') and type=1 order by alpha_titre LIMIT 0,5000'; $this->_mock_sql ->whenCalled('fetchAllByColumn') diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index 81cc00d08014b0ba6d2612ca21eed2bad3e6df66..fe7ccc79d0a6ddc65e642f28eaf38f78ac41f7ba 100644 --- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php +++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php @@ -924,7 +924,6 @@ abstract class Admin_NewsletterControllerPreviewActionTestCase 'mail_subject' => 'Nouveautés', 'contenu' => 'Notre sélection du mois<img src="zork.jpg"/> <b>Hoho</b>', 'id_catalogue' => 1, - 'nb_notices' => 0, 'id_panier' => null, 'articles_categories_ids' => '99-89', 'articles_ids' => '13-12', @@ -951,7 +950,7 @@ class Admin_NewsletterControllerPreviewActionWithArticlesSelectionTest public function setUp() { parent::setUp(); - $this->dispatch('/admin/newsletter/preview/id/3', true); + $this->dispatch('/admin/newsletter/preview/id/3'); } @@ -985,14 +984,13 @@ class Admin_NewsletterControllerPreviewActionWithArticlesSelectionTest /** @test */ public function martineALaPlageShouldBePresent() { - $this->assertQueryContentContains('p', 'Martine à la plage', $this->_response->getBody()); + $this->assertXPathContentContains('//p', 'Martine à la plage'); } /** @test */ public function noticeMartineALaPlageUrlShouldBeRechercheViewNotice42() { - $this->assertXPath('//a[contains(@href,"/recherche/viewnotice/clef//id/42")]', - $this->_response->getBody()); + $this->assertXPath('//a[contains(@href,"/recherche/viewnotice/clef//id/42")]'); } diff --git a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php index d2a76b184a2762760b96bba1c20bc5cb23844ad3..4b678a688d57669c23b44096fcc22efd30ae80a1 100644 --- a/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php +++ b/tests/application/modules/admin/controllers/SystemeControllerWebServicesTest.php @@ -64,9 +64,10 @@ class SystemeControllerWebServicesActionTest extends Admin_AbstractControllerTes */ public function webServicePremiereGetResumeShouldWork() { Class_AdminVar::set('WEBSERVICE_TEST', 1); - $this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1', true); + $this->dispatch('/admin/systeme/webservices/id_service/Premiere/id_fonction/1'); $this->assertXPathContentContains('//pre[@class="resultat"]', - 'Jake Sully est un ancien marine', $this->_response->getBody()); + 'Jake Sully est un ancien marine', + $this->_response->getBody()); } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/UrlManagerControllerTest.php b/tests/application/modules/admin/controllers/UrlManagerControllerTest.php index 5d36844deae5e746106bb66e2776b36f1ed58a44..ea40b5dfd12fd9749b943455995994d22cae98af 100644 --- a/tests/application/modules/admin/controllers/UrlManagerControllerTest.php +++ b/tests/application/modules/admin/controllers/UrlManagerControllerTest.php @@ -169,7 +169,7 @@ class UrlManagerControllerUpdateUrlInModelsActionTest extends UrlManagerTestCase parent::setUp(); $this->dispatch(sprintf('/admin/url-manager/update-url-in-models/url/%s/by/%s', urlencode('http://mon-domain.org'), - urlencode('https://mon-domain.org')), true); + urlencode('https://mon-domain.org'))); } diff --git a/tests/application/modules/opac/controllers/JavaControllerTest.php b/tests/application/modules/opac/controllers/JavaControllerTest.php index ab8913b24c5479e66a0f5733f24f10b8e2eca33c..f10ea1d9c75b128c3ac0fc3801d44f632dc2613c 100644 --- a/tests/application/modules/opac/controllers/JavaControllerTest.php +++ b/tests/application/modules/opac/controllers/JavaControllerTest.php @@ -138,16 +138,17 @@ class JavaControllerCarrouselHorizontalWithoutIdModuleTest class JavaControllerWithKiosqueMurPageTest extends AbstractControllerTestCase { + public function setUp() { parent::setUp(); $cfg_accueil = ['modules' => ['1' => ['division' => 1, 'type_module' => 'KIOSQUE', - 'preferences' => ['style_liste' => 'mur', - 'nb_notices' => 10, - 'nb_analyse' => 50, - 'aleatoire' => 0, - 'only_img' => 0]]]]; + 'preferences' => ['style_liste' => 'mur', + 'nb_notices' => 10, + 'nb_analyse' => 50, + 'aleatoire' => 0, + 'only_img' => 0]]]]; Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil); diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index 164a1344a5ec21a18efb84a0caf8135aa8d1348a..4e69e4fd57084b58662234bf290c765d5b6a2b9d 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -486,7 +486,7 @@ class CatalogueGetRequetesWithFacettesAndNoCatalogueTest extends ModelTestCase { /** @test */ public function requeteListeShouldEqualsSelectStarWhereFacettesFromNotices() { - $this->assertEquals('select * from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre LIMIT 5000', $this->_requetes['req_liste']); + $this->assertEquals('select * from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre LIMIT 0,5000', $this->_requetes['req_liste']); } @@ -498,7 +498,7 @@ class CatalogueGetRequetesWithFacettesAndNoCatalogueTest extends ModelTestCase { /** @test */ public function requeteFacettesShouldBeSelectIdNoticeTypeDocFacet() { - $this->assertEquals('select notices.id_notice, notices.type_doc, facettes from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 LIMIT 5000', $this->_requetes['req_facettes']); + $this->assertEquals('select notices.id_notice, notices.type_doc, facettes from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 LIMIT 0,5000', $this->_requetes['req_facettes']); } } @@ -1214,7 +1214,7 @@ class CatalogueWithNoveltyTest extends ModelTestCase { /** @test */ public function recordFacetsShouldContainsNoveltyForRoubaixAndNoveltyForLille() { - $this->assertSame('select * from notices Where (MATCH(facettes) AGAINST(\' +(B10 B11) +(YROUB YISTR) +(HNNNN0001 HNNNN0002 HNANA0001 HNANA0002)\' IN BOOLEAN MODE) and date_creation >= \'2016-05-11\') and type=1 order by alpha_titre LIMIT 5000', + $this->assertSame('select * from notices Where (MATCH(facettes) AGAINST(\' +(B10 B11) +(YROUB YISTR) +(HNNNN0001 HNNNN0002 HNANA0001 HNANA0002)\' IN BOOLEAN MODE) and date_creation >= \'2016-05-11\') and type=1 order by alpha_titre LIMIT 0,5000', $this->_domain_request['req_liste']); } } @@ -1280,3 +1280,28 @@ class CatalogueEmptyFacetTestCase extends ModelTestCase { Class_Catalogue::facetsClauseFor($catalogue)); } } + + + +/** @see #153857 **/ +class CatalogueGetRequetesWith0NbNoticesTest extends ModelTestCase { + + + protected $_requestes; + + + public function setUp() { + parent::setUp(); + $this->_requetes = Class_Catalogue::getLoader() + ->getRequetes(['id_catalogue' => 0, + 'nb_notices' => 0, + 'facettes' => 'T1, Y1']); + } + + + /** @test */ + public function requeteListeShouldEqualsSelectStarWhereFacettesFromNotices0Limited() { + $this->assertEquals('select * from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre LIMIT 0,0', + $this->_requetes['req_liste']); + } +} \ No newline at end of file diff --git a/tests/library/Class/NewsletterTest.php b/tests/library/Class/NewsletterTest.php index 6ce28eb7b03dd7bcdd721d4109feabbbd2155513..1140918c6e26afbc52cb85dd8a09f9dfab1479a1 100644 --- a/tests/library/Class/NewsletterTest.php +++ b/tests/library/Class/NewsletterTest.php @@ -104,4 +104,44 @@ class NewsletterTimeSourceTest extends NewsletterTestCase { } -?> \ No newline at end of file + + +class NewsletterGetNoticesTest extends ModelTestCase { + + public function setUp() { + parent::setUp(); + + $this->fixture(Class_Catalogue::class, + ['id' => 12, + 'libelle' => 'Les livres pour enfants', + 'annee_debut' => '2020', + 'section' => '4', + 'nouveaute' => 0, + 'thesaurus' => ';;', + 'indexer' => 0, + 'custom_form_id' => null, + 'custom_form_values' => '']); + + $this->fixture(Class_Newsletter::class, + ['id' => 1, + 'titre' => 'les nouveautés pour enfants', + 'contenu' => 'Voici les nouveautés : ', + 'mail_subject'=>'Enfants: nouveatés du mois de mars', + 'id_catalogue' => 12, + 'nb_notices' => 0]); + + $this->onLoaderOfModel(Class_Notice::class); + } + + + /** @test */ + public function catalogRequestShouldLimitTo0() { + $this->assertEmpty(Class_Newsletter::find(1)->getNotices()); + } + + + /** @test */ + public function recordsLoadingForNewsletterShouldNotBeCall() { + $this->assertTrue(Class_Notice::methodHasNotBeenCalled('getNoticesFromPreferences')); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesNewslettersTest.php b/tests/scenarios/Templates/TemplatesNewslettersTest.php index 83b69c591c1290c50845a00b239b79576f26f6f3..9f80447777aa8b7a21e90f6762760dd988886bb3 100644 --- a/tests/scenarios/Templates/TemplatesNewslettersTest.php +++ b/tests/scenarios/Templates/TemplatesNewslettersTest.php @@ -70,3 +70,97 @@ class TemplatesNewslettersWidgetWithDescriptionLengthTest extends AbstractContro $this->assertXPathContentContains('//a[@href="/auth/newsletter-register/id/3"]', 'M\'inscrire'); } } + + + + +class TemplatesNewslettersWidgetWithCatalogueTestCase extends AbstractControllerTestCase { + + protected + $_storm_default_to_volatile = true, + $_nb_notices; + + + public function setUp() { + parent::setUp(); + + $profile = $this->_buildTemplateProfil(['id' => 789789]); + + $profile_patcher = (new Class_Template_ProfilePatcher(null)) + ->setProfile($profile); + + $profile_patcher + ->addWidget(Intonation_Library_Widget_Carousel_Newsletter_Definition::CODE, + Class_Profil::DIV_MAIN, + ['rendering' => 'card-description', + 'layout' => 'list', + 'size' => 1, + 'description_length' => 4]); + + $this->fixture(Class_Catalogue::class, + ['id' => 12, + 'libelle' => 'Les livres pour enfants', + 'annee_debut' => '2020', + 'section' => '4', + 'nouveaute' => 0, + 'thesaurus' => ';;', + 'indexer' => 0, + 'custom_form_id' => null, + 'custom_form_values' => '']); + + $this->fixture(Class_Newsletter::class, + ['id' => 1, + 'titre' => 'les nouveautés pour enfants', + 'contenu' => 'Voici les nouveautés : ', + 'mail_subject'=>'Enfants: nouveatés du mois de mars', + 'id_catalogue' => 12, + 'nb_notices' => $this->_nb_notices]); + + $this->onLoaderOfModel(Class_Notice::class); + + $this->dispatch('/'); + } + + + /** @test */ + public function newsletterWidgetShouldBePresent() { + $this->assertXPath('//div[@id="boite_1"][contains(@class, "boite newsletters")]'); + } + + + /** @test */ + public function newsletterNewsForChildrenShouldBeDisplay() { + $this->assertXPathContentContains('//main//div[@class="card-title card_title card_title_Intonation_Library_View_Wrapper_Newsletter"]', + 'les nouveautés pour enfants'); + } +} + + + + +class TemplatesNewslettersWidgetWithCatalogueAndZeroNbRecords extends TemplatesNewslettersWidgetWithCatalogueTestCase { + + + protected $_nb_notices = 0; + + + /** @test */ + public function recordsLoadingForNewsletterShouldNotBeCall() { + $this->assertTrue(Class_Notice::methodHasNotBeenCalled('getNoticesFromPreferences')); + } +} + + + + +class TemplatesNewslettersWidgetWithCatalogueAndOneNbRecords extends TemplatesNewslettersWidgetWithCatalogueTestCase { + + + protected $_nb_notices = 1; + + + /** @test */ + public function recordsLoadingForNewsletterShouldBeCall() { + $this->assertTrue(Class_Notice::methodHasBeenCalled('getNoticesFromPreferences')); + } +}