Commit 713c70bb authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'hotline#137761_actualites_en_ligne_non_visible' into 'hotline'

hotline: #137761 : Carousel articles should be filtered with status

See merge request afi/opacce!4148
parents 24c7c89c cef45991
- ticket #137761 : Magasin de thèmes : Correction du filtrage des articles dans les caroussels
\ No newline at end of file
...@@ -349,20 +349,59 @@ class ArticleLoader extends Storm_Model_Loader { ...@@ -349,20 +349,59 @@ class ArticleLoader extends Storm_Model_Loader {
* @return ArticleLoader * @return ArticleLoader
*/ */
protected function _filterByStatus() { protected function _filterByStatus() {
if (null === $this->_status) { if (null === $this->_select)
return $this; return $this;
}
if (null === $this->_select) { $filters = ($filters = $this->_getFilterByWorkflow())
return $this; ? $filters
} : $this->_status;
$this->_select->where('STATUS in (?)', $this->_status); if ($filters)
$this->_select->where('STATUS in (?)', $filters);
return $this; return $this;
} }
protected function _getFilterByWorkflow() {
if (! $this->_filter_by_workflow)
return null;
if (!Class_AdminVar::isWorkflowEnabled())
return null;
$status_filter = [Class_Article::STATUS_VALIDATED];
if (Class_Users::isCurrentUserCanAccesBackend())
$status_filter [] = Class_Article::STATUS_DRAFT;
if ($this->_status)
$status_filter [] = $this->_status;
return array_unique($status_filter);
}
protected function _filterByLocal() {
if (! $this->_filter_by_local)
return null;
if (!Class_AdminVar::isTranslationEnabled())
return null;
if ($langue = Zend_Registry::get('translate')->getLocale())
$this->_select
->where('(cms_article.langue = "' . $langue . '" or exists (select \'x\' from cms_article as translation where translation.PARENT_ID = cms_article.ID_ARTICLE and trim(translation.langue) = "' . $langue . '") or cms_article.langue = "" or cms_article.langue is null)');
return function ($articles) use ($langue) {
return array_map(function ($article) use ($langue)
{
return $article->getTraductionLangue($langue);
},
$articles);
};
}
public function getArticlesByPreferencesDefaults() { public function getArticlesByPreferencesDefaults() {
return ['id_categorie' => '', // catégories d'article, ex: 12-2-8-1-89 return ['id_categorie' => '', // catégories d'article, ex: 12-2-8-1-89
...@@ -383,7 +422,9 @@ class ArticleLoader extends Storm_Model_Loader { ...@@ -383,7 +422,9 @@ class ArticleLoader extends Storm_Model_Loader {
'id_lieu' => null, // id du lieu Class_Lieu 'id_lieu' => null, // id du lieu Class_Lieu
'place_town' => null, 'place_town' => null,
'display_mode' => 'Title', 'display_mode' => 'Title',
'custom_fields' => []]; 'custom_fields' => [],
'filter_by_workflow' => false,
'filter_by_local' => false];
} }
...@@ -420,6 +461,9 @@ class ArticleLoader extends Storm_Model_Loader { ...@@ -420,6 +461,9 @@ class ArticleLoader extends Storm_Model_Loader {
$this->_display_mode = $preferences['display_mode']; $this->_display_mode = $preferences['display_mode'];
$this->_custom_fields = $preferences['custom_fields']; $this->_custom_fields = $preferences['custom_fields'];
$this->_filter_by_workflow = $preferences['filter_by_workflow'];
$this->_filter_by_local = $preferences['filter_by_local'];
if ($this->_sort_order == static::ORDER_SELECTION && !$this->_has_selection) if ($this->_sort_order == static::ORDER_SELECTION && !$this->_has_selection)
return []; return [];
...@@ -438,6 +482,8 @@ class ArticleLoader extends Storm_Model_Loader { ...@@ -438,6 +482,8 @@ class ArticleLoader extends Storm_Model_Loader {
->_orderAndLimit() ->_orderAndLimit()
->_getSelect(); ->_getSelect();
$filter_by_local_callback = $this->_filterByLocal();
$articles = Class_Article::getLoader()->findAll($select); $articles = Class_Article::getLoader()->findAll($select);
if ($this->_custom_fields) if ($this->_custom_fields)
...@@ -447,7 +493,11 @@ class ArticleLoader extends Storm_Model_Loader { ...@@ -447,7 +493,11 @@ class ArticleLoader extends Storm_Model_Loader {
if ((new ZendAfi_Validate_DateFormat)->isValid($this->_event_date)) if ((new ZendAfi_Validate_DateFormat)->isValid($this->_event_date))
$articles = $this->_filterByDay($this->_event_date, $articles); $articles = $this->_filterByDay($this->_event_date, $articles);
$this->_all_articles = $articles = $this->_sortArticles($articles); $articles = $this->_sortArticles($articles);
$this->_all_articles = $articles = $filter_by_local_callback
? $filter_by_local_callback($articles)
: $articles;
if ( if (
($this->_sort_order == static::ORDER_SELECTION) ($this->_sort_order == static::ORDER_SELECTION)
......
...@@ -34,8 +34,10 @@ class Intonation_Library_Widget_Carousel_Article_View extends Intonation_Library ...@@ -34,8 +34,10 @@ class Intonation_Library_Widget_Carousel_Article_View extends Intonation_Library
if ( ! (isset($this->preferences['id_categorie']) && $this->preferences['id_categorie'])) if ( ! (isset($this->preferences['id_categorie']) && $this->preferences['id_categorie']))
$this->preferences['size'] = Intonation_Library_Widget_Carousel_Definition::LIMIT_SIZE; $this->preferences['size'] = Intonation_Library_Widget_Carousel_Definition::LIMIT_SIZE;
$this->_articles = $loader->getArticlesByPreferences($this->preferences); $this->preferences['filter_by_workflow'] = true;
return Class_Article::filterByLocaleAndWorkflow($this->_articles); $this->preferences['filter_by_local'] = true;
return $this->_articles = $loader->getArticlesByPreferences($this->preferences);
} }
...@@ -62,4 +64,4 @@ class Intonation_Library_Widget_Carousel_Article_View extends Intonation_Library ...@@ -62,4 +64,4 @@ class Intonation_Library_Widget_Carousel_Article_View extends Intonation_Library
protected function _extendedActions() { protected function _extendedActions() {
return [function() { return $this->view->Admin_TagAddNewArticle($this->id_module, $this->_articles); }]; return [function() { return $this->view->Admin_TagAddNewArticle($this->id_module, $this->_articles); }];
} }
} }
\ No newline at end of file
...@@ -207,52 +207,6 @@ class TemplatesArticlesWidgetTest extends TemplatesArticlesWidgetTestCase { ...@@ -207,52 +207,6 @@ class TemplatesArticlesWidgetTest extends TemplatesArticlesWidgetTestCase {
class TemplatesArticlesWidgetWithWorklowTest extends TemplatesArticlesWidgetTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('WORKFLOW', 1);
Class_Article::find(4)->beValidated()->assertSave();
Class_Article::find(6)->beDraft()->assertSave();
Class_Article::find(7)->beValidationPending()->assertSave();
$this
->onLoaderOfModel('Class_Article')
->whenCalled('getArticlesByPreferences')
->answers(Class_Article::findAllBy(['id_article' => [4, 6, 7]]));
ZendAfi_Auth::getInstance()->clearIdentity();
$this->dispatch('/opac/index/index/id_profil/1', true);
}
/** @test */
public function widgetCarouselShouldContainsValidatedArticleWinter() {
$this->assertXPathContentContains('//div[contains(@class, "boite news")]//div[@class="card-title"]',
'Winter');
}
/** @test */
public function widgetCarouselShouldNotContainsDraftArticleSprechenSieDeutsh() {
$this->assertNotXPathContentContains('//div[contains(@class, "boite news")]//div[@class="card-title"]',
'Sprechen Sie Deutsch ?');
}
/** @test */
public function widgetCarouselShouldNotContainsPendingArticleParlezVousFrancais() {
$this->assertNotXPathContentContains('//div[contains(@class, "boite news")]//div[@class="card-title"]',
'Parlez-vous français ?');
}
}
class TemplatesArticlesCmsListActionTest extends TemplatesArticlesWidgetTestCase { class TemplatesArticlesCmsListActionTest extends TemplatesArticlesWidgetTestCase {
/** @test */ /** @test */
public function dispatchShouldRenderSprechenSieDeutsh() { public function dispatchShouldRenderSprechenSieDeutsh() {
...@@ -1092,4 +1046,4 @@ class TemplatesArticlesWidgetWithDescriptionHTMLTest extends AbstractControllerT ...@@ -1092,4 +1046,4 @@ class TemplatesArticlesWidgetWithDescriptionHTMLTest extends AbstractControllerT
$this->assertXPathContentContains('//div[contains(@class, "news widget")]//p[contains(@class, "model_description")]', $this->assertXPathContentContains('//div[contains(@class, "news widget")]//p[contains(@class, "model_description")]',
'<a href="#">là</a><a href="#">ici</a>La description s\'arrête ici et pas plus loin.'); '<a href="#">là</a><a href="#">ici</a>La description s\'arrête ici et pas plus loin.');
} }
} }
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2021, 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
*/
/* hotline: #137761 */
abstract class TemplatesWidgetCarouselArticlesTestCase
extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_loader_article;
public function setUp() {
parent::setUp();
$this->_buildTemplateProfil(['id' => 1,
'libelle' => 'Carousel Articles'])
->setBoiteOfTypeInDivision(2,
Intonation_Library_Widget_Carousel_Article_Definition::CODE,
['all_layout' => Intonation_Library_Widget_Carousel_Definition::CAROUSEL,
'size' => 3,
'order' => 'Random',
'id_categorie' => 1,
'rss' => 1,
'link_to_all' => 1,
'embeded_code'=> 1,
'IntonationShowFooter' => 1,
'layout' => 'carousel'
])
->assertSave();
$this->_loader_article = $this->onLoaderOfModel(Class_Article::class);
}
}
class TemplatesWidgetCarouselArticlesWithWorkflowTest
extends TemplatesWidgetCarouselArticlesTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('WORKFLOW', 1);
$this->dispatch('/index');
}
/** @test */
public function getArticlesByPreferencesShouldBeCalledWithFilterByWorkflow() {
$prefs = $this->_loader_article
->getFirstAttributeForLastCallOn('getArticlesByPreferences');
$this->assertTrue($prefs['filter_by_workflow']);
}
/** @test */
public function getArticlesByPreferencesShouldBeCalledWithFilterByLocal() {
$prefs = $this->_loader_article
->getFirstAttributeForLastCallOn('getArticlesByPreferences');
$this->assertTrue($prefs['filter_by_local']);
}
}
class TemplatesWidgetCarouselArticlesNotVolatileTest
extends TemplatesWidgetCarouselArticlesTestCase {
protected $_storm_default_to_volatile = false;
/** @test */
public function withWorkflowShouldDisplayThreeItems() {
Class_AdminVar::set('WORKFLOW', 1);
$this->dispatch('/index');
$this->assertXpathCount('//div[contains(@class, "carousel-item")]', '3');
}
/** @test */
public function withoutWorkflowShouldDisplayThreeItems() {
Class_AdminVar::set('WORKFLOW', 0);
$this->dispatch('/index');
$this->assertXpathCount('//div[contains(@class, "carousel-item")]', '3');
}
/** @test */
public function withLangueShouldDisplayThreeItems() {
Class_AdminVar::set('LANGUES', 'fr;en;es;ro;it');
$this->dispatch('/index');
$this->assertXpathCount('//div[contains(@class, "carousel-item")]', '3');
}
/** @test */
public function withoutLangueShouldDisplayThreeItems() {
Class_AdminVar::set('LANGUES', '');
$this->dispatch('/index');
$this->assertXpathCount('//div[contains(@class, "carousel-item")]', '3');
}
}
Markdown is supported
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