From a73413c64b3e90093ed902fb08da7f844af92e78 Mon Sep 17 00:00:00 2001
From: Julian Maurice <julian.maurice@biblibre.com>
Date: Mon, 22 Sep 2014 17:17:51 +0200
Subject: [PATCH] dev #14409 filters in calendar box

cms calendar test refactoring
---
 .../modules/opac/controllers/CalendarTest.php | 141 -------------
 .../CmsControllerCalendarActionTest.php       | 192 ++++++++++++++++++
 2 files changed, 192 insertions(+), 141 deletions(-)
 delete mode 100644 tests/application/modules/opac/controllers/CalendarTest.php
 create mode 100644 tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php

diff --git a/tests/application/modules/opac/controllers/CalendarTest.php b/tests/application/modules/opac/controllers/CalendarTest.php
deleted file mode 100644
index 14d314b9120..00000000000
--- a/tests/application/modules/opac/controllers/CalendarTest.php
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
- *
- * AFI-OPAC 2.0 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).
- *
- * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
- */
-require_once 'AbstractControllerTestCase.php';
-
-class CalendarCmsActionTest extends AbstractControllerTestCase {
-	protected $_article_loader;
-	protected $_nanook2, $_opac4;
-
-	public function setUp() {
-		parent::setUp();
-
-		$this->cfg_accueil =
-			array('modules' => array('1' => array('division' => '1',
-																						'type_module' => 'CALENDAR',
-																						'preferences' => array('titre' => 'Rendez-vous',
-																																	 'rss_avis' => false,
-																																	 'id_categorie' => '12-2',
-																																	 'display_cat_select' => true,
-																																	 'display_event_info' => 'none'))),
-						'options' => 	array());
-
-
-		$this->profil_rdv = Class_Profil::getLoader()->newInstanceWithId(3)
-			->setBrowser('opac')
-			->setLibelle('Rendez-vous')
-			->setCfgAccueil($this->cfg_accueil);
-
-		$_SESSION["CALENDAR"] = array('DATE' => '',
-																	'HTML' => array(''));
-
-		Class_AdminVar::getLoader()->newInstanceWithId('CACHE_ACTIF')->setValeur('1');
-
-		$this->_nanook2 = Class_Article::getLoader()
-			->newInstanceWithId(4)
-			->setTitre('Nanook 2 en prod !')
-			->setEventsDebut('2011-02-17')
-			->setEventsFin('2011-02-22');
-
-
-		$this->_opac4 = Class_Article::getLoader()
-			->newInstanceWithId(4)
-			->setTitre('OPAC 4 en prod !')
-			->setEventsDebut('2011-02-17')
-			->setEventsFin('2011-02-22');
-
-		$this->_article_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
-			->whenCalled('getArticlesByPreferences')
-			->answers(array($this->_nanook2))->getWrapper();
-	}
-
-
-	function tearDown() {
-		Class_AdminVar::getLoader()->find('CACHE_ACTIF')->setValeur('0');
-		parent::tearDown();
-	}
-
-
-	/**
-	 * Test non-regression vu sur Bucarest (prenait le layout normal au lieu du layout iframe)
-	 * @test
-	 */
-	function calendarShouldNotBeInAnIframeEventWithCacheActive() {
-		$cache = Storm_Test_ObjectWrapper::mock();
-		Storm_Cache::setDefaultZendCache($cache);
-		$module_cal = new ZendAfi_View_Helper_Accueil_Calendar(1, $this->cfg_accueil['modules']['1']);
-		$module_cal->setView(new ZendAfi_Controller_Action_Helper_View());
-
-		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/render/ajax');
-		// ça plantait lors de la réutilisation du cache, donc 2 dispatchs
-		$this->bootstrap();
-		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/render/ajax');
-		$this->assertNotXPath('//div[@id="site_web_wrapper"]');
-	}
-
-
-	/** @test */
-	function withLocaleEnMonthShouldBeFebruary() {
-		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en/render/ajax');
-		$this->assertXPathContentContains('//td[@class="calendar_title_month"]/a', "february", $this->_response->getBody());
-	}
-
-
-	/** @test **/
-	function calendarShouldContains3AwithClassCalendarTitleMonthClickable() {
-		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en/render/ajax');
-		$this->assertXPathCount('//a[@class="calendar_title_month_clickable"]',3,$this->_response->getBody());
-	}
-
-	/** @test **/
-	function calendarWithCustomFieldFiltersShould() {
-		$common_preferences = [
-										'display_order' => 'EventDebut',
-										'id_categorie' => '',
-										'events_only' => true,
-										 'id_bib' => 0,
-										'custom_fields' => [
-																				2 => 'music',
-										],
-										'published' => false,
-
-		];
-
-		$this->_article_loader
-			->whenCalled('getArticlesByPreferences')
-			->with(array_merge($common_preferences, ['event_date' => '2014-08']))
-			->answers([$this->_opac4])
-
-			->whenCalled('getArticlesByPreferences')
-			->with(array_merge($common_preferences, ['event_date' => '',
-																							 'event_start_after' => '2014-08',
-																							 'event_end_after' => '',
-																							 'limit' => 3]))
-			->answers([])
-			->beStrict();
-
-		$this->dispatch('/cms/calendar/date/2014-08/custom_field_2/music', true);
-		$this->assertXPathContentContains('//a[@class="calendar_event_title"]',
-																			'OPAC 4 en prod !',
-																			$this->_response->getBody());
-	}
-}
-
-?>
diff --git a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php
new file mode 100644
index 00000000000..af4a3221ce7
--- /dev/null
+++ b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php
@@ -0,0 +1,192 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+abstract class CmsControllerCalendarActionTestCase extends AbstractControllerTestCase {
+	protected
+		$_nanook2;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->cfg_accueil =
+			['modules' =>
+			 [ '1' => [
+								 'division' => '1',
+								 'type_module' => 'CALENDAR',
+								 'preferences' => [
+																	 'titre' => 'Rendez-vous',
+																	 'rss_avis' => false,
+																	 'id_categorie' => '12-2',
+																	 'display_cat_select' => true,
+																	 'enabled_filters' => 'month;place;custom_field_2',
+																	 'display_event_info' => 'none']]],
+			 'options' => 	[]];
+
+
+		$this->fixture('Class_Profil',
+									 ['id' => 3,
+										'browser' => 'opac',
+										'libelle' => 'Rendez-vous',
+										'cfg_accueil' => $this->cfg_accueil]);
+
+		Class_AdminVar::newInstanceWithId('CACHE_ACTIF',
+																			['valeur' => '1']);
+
+		$this->_nanook2 = $this->fixture('Class_Article',
+																		 ['id' => 4,
+																			'titre' => 'Nanook 2 en prod !',
+																			'contenu' => 'youpi !',
+																			'events_debut' => '2011-02-17',
+																			'events_fin' => '2011-02-22']);
+
+		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
+			->whenCalled('getArticlesByPreferences')
+			->answers([$this->nanook2]);
+	}
+
+
+	function tearDown() {
+		Class_AdminVar::getLoader()->find('CACHE_ACTIF')->setValeur('0');
+		parent::tearDown();
+	}
+}
+
+
+
+
+class CmsControllerCalendarActionCacheTest extends CmsControllerCalendarActionTestCase {
+	public function setUp() {
+		parent::setUp();
+		$cache = Storm_Test_ObjectWrapper::mock();
+		Storm_Cache::setDefaultZendCache($cache);
+		$module_cal = new ZendAfi_View_Helper_Accueil_Calendar(1, $this->cfg_accueil['modules']['1']);
+		$module_cal->setView(new ZendAfi_Controller_Action_Helper_View());
+	}
+	/**
+	 * Test non-regression vu sur Bucarest (prenait le layout normal au lieu du layout iframe)
+	 * @test
+	 */
+	function calendarShouldNotBeInAnIframeEventWithCacheActive() {
+		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/render/ajax');
+		// ça plantait lors de la réutilisation du cache, donc 2 dispatchs
+		$this->bootstrap();
+		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/render/ajax');
+		$this->assertNotXPath('//div[@id="site_web_wrapper"]');
+	}
+}
+
+
+
+
+class CmsControllerCalendarActionLanguageEnTest extends CmsControllerCalendarActionTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en/render/ajax');
+	}
+
+
+	/** @test */
+	function withLocaleEnMonthShouldBeFebruary() {
+		$this->assertXPathContentContains('//td[@class="calendar_title_month"]/a', "february", $this->_response->getBody());
+	}
+
+
+	/** @test **/
+	function calendarShouldContains3AwithClassCalendarTitleMonthClickable() {
+		$this->assertXPathCount('//a[@class="calendar_title_month_clickable"]',3);
+	}
+}
+
+
+
+
+class CmsControllerCalendarActionWithFiltersTest extends CmsControllerCalendarActionTestCase {
+	protected $_opac4;
+
+	public function setupCustomFields() {
+		Class_CustomField_Meta::beVolatile();
+		$theme = $this->fixture('Class_CustomField',
+														['id' => 2,
+														 'priority' => 3,
+														 'label' => 'Theme',
+														 'field_type' => Class_CustomField_Meta::SELECT,
+														 'options_list' => 'sigb;opac',
+														 'model' => 'Article']);
+
+		$this->fixture('Class_CustomField_Value',
+									 ['id' => 5,
+										'custom_field_id' => $theme->getId(),
+										'model' => $this->_nanook2,
+										'value' => 'sigb']);
+
+		$this->fixture('Class_CustomField_Value',
+									 ['id' => 2,
+										'custom_field_id' => $theme->getId(),
+										'model' => $this->_opac4,
+										'value' => 'opac']);
+	}
+
+
+	public function setUp() {
+		parent::setUp();
+		$this->_opac4 = $this->fixture('Class_Article',
+																	 ['id' => 5,
+																		'titre' => 'OPAC 4 en prod !',
+																		'contenu' => 'youpi !',
+																		'events_debut' => '2011-02-17',
+																		'events_fin' => '2011-02-22']);
+		$this->setupCustomFields();
+
+		$common_preferences = [
+													 'display_order' => 'EventDebut',
+													 'id_categorie' => '',
+													 'events_only' => true,
+													 'id_bib' => 0,
+													 'custom_fields' => [
+																							 2 => 'music',
+													 ],
+													 'published' => false];
+
+
+		Class_Article::getLoader()
+			->whenCalled('getArticlesByPreferences')
+			->with(array_merge($common_preferences, ['event_date' => '2014-08']))
+			->answers([$this->_opac4])
+
+			->whenCalled('getArticlesByPreferences')
+			->with(array_merge($common_preferences, ['event_date' => '',
+																							 'event_start_after' => '2014-08',
+																							 'event_end_after' => '',
+																							 'limit' => 3]))
+			->answers([])
+			->beStrict();
+
+		$this->dispatch('/cms/calendar/date/2014-08/custom_field_2/music', true);
+	}
+
+
+	/** @test **/
+	function calendarWithCustomFieldFiltersShouldBuildPreferencesForGetArticlesByPreferences() {
+		$this->assertXPathContentContains('//a[@class="calendar_event_title"]',
+																			'OPAC 4 en prod !');
+	}
+}
+
+?>
-- 
GitLab