Commit 2f38fd36 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT Committed by Patrick Barroca

hotline#94066 : Calendar Widget : Allow user to reset date filter when calendar is not displayed

parent c6f20b5f
Pipeline #7669 failed with stage
in 31 minutes and 47 seconds
- ticket #94066 : Filtres de l'agenda : Ajout de l'élément "Tous" sur le filtre "Mois" pour déselectionner le critère lorsque la configuration d'affichage est mise à "Afficher le calendrier" = "non"
\ No newline at end of file
......@@ -291,6 +291,11 @@ class Class_Calendar {
}
public function isDisplayNoCalendar() {
return 0 == $this->preferences['display_calendar'];
}
public function getActiveFilters() {
if (empty($filters = $this->getEnabledFilters()))
return [];
......
......@@ -83,6 +83,17 @@ abstract class ZendAfi_View_Helper_Filters_Element extends ZendAfi_View_Helper_B
}
/**
* @param Class_FilterSettings $settings
* @param callable $callback
*
* Take a chance to decide whether to render any value item or not
*/
public function renderAnyValueItem($settings, $callback) {
return call_user_func($callback);
}
protected function _getFilterStrategy() {
return ZendAfi_View_Helper_Filters_Strategy_Abstract::newFor($this);
}
......
......@@ -26,8 +26,10 @@ class ZendAfi_View_Helper_Filters_Element_Date extends ZendAfi_View_Helper_Filte
}
protected function _renderAnyValueItem($base_url, $selected) {
return '';
public function renderAnyValueItem($settings, $callback) {
return ($calendar = $settings->getCalendar()) && $calendar->isDisplayNoCalendar()
? parent::renderAnyValueItem($settings, $callback)
: '';
}
......
......@@ -20,7 +20,8 @@
*/
abstract class ZendAfi_View_Helper_Filters_Strategy_Elements extends ZendAfi_View_Helper_Filters_Strategy_Abstract {
abstract class ZendAfi_View_Helper_Filters_Strategy_Elements
extends ZendAfi_View_Helper_Filters_Strategy_Abstract {
protected function _shouldRender() {
......
......@@ -20,7 +20,8 @@
*/
class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Filters_Strategy_Elements {
class ZendAfi_View_Helper_Filters_Strategy_Facet
extends ZendAfi_View_Helper_Filters_Strategy_Elements {
public function renderFilterItems($elements) {
$html = $this->_renderAnyValueItem(!$this->_isActive());
......@@ -32,10 +33,12 @@ class ZendAfi_View_Helper_Filters_Strategy_Facet extends ZendAfi_View_Helper_Fil
protected function _renderAnyValueItem($selected) {
if ($this->_getCustomFieldId() == 'date')
return '';
return $this->_renderFilterItem(null, $this->_('Tous'), $selected);
return $this->_filter_elements
->renderAnyValueItem($this->_settings,
function () use($selected)
{
return $this->_renderFilterItem(null, $this->_('Tous'), $selected);
});
}
......
......@@ -276,7 +276,8 @@ class CmsControllerCalendarActionWithMultipleFiltersTest extends CmsControllerCa
}
abstract class CmsControllerCalendarActionWithFiltersTestCase extends CmsControllerCalendarActionTestCase {
abstract class CmsControllerCalendarActionWithFiltersTestCase
extends CmsControllerCalendarActionTestCase {
protected
$_opac4,
$_date,
......@@ -309,7 +310,8 @@ abstract class CmsControllerCalendarActionWithFiltersTestCase extends CmsControl
class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalendarActionWithFiltersTestCase {
class CmsControllerCalendarActionWithFiltersDateTest
extends CmsControllerCalendarActionWithFiltersTestCase {
public function setUp() {
parent::setUp();
......@@ -348,6 +350,15 @@ class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalen
}
/** @test */
public function calendarFilterOnMonthShouldNotContainsLinkToResetDate() {
$expected = '/custom_field_2/opac';
$this->assertNotXPathContentContains('//li[@data-id="date"]//a["' . $expected. '"=substring(@href, string-length(@href)-' . (strlen($expected)-1) .')]',
'Tous',
$this->_response->getBody());
}
/** @test **/
public function calendarWithCustomFieldFiltersShouldBuildPreferencesForGetArticlesByPreferences() {
$this->assertXPathContentContains('//a[@class="calendar_event_title"]',
......@@ -424,11 +435,13 @@ class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalen
$this->assertXPath('//a[@class="calendar_title_month_clickable"][contains(@href,"/day/2014-06")][contains(@href, "/date/2014-06")]');
}
/** @test */
public function linkCurrentMonthContainsDayParameter() {
$this->assertXPath('//a[@class="calendar_title_month_clickable"][contains(@href,"/day/2014-07")][contains(@href,"/cms/calendar")]');
}
/** @test */
public function linkInsideCalendarShouldContainsDayButNoDateParameters() {
$this->assertXPath('//a[contains(@class,"day_clickable")][contains(@href,"/day/2014-07-17")][not(contains(@href, "/date/"))]',
......@@ -438,6 +451,44 @@ class CmsControllerCalendarActionWithFiltersDateTest extends CmsControllerCalen
class CmsControllerCalendarActionWithFiltersDateAndNoCalendarTest
extends CmsControllerCalendarActionWithFiltersTestCase {
public function setUp() {
parent::setUp();
Class_Article::getLoader()
->whenCalled('getArticlesByPreferences')
->with(array_merge($this->_common_preferences, ['event_date' => '2014-07']))
->answers([$this->_opac4])
->whenCalled('getArticlesByPreferences')
->with(array_merge($this->_common_preferences, ['event_date' => '',
'event_start_after' => '2014-07',
'event_end_after' => '',
'limit' => 3]))
->answers([])
->beStrict();
$profil = Class_Profil::find(3);
$cfg_accueil = $profil->getCfgAccueilAsArray();
$cfg_accueil['modules'][1]['preferences']['display_calendar'] = '0';
$profil->setCfgAccueil($cfg_accueil)->assertSave();
$this->dispatch('/cms/calendar/id_profil/3/id_module/1/date/2014-07/custom_field_2/opac/render/ajax', true);
}
/** @test */
public function calendarFilterOnMonthShouldContainsLinkToResetDate() {
$expected = '/custom_field_2/opac';
$this->assertXPathContentContains('//li[@data-id="date"]//a["' . $expected. '"=substring(@href, string-length(@href)-' . (strlen($expected)-1) .')]',
'Tous',
$this->_response->getBody());
}
}
class CmsControllerCalendarActionWithFiltersDayTest extends CmsControllerCalendarActionWithFiltersTestCase {
public function setUp() {
......
......@@ -950,9 +950,9 @@ abstract class CalendarHelperDisplayModeTestCase extends CalendarViewHelperTestC
'categorie' => '',
'contenu' => 'toto'
]);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
->whenCalled('getArticlesByPreferences')
->answers([$this->_article_bokeh]);
$this->onLoaderOfModel('Class_Article')
->whenCalled('getArticlesByPreferences')
->answers([$this->_article_bokeh]);
$params = ['type_module' => 'CALENDAR',
'division' => 2,
......@@ -1127,14 +1127,16 @@ class CalendarHelperWithFiltersTest extends CalendarHelperDisplayModeTestCase {
/** @test */
public function dateFilterShouldContainsAllMonths() {
$this->assertXPathCount($this->html,
'//ul[contains(@class, "filters")]/li[@class="date"]/ul/li', 12, $this->html);
'//ul[contains(@class, "filters")]/li[@class="date"]/ul/li',
13,
$this->html);
}
/** @test */
public function dateFilterShouldContainsJuillet() {
$this->assertXPathContentContains($this->html,
'//ul[contains(@class, "filters")]/li[@class="date"]//li[1]/a[contains(@href, "date/2014-07")]', 'Juillet', $this->html);
'//ul[contains(@class, "filters")]/li[@class="date"]//li[2]/a[contains(@href, "date/2014-07")]', 'Juillet', $this->html);
}
......@@ -1142,7 +1144,7 @@ class CalendarHelperWithFiltersTest extends CalendarHelperDisplayModeTestCase {
/** @test */
public function dateFilterShouldContainsJuin() {
$this->assertXPathContentContains($this->html,
'//ul[contains(@class, "filters")]/li[@class="date"]//li[12]/a[contains(@href, "date/2015-06")]', 'Juin');
'//ul[contains(@class, "filters")]/li[@class="date"]//li[13]/a[contains(@href, "date/2015-06")]', 'Juin');
}
......
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