From 9e1bf6f9d509a60482977134a7f9e700ae063569 Mon Sep 17 00:00:00 2001
From: adiouf <adiouf@afi-sa.fr>
Date: Wed, 10 Dec 2014 11:57:56 +0100
Subject: [PATCH] authorize the reservation of device the closing days

---
 .../controllers/MultimediaController.php      |  38 +++-
 .../opac/controllers/AbonneController.php     |   2 +-
 library/Class/Multimedia/Location.php         |  73 ++++----
 .../AbonneControllerMultimediaTest.php        | 166 +++++++++++++-----
 .../library/Class/Multimedia/LocationTest.php |  65 ++++---
 5 files changed, 235 insertions(+), 109 deletions(-)

diff --git a/application/modules/admin/controllers/MultimediaController.php b/application/modules/admin/controllers/MultimediaController.php
index 9df8e86fad5..1783a130b93 100644
--- a/application/modules/admin/controllers/MultimediaController.php
+++ b/application/modules/admin/controllers/MultimediaController.php
@@ -16,7 +16,7 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301	 USA
  */
 
 class Admin_MultimediaController extends ZendAfi_Controller_Action {
@@ -39,7 +39,10 @@ class Admin_MultimediaController extends ZendAfi_Controller_Action {
 																					'elements' => $this->getConfigFields()],
 
 														 'config_auto' => ['legend' => 'Réservation automatique',
-																							 'elements' => $this->getConfigAutoFields()]
+																							 'elements' => $this->getConfigAutoFields()],
+
+														 'config_auto_closing_days' => ['legend' => 'Réservation les jours de fermetures',
+																							 'elements' => $this->getConfigClosingDaysFields()]
 														 ]
 						];
 	}
@@ -49,7 +52,7 @@ class Admin_MultimediaController extends ZendAfi_Controller_Action {
 		$libelles = [];
 		foreach (Class_Bib::findAllBy(['order' => 'libelle']) as $bib)
 			$libelles[$bib->getId()] = $bib->getLibelle();
-		
+
 		return ['id_site' => ['element' => 'select',
 													'options' => ['multioptions' => $libelles]]];
 	}
@@ -128,6 +131,29 @@ disponible',
 	}
 
 
+	public function getConfigClosingDaysFields() {
+		$hours_select = Class_Multimedia_Location::getLoader()->getPossibleHours(30);
+
+
+		$fields['autohold_for_closing_days'] = ['element' => 'checkbox',
+													 'options' => ['label' => 'Autoriser les réservations automatique pour les jours de fermeture
+disponible',
+																				 'title' => 'Permet de définir des jours d\'utilisation des postes sans possibilités de réservation de bokeh',
+																				 'required' => true,
+																				 'allowEmpty' => false]];
+
+
+		$field_labels = ['open_hour' => $this->view->_('Heure d\'ouverture'),
+										 'close_hour' => $this->view->_('Heure de fermeture')];
+
+		foreach ($field_labels as $field => $label)
+			$fields[$field] = ['element' => 'select', 'options' => ['label' => $label,
+																															'multiOptions' => $hours_select]];
+
+		return $fields;
+						}
+
+
 	public function browseAction() {
 		if (!$location = Class_Multimedia_Location::find((int)$this->_getParam('id'))) {
 			$this->_redirect('/admin/multimedia');
@@ -140,19 +166,19 @@ disponible',
 																								 'devices' => $devices]);
 		$this->_forward('index');
 	}
-		
+
 
 	protected function _postEditAction($model) {
 		$this->view->titre = 'Modification du site multimédia "' . $this->view->escape($model->getLibelle()) . '"';
 	}
-		
+
 
 	/** Les données viennent d'un serveur multimédia, pas de suppression */
 	public function deleteAction() {
 		$this->_redirect('/admin/multimedia');
 	}
 
-	
+
 	/** Les données viennent d'un serveur multimédia, pas d'ajout */
 	public function addAction() {
 		$this->_redirect('/admin/multimedia');
diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php
index 1860dfdd57f..ce0b48480c0 100644
--- a/application/modules/opac/controllers/AbonneController.php
+++ b/application/modules/opac/controllers/AbonneController.php
@@ -575,7 +575,7 @@ class AbonneController extends ZendAfi_Controller_Action {
 		$response->auth = 0;
 		$response->until = '';
 
-		$request = Class_Multimedia_AuthenticateRequest::newWithRequest($this->_request);
+		$request =Class_Multimedia_AuthenticateRequest::newWithRequest($this->_request);
 		if ($user = $request->getUser()) {
 			foreach (['id', 'login', 'password', 'nom',
 								'prenom', 'date_debut', 'date_fin'] as $attribute)
diff --git a/library/Class/Multimedia/Location.php b/library/Class/Multimedia/Location.php
index b746be2a82f..3c87b5ea6aa 100644
--- a/library/Class/Multimedia/Location.php
+++ b/library/Class/Multimedia/Location.php
@@ -16,7 +16,7 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 class Multimedia_LocationLoader extends Storm_Model_Loader {
@@ -69,7 +69,7 @@ class Multimedia_LocationLoader extends Storm_Model_Loader {
 
 		if ($from > $to)
 			return array();
-				
+
 		$times = range($from, $to, 60 * $increment);
 		if (end($times) == $to)
 			array_pop($times);
@@ -105,9 +105,9 @@ class Multimedia_LocationLoader extends Storm_Model_Loader {
 
 
 class Class_Multimedia_Location extends Storm_Model_Abstract {
-	/** @var Class_TimeSource */
-	protected static $_time_source;
-	
+
+	use Trait_TimeSource;
+
 	protected $_loader_class = 'Multimedia_LocationLoader';
 	protected $_table_name = 'multimedia_location';
 	protected $_has_many = ['groups' => ['model' => 'Class_Multimedia_DeviceGroup',
@@ -122,7 +122,7 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 	protected $_belongs_to = ['bib' => ['model' => 'Class_Bib',
 																			'referenced_in' => 'id_site']];
 
-	protected $_default_attribute_values = ['days' => '', 
+	protected $_default_attribute_values = ['days' => '',
 																					'autohold_min_time' => 10,
 																					'admin_url' => '',
 																					'slot_size' => 15,
@@ -144,7 +144,7 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 			$url = 'http://'.$url;
 		return parent::_set('admin_url', $url);
 	}
-	
+
 
 	/**
 	 * @param $date string (YYYY-MM-DD)
@@ -161,8 +161,8 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 		};
 
 		$slots_for_interval = function($start, $end) use ($timestamp) {
-			return $this->getLoader()->getPossibleHours($this->getSlotSize(), 
-																									$timestamp($start), 
+			return $this->getLoader()->getPossibleHours($this->getSlotSize(),
+																									$timestamp($start),
 																									$timestamp($end));
 		};
 
@@ -170,12 +170,12 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 																									 $ouverture->getFinMatin()),
 															 $slots_for_interval($ouverture->getDebutApresMidi(),
 																									 $ouverture->getFinApresMidi()));
-		if (date('Y-m-d', $now) !== $date) 
+		if (date('Y-m-d', $now) !== $date)
 			return $start_times;
 
 		$hour = (int) date('H', $now);
 		$minute = (int) date('i', $now);
-		return array_filter($start_times, 
+		return array_filter($start_times,
 												function ($time) use ($hour, $minute) {
 													$parts = explode('h', $time);
 													return ($hour < (int)$parts[0])
@@ -206,29 +206,6 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 	}
 
 
-	/**
-	 * @category testing
-	 * @return int
-	 */
-	public function getCurrentTime() {
-		return self::getTimeSource()->time();
-	}
-
-
-	/** @return Class_TimeSource */
-	public static function getTimeSource() {
-		if (null == self::$_time_source)
-			self::$_time_source = new Class_TimeSource();
-		return self::$_time_source;
-	}
-
-
-	/** @param $time_source Class_TimeSource */
-	public static function setTimeSource($time_source) {
-		self::$_time_source = $time_source;
-	}
-
-
 
 	public function getOuvertureForDate($date) {
 		if (is_string($date))
@@ -245,6 +222,20 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 			if ($ouverture->getJourSemaine() == $dow)
 				return $ouverture;
 		}
+
+		if($this->getAutoholdForClosingDays()){
+			$middleTime = strtotime('12:00:00');
+			$ouverture = Class_Ouverture::newInstance();
+			if(strtotime($this->getOpenHour()) < $middleTime){
+				$ouverture->setHoraires([$this->getOpenHour(), '12:00', '12:00', $this->getCloseHour()]);
+			}
+			else {
+				$ouverture->setHoraires(['12:00', '12:00', $this->getOpenHour(), $this->getCloseHour()]);
+			}
+			return $ouverture;
+		}
+
+
 	}
 
 
@@ -255,7 +246,7 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 	public function getMinTimeForDate($date) {
 		if ($ouverture = $this->getOuvertureForDate($date))
 			return strtotime($date . ' ' . $ouverture->getDebutMatin() . ':00');
-			
+
 		return strtotime($date . ' 00:00:00');
 	}
 
@@ -277,7 +268,7 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 			return 0;
 		return $ouverture->getNextCloseFrom($this->getCurrentTime());
 	}
-	
+
 
 	/** @return array */
 	public function getDurations() {
@@ -306,7 +297,7 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 		$holdables = array();
 		foreach ($this->getGroups() as $group)
 			$holdables += $group->getHoldableDevicesForDateTimeAndDuration($date, $time, $duration);
-				
+
 		shuffle($holdables);
 		if (3 < count($holdables))
 			return array_slice($holdables, 0, 3);
@@ -326,8 +317,8 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 
 		return strtotime('+' . $delay . ' day', $this->getTimeSource()->time());
 	}
-	
-		
+
+
 	/** @return string formatted date YYYY-MM-DD */
 	public function getMaxDate() {
 		return date('Y-m-d', $this->getMaxDateTimeStamp());
@@ -356,13 +347,13 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
 		$all_days = Class_Date::dateRange($this->getMinDateTimeStamp(),
 																			$this->getMaxDateTimeStamp());
 
-		return array_values(array_filter($all_days, 
+		return array_values(array_filter($all_days,
 																		 function ($day) {
 																			 return (null !== $this->getOuvertureForDate($day));
 																		 }));
 	}
 
-		
+
 	public function beforeSave() {
 		if (is_array($days = $this->getDays()))
 			$this->setDays(implode(',', $days));
diff --git a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
index b9259d9266a..7fbff892dc5 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
@@ -16,7 +16,7 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 require_once 'AbstractControllerTestCase.php';
@@ -28,17 +28,17 @@ trait TAbonneControllerMultimediaFixtureHoldSuccessOnSept12 {
 			->whenCalled('findByIdOrigine')
 			->answers(Class_Multimedia_Location::newInstanceWithId(1));
 
-				
+
 		$this->onLoaderOfModel('Class_Multimedia_Device')
 			->whenCalled('findByIdOrigineAndLocation')
 			->answers(Class_Multimedia_Device::newInstanceWithId(1));
-				
+
 		$this->onLoaderOfModel('Class_Multimedia_DeviceHold')
 			->whenCalled('getHoldOnDeviceAtTime')
 			->answers(Class_Multimedia_DeviceHold::newInstanceWithId(333)
 				->setIdUser($this->_user->getId())
 				->setEnd(strtotime('2012-09-12 16:40:00')));
-				
+
 		parent::_launch();
 	}
 }
@@ -69,7 +69,7 @@ abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractCo
 			->whenCalled('getIdentity')->answers(null)
 			->whenCalled('newAuthSIGB')->answers('auth_sigb')
 			->whenCalled('newAuthDb')->answers('auth_db');
-		
+
 		ZendAfi_Auth::setInstance($this->_auth);
 	}
 
@@ -108,7 +108,7 @@ abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractCo
 			->whenCalled('findFirstBy')
 			->with(array('login'=> $user->getLogin()))
 			->answers($user)
-				
+
 			->whenCalled('findFirstBy')
 			->answers(null);
 	}
@@ -130,7 +130,7 @@ abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractCo
 
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_UserGroup')
 			->whenCalled('findAllBy')
-			->with(['role_level' => $user->getRoleLevel(), 
+			->with(['role_level' => $user->getRoleLevel(),
 							'group_type' => Class_UserGroup::TYPE_DYNAMIC])
 			->answers([]);
 	}
@@ -143,7 +143,7 @@ class AbonneControllerMultimediaAuthenticateValidationTest extends AbonneControl
 	public function setUp() {
 		parent::setUp();
 		$this->_expectUserToLoad(AbonneControllerMultimediaUsersFixtures::getLaurent());
-	}		
+	}
 
 
 	/** @test */
@@ -185,7 +185,7 @@ class AbonneControllerMultimediaAuthenticateValidationTest extends AbonneControl
 	/** @test */
 	public function authenticateAbonneLaurentPasswordXXXShouldReturnWrongPassword() {
 		$json = $this->getJson('/abonne/authenticate/login/laurent/password/xxx/poste/1/site/1');
-		$this->assertEquals("PasswordIsWrong", $json->error);	
+		$this->assertEquals("PasswordIsWrong", $json->error);
 	}
 }
 
@@ -204,7 +204,7 @@ class AbonneControllerMultimediaAuthenticateMireilleTest extends AbonneControlle
 
 	/** @test */
 	public function shouldReturnSubscriptionExpired() {
-		$this->assertEquals('SubscriptionExpired', $this->_json->error);	
+		$this->assertEquals('SubscriptionExpired', $this->_json->error);
 	}
 
 
@@ -245,28 +245,28 @@ abstract class AbonneControllerMultimediaAuthenticateValidTestCase extends Abonn
 
 
 class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneControllerMultimediaAuthenticateValidTestCase {
-	use 
+	use
 		TAbonneControllerMultimediaFixtureHoldSuccessOnSept12,
 		TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
-	
+
 	/** @test */
 	public function shouldNotReturnError() {
 		$this->assertFalse(property_exists($this->_json, 'error'));
 	}
-	
-	
+
+
 	/** @test */
 	public function idShoudBe8() {
 		$this->assertEquals('8', $this->_json->id);
 	}
-	
-	
+
+
 	/** @test */
 	public function loginShoudBelaurent() {
 		$this->assertEquals('laurent', $this->_json->login);
 	}
-	
-	
+
+
 	/** @test */
 	public function passwordShoudBeAfi() {
 		$this->assertEquals('afi', $this->_json->password);
@@ -277,14 +277,14 @@ class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneController
 	public function nomShoudBelaffont() {
 		$this->assertEquals('laffont', $this->_json->nom);
 	}
-	
-	
+
+
 	/** @test */
 	public function prenomShoudBelaurent() {
 		$this->assertEquals('laurent', $this->_json->prenom);
 	}
-	
-	
+
+
 	/** @test */
 	public function dateNaissanceShoudBe1978_02_17() {
 		$this->assertEquals('1978/02/17', $this->_json->date_naissance);
@@ -311,6 +311,92 @@ class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneController
 }
 
 
+class AbonneControllerMultimediaAuthenticateLaurentAtClosingDaysDeviceHoldByUserTest extends AbonneControllerMultimediaAuthenticateValidTestCase {
+	use TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
+
+	protected function _launch() {
+
+		Class_Multimedia_Location::setTimeSource(new TimeSourceForTest('2012-09-12 09:30:00'));
+
+		$this->onLoaderOfModel('Class_Multimedia_Location')
+			->whenCalled('findByIdOrigine')
+			->answers($location = Class_Multimedia_Location::newInstanceWithId(1)
+								->setSlotSize(30)
+								->setAutoholdSlotsMax(1)
+								->setAuthDelay(1)
+								->setAutohold(1)
+								->setOuvertures([])
+								->setAutoholdForClosingDays(1)
+								->setOpenHour('09:00')
+								->setCloseHour('17:00'));
+
+		$this->onLoaderOfModel('Class_Multimedia_Device')
+			->whenCalled('findByIdOrigineAndLocation')
+			->answers(Class_Multimedia_Device::newInstanceWithId(1)
+								->setGroup(Class_Multimedia_DeviceGroup::newInstanceWithId(34)->setLocation($location)));
+
+
+		$this->onLoaderOfModel('Class_Multimedia_DeviceHold')
+			->whenCalled('getHoldOnDeviceAtTime')
+			->answers(null);
+
+		parent::_launch();
+	}
+
+
+	/** @test */
+	public function shouldHaveHold() {
+		$this->assertEquals(1, $this->_json->auth);
+	}
+
+	/** @test */
+	public function holdShouldLastUntil16h40() {
+		$this->assertEquals('2012-09-12T10:00:00+02:00', $this->_json->until);
+	}
+
+
+}
+
+
+class AbonneControllerMultimediaAuthenticateLaurentAtClosingDaysDeviceNotHeldByUserTest extends AbonneControllerMultimediaAuthenticateValidTestCase {
+	use TAbonneControllerMultimediaFixtureWithUserLaurentInDevsAgiles;
+
+	protected function _launch() {
+
+		Class_Multimedia_Location::setTimeSource(new TimeSourceForTest('2012-09-12 09:30:00'));
+
+		$this->onLoaderOfModel('Class_Multimedia_Location')
+			->whenCalled('findByIdOrigine')
+			->answers($location = Class_Multimedia_Location::newInstanceWithId(1)
+								->setAuthDelay(1)
+								->setAutohold(1)
+								->setOuvertures([])
+								->setAutoholdForClosingDays(0)
+								->setOpenHour('09:00')
+								->setCloseHour('17:00'));
+
+		$this->onLoaderOfModel('Class_Multimedia_Device')
+			->whenCalled('findByIdOrigineAndLocation')
+			->answers(Class_Multimedia_Device::newInstanceWithId(1)
+								->setGroup(Class_Multimedia_DeviceGroup::newInstanceWithId(34)->setLocation($location)));
+
+
+		$this->onLoaderOfModel('Class_Multimedia_DeviceHold')
+			->whenCalled('getHoldOnDeviceAtTime')
+			->answers(null);
+
+		parent::_launch();
+	}
+
+
+	/** @test */
+	public function shouldHaveHold() {
+		$this->assertEquals(0, $this->_json->auth);
+	}
+
+
+}
+
 
 
 class AbonneControllerMultimediaAuthenticateLaurentDeviceNotHeldByUserTest extends AbonneControllerMultimediaAuthenticateValidTestCase {
@@ -319,7 +405,7 @@ class AbonneControllerMultimediaAuthenticateLaurentDeviceNotHeldByUserTest exten
 	protected function _launch() {
 		$this->onLoaderOfModel('Class_Multimedia_Location')
 			->whenCalled('findByIdOrigine')
-			->answers($location = Class_Multimedia_Location::newInstanceWithId(1)								
+			->answers($location = Class_Multimedia_Location::newInstanceWithId(1)
 								->setAuthDelay(1)
 								->setAutohold(1));
 
@@ -334,7 +420,7 @@ class AbonneControllerMultimediaAuthenticateLaurentDeviceNotHeldByUserTest exten
 								->setIdUser(9878)
 								->setStart(strtotime('2012-09-12 08:30:00'))
 								->setEnd(strtotime('2012-09-12 16:40:00')));
-				
+
 		parent::_launch();
 	}
 
@@ -370,7 +456,7 @@ class AbonneControllerMultimediaAuthenticateLaurentDeviceNotFoundTest extends Ab
 		$this->onLoaderOfModel('Class_Multimedia_Device')
 			->whenCalled('findByIdOrigineAndLocation')
 			->answers(null);
-				
+
 		parent::_launch();
 	}
 
@@ -400,7 +486,7 @@ class AbonneControllerMultimediaAuthenticateArnaudTest extends AbonneControllerM
 
 	/** @test */
 	public function groupsShouldBeAbonneAndPatrons() {
-		$this->assertEquals(array('abonne_sigb', 'Patrons'), $this->_json->groupes);	
+		$this->assertEquals(array('abonne_sigb', 'Patrons'), $this->_json->groupes);
 	}
 
 
@@ -421,11 +507,11 @@ class AbonneControllerMultimediaAuthenticateBaptisteTest extends AbonneControlle
 		$this->_group= 'Devs Oldschool';
 	}
 
-		
+
 	/** @test */
 	public function groupsShouldBeMineurAbonneAndOldSchool() {
-		$this->assertEquals(['mineur','abonne_sigb', 'Devs Oldschool'], 
-												$this->_json->groupes);	
+		$this->assertEquals(['mineur','abonne_sigb', 'Devs Oldschool'],
+												$this->_json->groupes);
 	}
 
 
@@ -448,7 +534,7 @@ class AbonneControllerMultimediaAuthenticateBaptisteTest extends AbonneControlle
 abstract class AbonneControllerMultimediaHoldTestCase extends AbstractControllerTestCase {
 	protected $_session;
 	protected $_bean;
-	
+
 	public function setUp() {
 		parent::setUp();
 		$this->_session = new Zend_Session_Namespace('abonneController');
@@ -459,7 +545,7 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 											 ->setMaxDay(120)
 											 ->setMaxWeek(240)
 											 ->setMaxMonth(360)]);
-				
+
 		$this
 			->onLoaderOfModel('Class_Multimedia_DeviceHold')
 			->whenCalled('getDurationForUserBetweenTimes')
@@ -473,7 +559,7 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 		Class_Bib::newInstanceWithId(3)
 			->setLibelle('Médiathèque d\'Antibes');
 
-		
+
 		Class_Multimedia_Location::newInstanceWithId(123)
 			->setIdSite(3)
 			->setLibelle('Antibes')
@@ -531,7 +617,7 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 		$this->_bean->group = 5;
 	}
 
-	
+
 	protected function _assertCurrentTimelineStep($step) {
 		$this->_assertTimeLineStepWithClass($step, 'selected');
 	}
@@ -592,7 +678,7 @@ abstract class AbonneControllerMultimediaHoldLocationTest extends AbonneControll
 	public function currentTimelineStepShouldBeLieu() {
 		$this->_assertCurrentTimelineStep('Lieu');
 	}
-		
+
 
 	/** @test */
 	public function locationSalle1ShouldBePresent() {
@@ -707,7 +793,7 @@ class AbonneControllerMultimediaHoldDayChoiceWithOverQuotaTest extends AbonneCon
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
 			->whenCalled('getDurationForUserBetweenTimes')
 			->answers(8000);
-				
+
 		$this->dispatch('/abonne/multimedia-hold-day/day/2012-09-12', true);
 	}
 
@@ -745,7 +831,7 @@ class AbonneControllerMultimediaHoldHoursTest extends AbonneControllerMultimedia
 	public function currentTimelineStepShouldBeHoraires() {
 		$this->_assertCurrentTimelineStep('Horaires');
 	}
-		
+
 
 	/** @test */
 	public function listOfStartTimesShouldBePresent() {
@@ -942,7 +1028,7 @@ class AbonneControllerMultimediaHoldDeviceTest extends AbonneControllerMultimedi
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
 				->whenCalled('countBy')
 				->answers(0);
-				
+
 		$this->dispatch('/abonne/multimedia-hold-device', true);
 	}
 
@@ -1030,7 +1116,7 @@ class AbonneControllerMultimediaHoldConfirmTest extends AbonneControllerMultimed
 		$this->_assertCurrentTimelineStep('Confirmation');
 	}
 
-		
+
 	/** @test */
 	public function locationShouldBeAntibes() {
 		$this->assertXPathContentContains('//li', 'Lieu : Médiathèque d\'Antibes');
@@ -1161,7 +1247,7 @@ class AbonneControllerMultimediaHoldViewTest extends AbonneControllerMultimediaH
 
 class AbonneControllerMultimediaHoldViewDeleteTest extends AbonneControllerMultimediaHoldTestCase {
 	protected $_wrapper;
-	
+
 	public function setUp() {
 		parent::setUp();
 		Class_Multimedia_DeviceHold::getLoader()->newInstanceWithId(455)
@@ -1178,7 +1264,7 @@ class AbonneControllerMultimediaHoldViewDeleteTest extends AbonneControllerMulti
 		$this->assertTrue($this->_wrapper->methodHasBeenCalled('delete'));
 	}
 
-		
+
 	/** @test */
 	public function shouldRedirectToFicheAbonne() {
 		$this->assertRedirectTo('/abonne/fiche');
diff --git a/tests/library/Class/Multimedia/LocationTest.php b/tests/library/Class/Multimedia/LocationTest.php
index 6ded0df170c..652087850c4 100644
--- a/tests/library/Class/Multimedia/LocationTest.php
+++ b/tests/library/Class/Multimedia/LocationTest.php
@@ -17,7 +17,7 @@
  *
  * 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 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 require_once 'ModelTestCase.php';
 
@@ -31,7 +31,7 @@ abstract class Multimedia_LocationWithBibTestCase extends Storm_Test_ModelTestCa
 
 		$_ouverture_19_sept = Class_Ouverture::newInstanceWithId(5)
 			->setJour('2012-09-19')
-			->setHoraires(['09:00', '12:00', '12:00', '18:00']);
+			->setHoraires(['09:00', '12:00', '12:00', '18:0mysql0']);
 
 		$_ouverture_dimanche_9_sept = Class_Ouverture::newInstanceWithId(15)
 			->setJour('2012-09-09')
@@ -83,14 +83,14 @@ class Multimedia_LocationWithBibTest extends Multimedia_LocationWithBibTestCase
 	/** @test */
 	public function bibShouldHaveOuvertureForMercredi() {
 		Class_Bib::find(3)->getOuvertures();
-		$this->assertEquals(Class_Ouverture::MERCREDI, 
+		$this->assertEquals(Class_Ouverture::MERCREDI,
 												Class_Bib::find(3)->getOuvertures()[0]->getJourSemaine());
 	}
 
 
 	/** @test */
 	public function bibShouldHaveOuvertureForJeudi() {
-		$this->assertEquals(Class_Ouverture::JEUDI, 
+		$this->assertEquals(Class_Ouverture::JEUDI,
 												Class_Bib::find(3)->getOuvertures()[1]->getJourSemaine());
 	}
 
@@ -104,7 +104,7 @@ class Multimedia_LocationWithBibTest extends Multimedia_LocationWithBibTestCase
 
 	/** @test */
 	public function getMinTimeFor8Aug2012ShouldReturnDebutMatinOfMercredi() {
-		$this->assertEquals(strtotime('2012-08-08 08:30:00'), 
+		$this->assertEquals(strtotime('2012-08-08 08:30:00'),
 												$this->_location->getMinTimeForDate('2012-08-08'),
 												'getMinTimeForDate => '.strftime('%Y-%m-%d %H:%M:%S',
 																												 $this->_location->getMinTimeForDate('2012-08-08')));
@@ -113,33 +113,33 @@ class Multimedia_LocationWithBibTest extends Multimedia_LocationWithBibTestCase
 
 	/** @test */
 	public function getMaxTimeFor8Aug2012ShouldReturnFinApresMidiOfMercredi() {
-		$this->assertEquals(strtotime('2012-08-08 17:45:00'), 
+		$this->assertEquals(strtotime('2012-08-08 17:45:00'),
 												$this->_location->getMaxTimeForDate('2012-08-08'));
 	}
 
 
 	/** @test */
 	public function getMinTimeFor9Aug2012ShouldReturnDebutMatinOfJeudi() {
-		$this->assertEquals(strtotime('2012-08-09 10:00:00'), 
+		$this->assertEquals(strtotime('2012-08-09 10:00:00'),
 												$this->_location->getMinTimeForDate('2012-08-09'));
 	}
 
 
 	/** @test */
 	public function getMinTimeFor19Sept2012ShouldReturn0900() {
-		$this->assertTimeStampEquals('2012-09-19 09:00:00', 
+		$this->assertTimeStampEquals('2012-09-19 09:00:00',
 																 $this->_location->getMinTimeForDate('2012-09-19'));
 	}
 
 
 	/** @test */
 	public function getStartTimesFor8AugShouldReturnAllHalfHoursFrom_0830_to_1730() {
-		$this->assertEquals(['08:30' => '08h30', '09:00' => '09h00', '09:30' => '09h30', '10:00' => '10h00', '10:30' => '10h30', 
-												 '11:00' => '11h00', '11:30' => '11h30', '12:00' => '12h00', '12:30' => '12h30', '13:00' => '13h00', 
-												 '13:30' => '13h30', '14:00' => '14h00', '14:30' => '14h30', '15:00' => '15h00', '15:30' => '15h30', 
-												 '16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30'], 
+		$this->assertEquals(['08:30' => '08h30', '09:00' => '09h00', '09:30' => '09h30', '10:00' => '10h00', '10:30' => '10h30',
+												 '11:00' => '11h00', '11:30' => '11h30', '12:00' => '12h00', '12:30' => '12h30', '13:00' => '13h00',
+												 '13:30' => '13h30', '14:00' => '14h00', '14:30' => '14h30', '15:00' => '15h00', '15:30' => '15h30',
+												 '16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30'],
 												$this->_location->getStartTimesForDate('2012-08-08'));
-		
+
 	}
 
 
@@ -147,20 +147,20 @@ class Multimedia_LocationWithBibTest extends Multimedia_LocationWithBibTestCase
 	/** @test */
 	public function getStartTimesFor8AugAt8Aug1543ShouldReturnAllHalfHoursFrom_1600_to_1730() {
 		$this->_time_source->setTime(strtotime('2012-08-08 15:45'));
-		$this->assertEquals(['16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30'], 
+		$this->assertEquals(['16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30'],
 												$this->_location->getStartTimesForDate('2012-08-08'));
-		
+
 	}
 
 
 	/** @test */
 	public function getStartTimesFor9AugShouldReturnAllHalfHoursFrom_1000_to_1130_then_1400_to_1830() {
-		$this->assertEquals(['10:00' => '10h00', '10:30' => '10h30', '11:00' => '11h00', '11:30' => '11h30', 
-												 '14:00' => '14h00', '14:30' => '14h30', '15:00' => '15h00', '15:30' => '15h30', 
+		$this->assertEquals(['10:00' => '10h00', '10:30' => '10h30', '11:00' => '11h00', '11:30' => '11h30',
+												 '14:00' => '14h00', '14:30' => '14h30', '15:00' => '15h00', '15:30' => '15h30',
 												 '16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30',
-												 '18:00' => '18h00', '18:30' => '18h30'], 
+												 '18:00' => '18h00', '18:30' => '18h30'],
 												$this->_location->getStartTimesForDate('2012-08-09'));
-		
+
 	}
 
 
@@ -174,8 +174,9 @@ class Multimedia_LocationWithBibTest extends Multimedia_LocationWithBibTestCase
 	/** @test */
 	public function getDatesOuvertureShouldAnswersAllMercrediJeudiForNextTwoMonthsWith9and19Sept() {
 		$this->_time_source->setTime(strtotime('2012-08-05'));
-		$this->_location->setHoldDelayMax(60);
-		$this->assertEquals(['2012-08-08', '2012-08-09', 
+		$this->_location->setHoldDelayMax(60)
+										->setAutoholdForClosingDays(false);
+		$this->assertEquals(['2012-08-08', '2012-08-09',
 												 '2012-08-15', '2012-08-16',
 												 '2012-08-22', '2012-08-23',
 												 '2012-08-29', '2012-08-30',
@@ -187,6 +188,28 @@ class Multimedia_LocationWithBibTest extends Multimedia_LocationWithBibTestCase
 												 '2012-10-03', '2012-10-04'],
 												$this->_location->getHoldableDays());
 	}
+
+	/** @test */
+	public function getDatesOuvertureMardiClosingDayShouldAnswersOpenHour0800() {
+		$this->_time_source->setTime(strtotime('2012-12-04'));
+		$this->_location->setAutoholdForClosingDays(true)
+										->setOpenHour('08:00')
+										->setCloseHour('17:00');
+
+		$this->assertEquals('08:00', $this->_location->getOuvertureForDate($this->_time_source->time())->getDebutMatin());
+
+	}
+
+	/** @test */
+	public function getDatesOuvertureMardiClosingDayShouldAnswersCloseHour1700() {
+		$this->_time_source->setTime(strtotime('2012-12-04'));
+		$this->_location->setAutoholdForClosingDays(true)
+										->setOpenHour('08:00')
+										->setCloseHour('17:00');
+
+		$this->assertEquals('17:00', $this->_location->getOuvertureForDate($this->_time_source->time())->getFinApresMidi());
+
+	}
 }
 
 
-- 
GitLab