From 030c0d5ab6e7252081c2de6657c0b17e697bd723 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Mon, 6 Aug 2012 16:49:44 +0000
Subject: [PATCH] =?UTF-8?q?Multim=C3=A9dia:=20branchement=20des=20r=C3=A9s?=
 =?UTF-8?q?ervations=20automatiques=20sur=20le=20planning=20des=20ouvertur?=
 =?UTF-8?q?es?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 library/Class/Ouverture.php                   |  14 +-
 .../AbonneControllerMultimediaTest.php        | 132 +++++++++++++-----
 tests/library/Class/Multimedia/DeviceTest.php |  40 ++++--
 .../library/Class/Multimedia/LocationTest.php |  22 ++-
 4 files changed, 155 insertions(+), 53 deletions(-)

diff --git a/library/Class/Ouverture.php b/library/Class/Ouverture.php
index c49d6583038..468ba464c1e 100644
--- a/library/Class/Ouverture.php
+++ b/library/Class/Ouverture.php
@@ -37,10 +37,16 @@ class Class_Ouverture extends Storm_Model_Abstract {
 
 		return static::getLoader()->newInstance()
 			->setJourSemaine(constant('Class_Ouverture::'.strtoupper($matches[1])))
-			->setDebutMatin($args[0])
-			->setFinMatin($args[1])
-			->setDebutApresMidi($args[2])
-			->setFinApresMidi($args[3]);
+			->setHoraires($args);
+	}
+
+
+	public function setHoraires($horaires) {
+		return $this
+			->setDebutMatin($horaires[0])
+			->setFinMatin($horaires[1])
+			->setDebutApresMidi($horaires[2])
+			->setFinApresMidi($horaires[3]);
 	}
 
 
diff --git a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
index 3dcb308e5ef..870da0c259c 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
@@ -71,6 +71,8 @@ abstract class AbonneControllerMultimediaAuthenticateTestCase extends AbstractCo
 }
 
 
+
+
 class AbonneControllerMultimediaAuthenticateValidationTest extends AbonneControllerMultimediaAuthenticateTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -114,6 +116,8 @@ class AbonneControllerMultimediaAuthenticateValidationTest extends AbonneControl
 }
 
 
+
+
 class AbonneControllerMultimediaAuthenticateMireilleTest extends AbonneControllerMultimediaAuthenticateTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -131,6 +135,8 @@ class AbonneControllerMultimediaAuthenticateMireilleTest extends AbonneControlle
 }
 
 
+
+
 abstract class AbonneControllerMultimediaAuthenticateValidTestCase extends AbonneControllerMultimediaAuthenticateTestCase {
 	protected $_user;
 	protected $_group;
@@ -156,6 +162,8 @@ abstract class AbonneControllerMultimediaAuthenticateValidTestCase extends Abonn
 }
 
 
+
+
 class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneControllerMultimediaAuthenticateValidTestCase {
 	protected function _initUser() {
 		$this->_user = AbonneControllerMultimediaUsersFixtures::getLaurent();
@@ -164,19 +172,19 @@ class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneController
 
 		
 	protected function _launch() {
-		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_Location')
+		$this->onLoaderOfModel('Class_Multimedia_Location')
 			->whenCalled('findByIdOrigine')
-			->answers(Class_Multimedia_Location::getLoader()->newInstanceWithId(1));
+			->answers(Class_Multimedia_Location::newInstanceWithId(1));
 				
-		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_Device')
+		$this->onLoaderOfModel('Class_Multimedia_Device')
 			->whenCalled('findByIdOrigineAndLocation')
-			->answers(Class_Multimedia_Device::getLoader()->newInstanceWithId(1));
+			->answers(Class_Multimedia_Device::newInstanceWithId(1));
 				
-		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
+		$this->onLoaderOfModel('Class_Multimedia_DeviceHold')
 			->whenCalled('getHoldOnDeviceAtTime')
-			->answers(Class_Multimedia_DeviceHold::getLoader()->newInstanceWithId(333)
+			->answers(Class_Multimedia_DeviceHold::newInstanceWithId(333)
 				->setIdUser($this->_user->getId())
-				->setEnd(strtotime('2012-09-09 16:40:00')));
+				->setEnd(strtotime('2012-09-12 16:40:00')));
 				
 		parent::_launch();
 	}
@@ -239,11 +247,13 @@ class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneController
 
 	/** @test */
 	public function holdShouldLastUntil16h40() {
-		$this->assertEquals('2012-09-09T16:40:00+02:00', $this->_json->until);
+		$this->assertEquals('2012-09-12T16:40:00+02:00', $this->_json->until);
 	}
 }
 
 
+
+
 class AbonneControllerMultimediaAuthenticateArnaudTest extends AbonneControllerMultimediaAuthenticateValidTestCase {
 	protected function _initUser() {
 		$this->_user = AbonneControllerMultimediaUsersFixtures::getArnaud();
@@ -271,6 +281,8 @@ class AbonneControllerMultimediaAuthenticateBaptisteTest extends AbonneControlle
 }
 
 
+
+/* Début test du workflow de réservation */
 abstract class AbonneControllerMultimediaHoldTestCase extends AbstractControllerTestCase {
 	protected $_session;
 	protected $_bean;
@@ -286,14 +298,14 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 		$bean->device = 0;
 		$this->_session->holdBean = $this->_bean = $bean;
 
-		Class_Users::getLoader()->getIdentity()->setUserGroups(array(
-				Class_UserGroup::getLoader()
-				->newInstanceWithId(12)
-				->setMaxDay(120)
-				->setMaxWeek(240)
-				->setMaxMonth(360)));
+		Class_Users::getIdentity()
+			->setUserGroups([Class_UserGroup::newInstanceWithId(12)
+											 ->setMaxDay(120)
+											 ->setMaxWeek(240)
+											 ->setMaxMonth(360)]);
 				
-		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
+		$this
+			->onLoaderOfModel('Class_Multimedia_DeviceHold')
 			->whenCalled('getDurationForUserBetweenTimes')
 			->answers(0);
 	}
@@ -301,21 +313,25 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 
 	protected function _prepareLocationInSession() {
 		$this->_bean->location = 123;
-		Class_Multimedia_Location::getLoader()
-				->newInstanceWithId(123)
-				->setLibelle('Antibes')
-				->setSlotSize(30)
-				->setMaxSlots(4)
-				->setHoldDelayMin(0)
-				->setHoldDelayMax(60)
-				->setDays('3,4')
-				->setOpenHour('08:30')
-				->setCloseHour('17:45');
+
+		Class_Bib::newInstanceWithId(3)
+			->setLibelle('Antibes');
+			
+		Class_Multimedia_Location::newInstanceWithId(123)
+			->setIdSite(3)
+			->setLibelle('Antibes')
+			->setSlotSize(30)
+			->setMaxSlots(4)
+			->setHoldDelayMin(0)
+			->setHoldDelayMax(60)
+			->setOuvertures([Class_Ouverture::chaqueLundi('08:30', '12:00', '12:00', '17:45')->setId(1)->cache(),
+											 Class_Ouverture::chaqueMercredi('08:30', '12:00', '12:00', '17:45')->setId(3)->cache(),
+											 Class_Ouverture::chaqueJeudi('08:30', '12:00', '12:00', '17:45')->setId(4)->cache()]);
 	}
 
 
 	protected function _prepareDayInSession() {
-		$this->_bean->day = '2012-09-09';
+		$this->_bean->day = '2012-09-12';
 	}
 
 
@@ -342,6 +358,9 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 }
 
 
+
+
+/* Premier écran de choix du lieu */
 class AbonneControllerMultimediaHoldLocationTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -375,6 +394,9 @@ class AbonneControllerMultimediaHoldLocationTest extends AbonneControllerMultime
 }
 
 
+
+
+/* Validation du lieu, on est redirigé sur l'écran choix du jour */
 class AbonneControllerMultimediaHoldLocationChoiceTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -395,6 +417,9 @@ class AbonneControllerMultimediaHoldLocationChoiceTest extends AbonneControllerM
 }
 
 
+
+
+/* Second écran choix du jour */
 class AbonneControllerMultimediaHoldDayTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -422,11 +447,14 @@ class AbonneControllerMultimediaHoldDayTest extends AbonneControllerMultimediaHo
 }
 
 
+
+
+/* Validation du second écran choix du jour, redirection vers le choix de l'heure */
 class AbonneControllerMultimediaHoldDayChoiceTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
 		$this->_prepareLocationInSession();
-		$this->dispatch('/abonne/multimedia-hold-day/day/2012-09-09', true);
+		$this->dispatch('/abonne/multimedia-hold-day/day/2012-09-12', true);
 	}
 
 
@@ -438,11 +466,14 @@ class AbonneControllerMultimediaHoldDayChoiceTest extends AbonneControllerMultim
 
 	/** @test */
 	public function beanShouldHaveDaySet() {
-		$this->assertEquals('2012-09-09', $this->_session->holdBean->day);
+		$this->assertEquals('2012-09-12', $this->_session->holdBean->day);
 	}
 }
 
 
+
+
+/* Validation du second écran mais l'utilisateur a dépassé son quota de réservation */
 class AbonneControllerMultimediaHoldDayChoiceWithOverQuotaTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -452,7 +483,7 @@ class AbonneControllerMultimediaHoldDayChoiceWithOverQuotaTest extends AbonneCon
 			->whenCalled('getDurationForUserBetweenTimes')
 			->answers(8000);
 				
-		$this->dispatch('/abonne/multimedia-hold-day/day/2012-09-09', true);
+		$this->dispatch('/abonne/multimedia-hold-day/day/2012-09-12', true);
 	}
 
 
@@ -469,6 +500,10 @@ class AbonneControllerMultimediaHoldDayChoiceWithOverQuotaTest extends AbonneCon
 }
 
 
+
+
+
+/* Troisième écran choix de l'heure de début de réservation */
 class AbonneControllerMultimediaHoldHoursTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -477,7 +512,7 @@ class AbonneControllerMultimediaHoldHoursTest extends AbonneControllerMultimedia
 
 		Class_Multimedia_Location::setTimeSource(Storm_Test_ObjectWrapper::mock()
 			->whenCalled('time')
-			->willDo(function() {return strtotime('2012-09-09 09:00:00');}));
+			->willDo(function() {return strtotime('2012-09-12 09:00:00');}));
 
 		$this->dispatch('/abonne/multimedia-hold-hours', true);
 	}
@@ -491,7 +526,7 @@ class AbonneControllerMultimediaHoldHoursTest extends AbonneControllerMultimedia
 
 	/** @test */
 	public function listOfStartTimesShouldBePresent() {
-		$this->assertXPathCount('//select[@id="time"]/option', 18);
+		$this->assertXPathCount('//select[@id="time"]/option', 18, $this->_response->getBody());
 	}
 
 
@@ -520,6 +555,9 @@ class AbonneControllerMultimediaHoldHoursTest extends AbonneControllerMultimedia
 }
 
 
+
+
+/* Troisième écran choix de l'heure, redirection sur le choix du poste */
 class AbonneControllerMultimediaHoldHoursChoiceTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -543,6 +581,9 @@ class AbonneControllerMultimediaHoldHoursChoiceTest extends AbonneControllerMult
 }
 
 
+
+
+/* Troisième écran choix d'une heure déjà allouée */
 class AbonneControllerMultimediaHoldHoursChooseAlreadyHeldTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -562,6 +603,9 @@ class AbonneControllerMultimediaHoldHoursChooseAlreadyHeldTest extends AbonneCon
 }
 
 
+
+
+/* Quatrième écran choix du poste */
 class AbonneControllerMultimediaHoldDeviceTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -603,6 +647,9 @@ class AbonneControllerMultimediaHoldDeviceTest extends AbonneControllerMultimedi
 }
 
 
+
+
+/* Quatrième écran validation du choix du poste, redirection vers la confirmation */
 class AbonneControllerMultimediaHoldDeviceChoiceTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -626,6 +673,9 @@ class AbonneControllerMultimediaHoldDeviceChoiceTest extends AbonneControllerMul
 }
 
 
+
+
+/* Cinquième écran confirmation de la réservation */
 class AbonneControllerMultimediaHoldConfirmTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -653,8 +703,8 @@ class AbonneControllerMultimediaHoldConfirmTest extends AbonneControllerMultimed
 
 
 	/** @test */
-	public function dayShouldBeSeptemberNine2012() {
-		$this->assertXPathContentContains('//li', 'Jour : 09 septembre 2012');
+	public function dayShouldBeSeptemberTwelve2012() {
+		$this->assertXPathContentContains('//li', 'Jour : 12 septembre 2012');
 	}
 
 
@@ -683,6 +733,9 @@ class AbonneControllerMultimediaHoldConfirmTest extends AbonneControllerMultimed
 }
 
 
+
+
+/* Cinquième écran, réservation confirmée */
 class AbonneControllerMultimediaHoldConfirmValidatedTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -708,6 +761,9 @@ class AbonneControllerMultimediaHoldConfirmValidatedTest extends AbonneControlle
 }
 
 
+
+
+/* Sixième écran, visualisation de la réservation */
 class AbonneControllerMultimediaHoldViewTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -733,7 +789,7 @@ class AbonneControllerMultimediaHoldViewTest extends AbonneControllerMultimediaH
 
 
 	/** @test */
-	public function dayShouldBeSeptemberNine2012() {
+	public function dayShouldBeSeptemberTwentyHeight2012() {
 		$this->assertXPathContentContains('//li', 'Jour : 28 décembre 2012');
 	}
 
@@ -763,6 +819,8 @@ class AbonneControllerMultimediaHoldViewTest extends AbonneControllerMultimediaH
 }
 
 
+
+
 class AbonneControllerMultimediaHoldViewDeleteTest extends AbonneControllerMultimediaHoldTestCase {
 	protected $_wrapper;
 	
@@ -790,6 +848,8 @@ class AbonneControllerMultimediaHoldViewDeleteTest extends AbonneControllerMulti
 }
 
 
+
+
 class AbonneControllerMultimediaHoldViewOfAnotherUserTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -806,6 +866,8 @@ class AbonneControllerMultimediaHoldViewOfAnotherUserTest extends AbonneControll
 }
 
 
+
+
 class AbonneControllerMultimediaHoldFicheAbonneTest extends AbstractControllerTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -840,6 +902,8 @@ class AbonneControllerMultimediaHoldFicheAbonneTest extends AbstractControllerTe
 }
 
 
+
+
 class AbonneControllerMultimediaUsersFixtures {
 	public static function getLaurent() {
 		return Class_Users::getLoader()->newInstanceWithId(8)
diff --git a/tests/library/Class/Multimedia/DeviceTest.php b/tests/library/Class/Multimedia/DeviceTest.php
index 9a9a47dd835..9c5b755f707 100644
--- a/tests/library/Class/Multimedia/DeviceTest.php
+++ b/tests/library/Class/Multimedia/DeviceTest.php
@@ -31,14 +31,22 @@ abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase {
 	protected $_hold;
 	/** @var int */
 	protected $_time;
+	/** @var Class_Bib */
+	protected $_bib_antibes;
 
 	public function setUp() {
 		parent::setUp();
 
-		$this->_location = Class_Multimedia_Location::getLoader()->newInstanceWithId(2);
-		$this->_group = Class_Multimedia_DeviceGroup::getLoader()->newInstanceWithId(2)
+		$this->_bib_antibes = Class_Bib::newInstanceWithId(5)->setLibelle('Antibes');
+
+		$this->_location = Class_Multimedia_Location::newInstanceWithId(2)
+			->setBib($this->_bib_antibes)
+			->setOuvertures([]);
+
+		$this->_group = Class_Multimedia_DeviceGroup::newInstanceWithId(2)
 				->setLocation($this->_location);
-		$this->_device = Class_Multimedia_Device::getLoader()->newInstanceWithId(2)
+
+		$this->_device = Class_Multimedia_Device::newInstanceWithId(2)
 				->setGroup($this->_group);
 
 		$this->_time = strtotime('today');
@@ -161,11 +169,14 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterCloseHoursTe
 	public function setUp() {
 		parent::setUp();
 		$this->_location
-				->setAuthDelay(10)
-				->setAutohold(1)
-				->setSlotSize(15)
-				->setAutoholdSlotsMax(600)
-				->setCloseHour('10:00');
+			->setAuthDelay(10)
+			->setAutohold(1)
+			->setSlotSize(15)
+			->setAutoholdSlotsMax(600)
+			->addOuverture(Class_Ouverture::newInstanceWithId(5)
+										 ->setJourSemaine(date('w'))
+										 ->setBib($this->_bib_antibes)
+										 ->setHoraires(['08:00', '10:00', '10:00', '10:00']));
 		
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
 				->whenCalled('getHoldOnDeviceAtTime')
@@ -202,11 +213,14 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterNextHoldStar
 	public function setUp() {
 		parent::setUp();
 		$this->_location
-				->setAuthDelay(10)
-				->setAutohold(1)
-				->setSlotSize(15)
-				->setAutoholdSlotsMax(600)
-				->setCloseHour('23:00');
+			->setAuthDelay(10)
+			->setAutohold(1)
+			->setSlotSize(15)
+			->setAutoholdSlotsMax(600)
+			->addOuverture(Class_Ouverture::newInstanceWithId(5)
+										 ->setBib($this->_bib_antibes)
+										 ->setJourSemaine(date('w'))
+										 ->setHoraires(['08:00', '12:00', '14:00', '23:00']));
 
 		$this->_nextStartTime = $this->_time + (60 * 60);
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
diff --git a/tests/library/Class/Multimedia/LocationTest.php b/tests/library/Class/Multimedia/LocationTest.php
index 2254ae23537..32db44fa5df 100644
--- a/tests/library/Class/Multimedia/LocationTest.php
+++ b/tests/library/Class/Multimedia/LocationTest.php
@@ -21,7 +21,7 @@
  */
 require_once 'ModelTestCase.php';
 
-class Multimedia_LocationTest extends Storm_Test_ModelTestCase {
+class Multimedia_LocationWithBibTest extends Storm_Test_ModelTestCase {
 	protected $_location;
 
 	public function setUp() {
@@ -101,10 +101,28 @@ class Multimedia_LocationTest extends Storm_Test_ModelTestCase {
 		$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', '19:00' => '19h00'], 
+												 '18:00' => '18h00', '18:30' => '18h30'], 
 												$this->_location->getStartTimesForDate('2012-08-09'));
 		
 	}
 }
 
+
+
+class Multimedia_LocationWithoutBibTest extends Storm_Test_ModelTestCase {
+	protected $_location;
+
+	public function setUp() {
+		$this->_location = Class_Multimedia_Location::newInstanceWithId(123)
+			->setOuvertures([Class_Ouverture::newInstanceWithId(3)]);
+	}
+
+
+	/** @test */
+	public function getOuverturesShouldAnswersEmptyArray() {
+		$this->assertEmpty($this->_location->getOuvertures());
+	}
+
+}
+
 ?>
\ No newline at end of file
-- 
GitLab