Skip to content
Snippets Groups Projects
Commit edfb70b7 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'hotline#143811_nouveautes_page_d_accueil' into 'hotline'

hotline : #143811 : random in carousel have always same records

See merge request !4291
parents 7f9fddb8 e4f970df
Branches
Tags
1 merge request!4291hotline : #143811 : random in carousel have always same records
Pipeline #15427 passed with stage
in 27 minutes and 23 seconds
- ticket #143811 : Magasin de thèmes : Correction du tri aléatoire dans les carousels de notices.
\ No newline at end of file
......@@ -22,6 +22,7 @@
class Intonation_Library_Widget_Carousel_Record_View extends Intonation_Library_Widget_Carousel_View {
protected static $_storm_limit = 100;
protected function _findElements() {
$order = $this->_settings->getOrder();
......@@ -36,18 +37,27 @@ class Intonation_Library_Widget_Carousel_Record_View extends Intonation_Library_
'url_image=""',
$order]);
$params = ['limit' => $this->_getSize(),
$params = ['limit' => $this->_getLimit(),
'order' => new Class_MoteurRecherche_OrderCriteria(implode(', ', $order))];
$records = $this->_findRecords($params);
if ($this->_settings->isDisplayRandom())
if ($this->_settings->isDisplayRandom()) {
shuffle($records);
array_slice($records, 0, $this->_getSize());
}
return $records;
}
protected function _getLimit() {
return $this->_settings->isDisplayRandom()
? static::$_storm_limit
: $this->_getSize();
}
protected function _findRecords($params) {
$selection_id = $this->_settings->getIdPanier();
$order = $this->_settings->getOrder();
......@@ -89,7 +99,7 @@ class Intonation_Library_Widget_Carousel_Record_View extends Intonation_Library_
return [];
return Class_Notice::findAllByRequeteRecherche($request_ids,
$this->_getSize(), 1);
$this->_getLimit(), 1);
}
......
......@@ -176,14 +176,13 @@ class NumelKioskMapLimit1000Test extends AbstractControllerTestCase {
->render()]);
$notices_ids = [];
for ($pos = 0; $pos < 1000; $pos++)
for ($pos = 1; $pos <= 100; $pos++)
$notices_ids [] = $pos;
$notices_100_ids = array_slice($notices_ids, 0, 100);
$this->_mock_sql = $this->mock()
->whenCalled('fetchAllByColumn')
->with('select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\'Q444\' IN BOOLEAN MODE)) and type=1 order by url_image="no", url_image="" LIMIT 0,1000')
->with('select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\'Q444\' IN BOOLEAN MODE)) and type=1 order by url_image="no", url_image="" LIMIT 0,100')
->answers($notices_ids);
Zend_Registry::set('sql', $this->_mock_sql);
......@@ -191,8 +190,8 @@ class NumelKioskMapLimit1000Test extends AbstractControllerTestCase {
Storm_Test_ObjectWrapper::onLoaderOfModel(Class_Notice::class)
->whenCalled('findAllBy')
->with(['id_notice' => $notices_100_ids,
'order' => 'FIELD(id_notice, ' . implode(',', $notices_100_ids) . ')'])
->with(['id_notice' => $notices_ids,
'order' => 'FIELD(id_notice, ' . implode(',', $notices_ids) . ')'])
->answers([$notice_fier])
->whenCalled('findAllBy')
......@@ -211,7 +210,7 @@ class NumelKioskMapLimit1000Test extends AbstractControllerTestCase {
$preferences = ['layout' => Intonation_Library_Widget_Carousel_Definition::MAP,
'rendering' => 'card',
'size' => 1000,
'size' => 50,
'id_catalogue' => 444,
'titre' => 'Les cartes postales sur la carte',
'order' => 'RAND()'
......@@ -229,8 +228,8 @@ class NumelKioskMapLimit1000Test extends AbstractControllerTestCase {
/** @test */
public function fetchAllByColumnWillBeCalledWithLimit1000() {
$this->assertEquals('select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\'Q444\' IN BOOLEAN MODE)) and type=1 order by url_image="no", url_image="" LIMIT 0,1000', $this->_mock_sql->getFirstAttributeForLastCallOn('fetchAllByColumn'));
public function fetchAllByColumnWillBeCalledWithLimit100() {
$this->assertEquals('select notices.id_notice from notices Where (MATCH(facettes) AGAINST(\'Q444\' IN BOOLEAN MODE)) and type=1 order by url_image="no", url_image="" LIMIT 0,100', $this->_mock_sql->getFirstAttributeForLastCallOn('fetchAllByColumn'));
}
......
......@@ -152,4 +152,71 @@ class TemplatesWidgetCarouselLoaderTestTest extends ArticleLoaderGetArticlesByPr
$article = $this->getArticles(['filter_by_local' => true]);
$this->assertQueryEquals('SELECT `cms_article`.* FROM `cms_article` WHERE ((DEBUT IS NULL) OR (DEBUT <= CURDATE())) AND ((FIN IS NULL) OR (FIN >= CURDATE())) AND (PARENT_ID=0) AND ((cms_article.langue = "fr" or exists (select \'x\' from cms_article as translation where translation.PARENT_ID = cms_article.ID_ARTICLE and trim(translation.langue) = "fr") or cms_article.langue = "" or cms_article.langue is null)) ORDER BY `DATE_CREATION` DESC');
}
}
\ No newline at end of file
}
/* hotline: #143811 */
class TemplatesWidgetCarouselRecordNewsTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->_buildTemplateProfil(['id' => 1,
'libelle' => 'Randomize carousel'])
->setBoiteOfTypeInDivision(2,
Intonation_Library_Widget_Carousel_Record_Definition::CODE,
['layout' => 'horizontal_list',
'rendering' => 'card-overlay',
'size' => 2,
'rss' => 0,
'embeded_code' => 0,
'link_to_all' => 1,
'all_layout' => 'list',
'all_rendering' => 'card-horizontal',
'description_length' => 20,
'titre' => 'Toutes les nouveautés',
'order' => 'RAND()',
'id_catalogue' => 10,
'type_module' => 'KIOSQUE'
])
->assertSave();
$this->fixture(Class_Catalogue::class,
['id' => 10,
'libelle' => 'Catalogue nouveauté',
'type_doc' => 1
]);
for ($i = 1; $i <= 100; $i++)
$this->fixture(Class_Notice::class,
['id' => $i]);
Zend_Registry::set('sql', null);
Storm_Cache::beVolatile();
$cache = (new Storm_Cache)
->memoize(['select notices.id_notice from notices Where (notices.type_doc=\'1\') and type=1 order by url_image="no", url_image="" LIMIT 0,100',
'NoticeLoader',
'getNoticeIdsByRequeteRecherche'],
function () {return range(1, 100);});
$this->dispatch('/index');
}
/** @test */
public function carouselShouldBePresentWithTwoRandomRecords() {
$this->assertXpathCount(2, '//div[contains(@class, "boite kiosque")]//div[contains(@class, "card-deck")]//div[contains(@class, "card_with_overlay")]');
}
/** @test */
public function carouselRecordsShouldBeShuffled() {
$this->assertRegExp('/.*(\/recherche\/viewnotice\/id\/(([^1-2]\/)|([0-9][0-9]0?\/)))./',
$this->_response->getBody());
}
}
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