From 6697622d4c7630fcf4b93373202e597151df32a2 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Thu, 23 Aug 2012 10:47:33 +0000 Subject: [PATCH] =?UTF-8?q?Multimedia:=20la=20liste=20des=20r=C3=A9servati?= =?UTF-8?q?ons=20c=C3=B4t=C3=A9=20admin=20ne=20montre=20que=20les=20r?= =?UTF-8?q?=C3=A9servations=20futures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 1 + .../views/scripts/multimedia/browse.phtml | 2 +- .../views/scripts/multimedia/holds.phtml | 2 +- library/Class/Multimedia/Device.php | 16 +++++++ .../controllers/MultimediaControllerTest.php | 44 ++++++++++++++----- tests/library/Class/Multimedia/DeviceTest.php | 19 +------- tests/library/Class/TimeSourceForTest.php | 35 +++++++++++++++ 7 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 tests/library/Class/TimeSourceForTest.php diff --git a/.gitattributes b/.gitattributes index e82b1c03e6b..e7a19fdc8ec 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3755,6 +3755,7 @@ tests/library/Class/Systeme/ModulesAccueilTest.php -text tests/library/Class/Systeme/ModulesAppliTest.php -text tests/library/Class/Systeme/ModulesMenuTest.php -text tests/library/Class/Systeme/PergameServiceTest.php -text +tests/library/Class/TimeSourceForTest.php -text tests/library/Class/TypeDocTest.php -text tests/library/Class/UploadTest.php -text tests/library/Class/UserGroupTest.php -text diff --git a/application/modules/admin/views/scripts/multimedia/browse.phtml b/application/modules/admin/views/scripts/multimedia/browse.phtml index ed42341cc67..bbdac2edc0d 100644 --- a/application/modules/admin/views/scripts/multimedia/browse.phtml +++ b/application/modules/admin/views/scripts/multimedia/browse.phtml @@ -8,7 +8,7 @@ ['libelle', 'os'], [ ['action' => 'holds', 'content' => function($model) { - return $this->boutonIco('type=show').$model->numberOfHolds().' rés.'; + return $this->boutonIco('type=show').$model->numberOfNextHolds().' rés.'; }] ], 'multimedia_devices', diff --git a/application/modules/admin/views/scripts/multimedia/holds.phtml b/application/modules/admin/views/scripts/multimedia/holds.phtml index 0d2b2bfad0d..4b0bdf21c13 100644 --- a/application/modules/admin/views/scripts/multimedia/holds.phtml +++ b/application/modules/admin/views/scripts/multimedia/holds.phtml @@ -1,7 +1,7 @@ <h2><?php echo $this->titre;?></h2> <?php echo $this->tagModelTable( - $this->device->getHolds(), + $this->device->getNextHolds(), [$this->_('Utilisateur'), $this->_('Début'), $this->_('Fin')], ['username', 'startHHMM', 'endHHMM'], [], diff --git a/library/Class/Multimedia/Device.php b/library/Class/Multimedia/Device.php index 67bd86f6aab..4231aa5465d 100644 --- a/library/Class/Multimedia/Device.php +++ b/library/Class/Multimedia/Device.php @@ -320,4 +320,20 @@ class Class_Multimedia_Device extends Storm_Model_Abstract { public function getSlotSize() { return $this->getGroup()->getSlotSize(); } + + /** @return int */ + public function numberOfNextHolds() { + return Class_Multimedia_DeviceHold::countBy(['role' => 'device', + 'model' => $this, + 'where' => 'start>='.$this->getTimeSource()->date(), + 'order' => 'start']); + } + + /** @return array of DeviceHold */ + public function getNextHolds() { + return Class_Multimedia_DeviceHold::findAllBy(['role' => 'device', + 'model' => $this, + 'where' => 'start>='.$this->getTimeSource()->date(), + 'order' => 'start']); + } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/MultimediaControllerTest.php b/tests/application/modules/admin/controllers/MultimediaControllerTest.php index 81b168867e1..431e98ab9b2 100644 --- a/tests/application/modules/admin/controllers/MultimediaControllerTest.php +++ b/tests/application/modules/admin/controllers/MultimediaControllerTest.php @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; +require_once 'TimeSourceForTest.php'; abstract class Admin_MultimetiaControllerTestCase extends Admin_AbstractControllerTestCase { public function setUp() { @@ -209,9 +210,15 @@ class Admin_MultimediaControllerBrowseTest extends Admin_MultimetiaControllerTes ->setGroups(array($group)); + $time_source = (new TimeSourceForTest())->setTime(strtotime('today')); + Class_Multimedia_Device::setTimeSource($time_source); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold') ->whenCalled('countBy') - ->with(['role' => 'device', 'model' => $device]) + ->with(['role' => 'device', + 'model' => $device, + 'where' => 'start>='.$time_source->date(), + 'order' => 'start']) ->answers(7); @@ -291,17 +298,30 @@ class Admin_MultimediaControllerHoldsTest extends Admin_MultimetiaControllerTest $device = Class_Multimedia_Device::getLoader()->newInstanceWithId(1) ->setLibelle('Poste 1') - ->setOs('Archlinux') - ->setHolds([ - Class_Multimedia_DeviceHold::newInstanceWithId(3) - ->setStart(strtotime('2012-09-12 15:00')) - ->setEnd(strtotime('2012-09-12 16:00')) - ->setUser(Class_Users::newInstanceWithId(3)->setPrenom('Laurent')), - - Class_Multimedia_DeviceHold::newInstanceWithId(4) - ->setStart(strtotime('2012-09-13 12:00')) - ->setEnd(strtotime('2012-09-13 13:00')) - ->setUser(Class_Users::newInstanceWithId(4)->setPrenom('Estelle'))]); + ->setOs('Archlinux'); + + + $time_source = (new TimeSourceForTest())->setTime(mktime(10, 10, 10, + 9, 12, 2012)); + Class_Multimedia_Device::setTimeSource($time_source); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold') + ->whenCalled('findAllBy') + ->with(['role' => 'device', + 'model' => $device, + 'where' => 'start>='.$time_source->date(), + 'order' => 'start']) + ->answers([ + Class_Multimedia_DeviceHold::newInstanceWithId(3) + ->setStart(strtotime('2012-09-12 15:00')) + ->setEnd(strtotime('2012-09-12 16:00')) + ->setUser(Class_Users::newInstanceWithId(3)->setPrenom('Laurent')), + + Class_Multimedia_DeviceHold::newInstanceWithId(4) + ->setStart(strtotime('2012-09-13 12:00')) + ->setEnd(strtotime('2012-09-13 13:00')) + ->setUser(Class_Users::newInstanceWithId(4)->setPrenom('Estelle')) + ]); $this->dispatch('/admin/multimedia/holds/id/1', true); diff --git a/tests/library/Class/Multimedia/DeviceTest.php b/tests/library/Class/Multimedia/DeviceTest.php index 9c441f65765..82d81b41141 100644 --- a/tests/library/Class/Multimedia/DeviceTest.php +++ b/tests/library/Class/Multimedia/DeviceTest.php @@ -19,22 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'ModelTestCase.php'; - - -class TimesSourceForTest extends Class_TimeSource { - protected $_time; - - public function setTime($time) { - $this->_time = $time; - return $this; - } - - public function time() { - return $this->_time; - } -} - - +require_once 'TimeSourceForTest.php'; abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase { @@ -69,7 +54,7 @@ abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase { ->setGroup($this->_group); $time = strtotime('today'); - $this->_time_source = (new TimesSourceForTest())->setTime($time); + $this->_time_source = (new TimeSourceForTest())->setTime($time); Class_Multimedia_Device::setTimeSource($this->_time_source); Class_Multimedia_Location::setTimeSource($this->_time_source); diff --git a/tests/library/Class/TimeSourceForTest.php b/tests/library/Class/TimeSourceForTest.php new file mode 100644 index 00000000000..d8e35b8737f --- /dev/null +++ b/tests/library/Class/TimeSourceForTest.php @@ -0,0 +1,35 @@ +<?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 + */ + +class TimeSourceForTest extends Class_TimeSource { + protected $_time; + + public function setTime($time) { + $this->_time = $time; + return $this; + } + + public function time() { + return $this->_time; + } +} + +?> \ No newline at end of file -- GitLab