Skip to content
Snippets Groups Projects
Commit 506c513f authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

dev #79945 : openings duplicate and closure UI

parent 4f358c80
Branches
Tags
3 merge requests!3297WIP: Master,!3035dev #79945 : openings duplicate and closure UI,!3027dev #79945 : openings duplicate and closure UI
Pipeline #6465 passed with stage
in 35 minutes and 27 seconds
Showing
with 520 additions and 100 deletions
'79945' =>
['Label' => $this->_('Gestion des ouvertures des bibliothèques'),
'Desc' => $this->_('Bokeh permet de définir des ouvertures / fermetures habituelles et limitées sur une période donnée.'),
'Image' => '',
'Video' => 'https://youtu.be/NWwEuxX7BpE',
'Category' => $this->_('Administration'),
'Right' => function($feature_description, $user) {return true;},
'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Ouvertures_des_biblioth%C3%A8ques',
'Test' => '',
'Date' => '2019-02-07'],
\ No newline at end of file
- ticket #79945 : Administration : Amélioration de la gestion des ouvertures de bibliothèques
\ No newline at end of file
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
class OuvertureLoader extends Storm_Model_Loader { class OuvertureLoader extends Storm_Model_Loader {
use Trait_Translator; use Trait_Translator;
const CLOSED_VALUE = '00:00';
public function compare($a, $b) { public function compare($a, $b) {
if ($a->getJourSemaine() && $b->getJourSemaine() && $a->getJourSemaine() > $b->getJourSemaine()) if ($a->getJourSemaine() && $b->getJourSemaine() && $a->getJourSemaine() > $b->getJourSemaine())
...@@ -46,6 +46,11 @@ class OuvertureLoader extends Storm_Model_Loader { ...@@ -46,6 +46,11 @@ class OuvertureLoader extends Storm_Model_Loader {
} }
public function getClosedValue() {
return static::CLOSED_VALUE;
}
public function getDays() { public function getDays() {
return [$this->_('Aucun'), return [$this->_('Aucun'),
$this->_('Lundi'), $this->_('Lundi'),
...@@ -58,6 +63,11 @@ class OuvertureLoader extends Storm_Model_Loader { ...@@ -58,6 +63,11 @@ class OuvertureLoader extends Storm_Model_Loader {
} }
public function isValueClosed($value) {
return $value == static::CLOSED_VALUE;
}
public function humanDate($date) { public function humanDate($date) {
return Class_Date::getHumanDate($date, 'dd/MM/yyyy'); return Class_Date::getHumanDate($date, 'dd/MM/yyyy');
} }
...@@ -66,6 +76,12 @@ class OuvertureLoader extends Storm_Model_Loader { ...@@ -66,6 +76,12 @@ class OuvertureLoader extends Storm_Model_Loader {
public function humanDateToDate($date) { public function humanDateToDate($date) {
return Class_Date::getHumanDate($date, 'yyyy-MM-dd'); return Class_Date::getHumanDate($date, 'yyyy-MM-dd');
} }
public function newClosedOn($day) {
return Class_Ouverture::newInstance(['horaires' => array_fill(0, 4, static::CLOSED_VALUE),
'jour' => $day]);
}
} }
...@@ -249,14 +265,14 @@ class Class_Ouverture extends Storm_Model_Abstract { ...@@ -249,14 +265,14 @@ class Class_Ouverture extends Storm_Model_Abstract {
public function isExceptionalOpenOnDate($date) { public function isExceptionalOpenOnDate($date) {
return $this->isExceptional() return $this->isExceptional()
&& (!$this->isClosure()) && (!$this->isClosed())
&& (date('Y-m-d', $date) == $this->getJour()); && (date('Y-m-d', $date) == $this->getJour());
} }
public function isExceptionalClosedOnDate($date) { public function isExceptionalClosedOnDate($date) {
return $this->isExceptional() return $this->isExceptional()
&& $this->isClosure() && $this->isClosed()
&& (date('Y-m-d', $date) == $this->getJour()); && (date('Y-m-d', $date) == $this->getJour());
} }
...@@ -279,7 +295,7 @@ class Class_Ouverture extends Storm_Model_Abstract { ...@@ -279,7 +295,7 @@ class Class_Ouverture extends Storm_Model_Abstract {
if (0 == $day_of_week = (int)date('w', $date)) if (0 == $day_of_week = (int)date('w', $date))
$day_of_week = 7; $day_of_week = 7;
return !$this->isClosure() && $this->getJourSemaine() == $day_of_week; return !$this->isClosed() && $this->getJourSemaine() == $day_of_week;
} }
...@@ -287,7 +303,7 @@ class Class_Ouverture extends Storm_Model_Abstract { ...@@ -287,7 +303,7 @@ class Class_Ouverture extends Storm_Model_Abstract {
if (0 == $day_of_week = (int)date('w', $date)) if (0 == $day_of_week = (int)date('w', $date))
$day_of_week = 7; $day_of_week = 7;
return $this->isClosure() && $this->getJourSemaine() == $day_of_week; return $this->isClosed() && $this->getJourSemaine() == $day_of_week;
} }
...@@ -307,11 +323,19 @@ class Class_Ouverture extends Storm_Model_Abstract { ...@@ -307,11 +323,19 @@ class Class_Ouverture extends Storm_Model_Abstract {
} }
public function isClosure() { public function isClosed() {
foreach(['debut_matin', 'fin_matin', 'debut_apres_midi', 'fin_apres_midi'] as $field) foreach(['debut_matin', 'fin_matin', 'debut_apres_midi', 'fin_apres_midi'] as $field)
if ('00:00' != $this->callGetterByAttributeName($field)) if (!$this->getLoader()->isValueClosed($this->callGetterByAttributeName($field)))
return false; return false;
return true; return true;
} }
public function copy() {
$attributes = $this->_attributes;
unset($attributes['id']);
return (new static())->updateAttributes($attributes);
}
} }
\ No newline at end of file
...@@ -59,7 +59,7 @@ class Class_Ouverture_Visitor { ...@@ -59,7 +59,7 @@ class Class_Ouverture_Visitor {
if (!$opening->hasValidityRange() && $opening->isRecurrent()) if (!$opening->hasValidityRange() && $opening->isRecurrent())
return $this->_addDefault($opening); return $this->_addDefault($opening);
if ($opening->isExceptional() && $opening->isClosure()) if ($opening->isExceptional() && $opening->isClosed())
return $this->_addClosure($opening); return $this->_addClosure($opening);
if ($opening->isExceptional()) if ($opening->isExceptional())
......
<?php
/**
* Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_TableDescription_Openings extends Class_TableDescription {
protected
$_view,
$_time_segment_callback;
public function init() {
$this
->addColumn($this->_('Jour'),
function($model) { return $this->_humanDateRange($model); })
->addColumn($this->_('Matinée'),
function($model)
{
return $this->_timeSegment($model->getDebutMatin(), $model->getFinMatin());
})
->addColumn($this->_('Après-midi'),
function($model)
{
return $this->_timeSegment($model->getDebutApresMidi(), $model->getFinApresMidi());
})
->addRowAction(['url' => ['module' => 'admin',
'controller' => 'ouvertures',
'action' => 'edit',
'id' => '%s'],
'label' => $this->_('Modifier'),
'icon' => 'edit'])
->addRowAction(['url' => ['module' => 'admin',
'controller' => 'ouvertures',
'action' => 'duplicate',
'id' => '%s'],
'label' => $this->_('Dupliquer'),
'icon' => 'copy',
'anchorOptions' => ['onclick' => 'javascript:return confirm(\'' . $this->_('Êtes vous sûr de vouloir dupliquer cet élément ?') . '\');']])
->addRowAction(['url' => ['module' => 'admin',
'controller' => 'ouvertures',
'action' => 'delete',
'id' => '%s'],
'label' => $this->_('Supprimer'),
'icon' => 'delete',
'anchorOptions' => ['onclick' => 'javascript:return confirm(\'' . $this->_('Êtes vous sûr de vouloir supprimer cet élément ?') . '\');']])
;
}
public function setView($view) {
$this->_view = $view;
return $this;
}
public function setTimeSegmentCallback($callback) {
$this->_time_segment_callback = $callback;
return $this;
}
protected function _humanDateRange($model) {
return $this->_view
? $this->_view->openingHumanDateRange($model)
: '';
}
protected function _timeSegment($start, $end) {
if (!isset($this->_time_segment_callback))
return '';
return ($segment = call_user_func($this->_time_segment_callback, $start, $end))
? $segment
: $this->_('Fermé');
}
}
<?php
/**
* Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_TableDescription_OpeningsLabelled extends Class_TableDescription_Openings {
public function init() {
$this->addColumn($this->_('Libellé'), 'label');
parent::init();
}
}
...@@ -35,6 +35,13 @@ class ZendAfi_Controller_Plugin_Manager_Opening extends ZendAfi_Controller_Plugi ...@@ -35,6 +35,13 @@ class ZendAfi_Controller_Plugin_Manager_Opening extends ZendAfi_Controller_Plugi
? $this->_getSQLDateFrom($post['validity_end']) ? $this->_getSQLDateFrom($post['validity_end'])
: ''; : '';
if (isset($post['closed_am']) && $post['closed_am'] == 1)
$post['debut_matin'] = $post['fin_matin'] = Class_Ouverture::getClosedValue();
if (isset($post['closed_pm']) && $post['closed_pm'] == 1)
$post['debut_apres_midi'] = $post['fin_apres_midi'] = Class_Ouverture::getClosedValue();
unset($post['closed_am'], $post['closed_pm']);
return $post; return $post;
} }
...@@ -46,6 +53,27 @@ class ZendAfi_Controller_Plugin_Manager_Opening extends ZendAfi_Controller_Plugi ...@@ -46,6 +53,27 @@ class ZendAfi_Controller_Plugin_Manager_Opening extends ZendAfi_Controller_Plugi
} }
public function duplicateAction() {
if (!$this->_canAdd()) {
$this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"',
$this->_getAddActionTitle()));
$this->_redirectToIndex();
return;
}
if (!$model = $this->_findModel()) {
$this->_helper
->notify($this->_view->_('Impossible de dupliquer, la plage d\'ouverture est introuvable'));
$this->_redirectToIndex();
return;
}
$model->copy()->save();
$this->_helper->notify($this->_view->_('Plage d\'ouverture dupliquée'));
$this->_redirectToIndex();
}
protected function _doBeforeSave($model) { protected function _doBeforeSave($model) {
return $model->setIdSite($this->_getParam('id_site', 0)); return $model->setIdSite($this->_getParam('id_site', 0));
} }
...@@ -66,4 +94,3 @@ class ZendAfi_Controller_Plugin_Manager_Opening extends ZendAfi_Controller_Plugi ...@@ -66,4 +94,3 @@ class ZendAfi_Controller_Plugin_Manager_Opening extends ZendAfi_Controller_Plugi
return $this; return $this;
} }
} }
?>
\ No newline at end of file
...@@ -26,7 +26,11 @@ class ZendAfi_Form_Admin_Ouverture extends ZendAfi_Form { ...@@ -26,7 +26,11 @@ class ZendAfi_Form_Admin_Ouverture extends ZendAfi_Form {
Class_ScriptLoader::getInstance() Class_ScriptLoader::getInstance()
->addJqueryReady('formSelectToggleVisibilityForElement("#jour_semaine", "#fieldset-plage_ouverture tr:nth-child(3)", ["0"]);' ->addJqueryReady('formSelectToggleVisibilityForElement("#jour_semaine", "#fieldset-plage_ouverture tr:nth-child(3)", ["0"]);'
. 'formSelectToggleVisibilityForElement("#jour_semaine", "#fieldset-plage_ouverture tr:nth-child(4)", ["1", "2", "3", "4", "5", "6", "7"]);'); . 'formSelectToggleVisibilityForElement("#jour_semaine", "#fieldset-plage_ouverture tr:nth-child(4)", ["1", "2", "3", "4", "5", "6", "7"]);'
. 'checkBoxToggleVisibilityForElement("#closed_am", $("#fieldset-plage_ouverture select[name$=\'_matin\']").parents("tr"), false);'
. 'checkBoxToggleVisibilityForElement("#closed_pm", $("#fieldset-plage_ouverture select[name$=\'_apres_midi\']").parents("tr"), false);');
$possible_hours = Class_Multimedia_Location::getPossibleHours(5);
$this $this
->addElement('text', ->addElement('text',
...@@ -48,18 +52,33 @@ class ZendAfi_Form_Admin_Ouverture extends ZendAfi_Form { ...@@ -48,18 +52,33 @@ class ZendAfi_Form_Admin_Ouverture extends ZendAfi_Form {
'validity_range', 'validity_range',
['label' => $this->_('Restreindre la période d\'ouverture'), ['label' => $this->_('Restreindre la période d\'ouverture'),
'start' => ['name' => 'validity_start'], 'start' => ['name' => 'validity_start'],
'end' => ['name' => 'validity_end']]); 'end' => ['name' => 'validity_end']])
->addElement('select',
'debut_matin',
['label' => $this->_('Début matinée'),
'multiOptions' => $possible_hours])
->addElement('select',
'fin_matin',
['label' => $this->_('Fin matinée'),
'multiOptions' => $possible_hours])
->addElement('checkbox', 'closed_am', ['label' => $this->_('Fermé matinée')])
$field_labels = ['debut_matin' => $this->_('Début matinée'), ->addElement('select',
'fin_matin' => $this->_('Fin matinée'), 'debut_apres_midi',
'debut_apres_midi' => $this->_('Début après-midi'), ['label' => $this->_('Début après-midi'),
'fin_apres_midi' => $this->_('Fin après-midi')]; 'multiOptions' => $possible_hours])
foreach ($field_labels as $field => $label) ->addElement('select',
$this->addElement('select', 'fin_apres_midi',
$field, ['label' => $this->_('Fin après-midi'),
['label' => $label, 'multiOptions' => $possible_hours])
'multiOptions' => Class_Multimedia_Location::getPossibleHours(5)]);
->addElement('checkbox', 'closed_pm', ['label' => $this->_('Fermé après-midi')])
;
$this->addDisplayGroup($this->getElementsNames(), $this->addDisplayGroup($this->getElementsNames(),
'plage_ouverture', 'plage_ouverture',
...@@ -90,6 +109,21 @@ class ZendAfi_Form_Admin_Ouverture extends ZendAfi_Form { ...@@ -90,6 +109,21 @@ class ZendAfi_Form_Admin_Ouverture extends ZendAfi_Form {
$this->getElement('validity_range') $this->getElement('validity_range')
->setStartValue(isset($values['validity_start']) ? $values['validity_start'] : '') ->setStartValue(isset($values['validity_start']) ? $values['validity_start'] : '')
->setEndValue(isset($values['validity_end']) ? $values['validity_end'] : ''); ->setEndValue(isset($values['validity_end']) ? $values['validity_end'] : '');
if (!isset($values['debut_matin']))
return parent::populate($values);
if ( Class_Ouverture::isValueClosed($values['debut_matin']) &&
Class_Ouverture::isValueClosed($values['fin_matin']) )
$this->getElement('closed_am')
->setChecked(true);
if ( Class_Ouverture::isValueClosed($values['debut_apres_midi']) &&
Class_Ouverture::isValueClosed($values['fin_apres_midi']) )
$this->getElement('closed_pm')
->setChecked(true);
return parent::populate($values); return parent::populate($values);
} }
} }
...@@ -98,7 +98,7 @@ class ZendAfi_View_Helper_LibraryOpenings extends ZendAfi_View_Helper_BaseHelper ...@@ -98,7 +98,7 @@ class ZendAfi_View_Helper_LibraryOpenings extends ZendAfi_View_Helper_BaseHelper
foreach($openings as $opening) { foreach($openings as $opening) {
$label = (!$label) ? $opening->getLabel() : $label; $label = (!$label) ? $opening->getLabel() : $label;
$only_closures = $only_closures && $opening->isClosure(); $only_closures = $only_closures && $opening->isClosed();
$content .= $this->_tag('li', $this->_renderOne($opening)); $content .= $this->_tag('li', $this->_renderOne($opening));
} }
......
...@@ -72,14 +72,17 @@ class ZendAfi_View_Helper_LibraryOpeningsAdmin ...@@ -72,14 +72,17 @@ class ZendAfi_View_Helper_LibraryOpeningsAdmin
foreach($openings as $opening) foreach($openings as $opening)
$label = (!$label) ? $opening->getLabel() : $label; $label = (!$label) ? $opening->getLabel() : $label;
$description = new Class_TableDescription_Openings('ouvertures');
return $this->_renderAdminSection($closure($label), return $this->_renderAdminSection($closure($label),
$this->_renderTagModelTable($openings)); $this->_renderTagModelTable($openings, $description));
} }
protected function _renderSectionLabelled($label, $openings) { protected function _renderSectionLabelled($label, $openings) {
$description = (new Class_TableDescription_OpeningsLabelled('ouvertures'));
return $this->_renderAdminSection($label, return $this->_renderAdminSection($label,
$this->_renderTagModelTable($openings, [$this->_('Libellé')], ['label'])); $this->_renderTagModelTable($openings, $description));
} }
...@@ -89,31 +92,15 @@ class ZendAfi_View_Helper_LibraryOpeningsAdmin ...@@ -89,31 +92,15 @@ class ZendAfi_View_Helper_LibraryOpeningsAdmin
} }
protected function _renderTagModelTable($openings, $columns_labels = [], $columns_datas = []) { /**
$columns_labels = array_merge($columns_labels, * @param $openings collection
[$this->_('Jour'), * @param $description Class_TableDescription
$this->_('Matin'), */
'', protected function _renderTagModelTable($openings, $description) {
$this->_('Après-midi'), $description
'']); ->setView($this->view)
->setTimeSegmentCallback(function($start, $end) { return $this->_renderTimeSegment($start, $end); });
$columns_datas = array_merge($columns_datas,
['formatted_jour', return $this->view->renderTable($description, $openings);
'debut_matin',
'fin_matin',
'debut_apres_midi',
'fin_apres_midi']);
return $this->view
->tagModelTable($openings,
$columns_labels,
$columns_datas,
[ ['action' => 'edit', 'content' => $this->view->boutonIco('type=edit')],
['action' => 'delete', 'content' => $this->view->boutonIco('type=del')] ],
'ouvertures',
null,
['formatted_jour' => function($opening) {
return $this->view->openingHumanDateRange($opening);
}]);
} }
} }
\ No newline at end of file
...@@ -33,7 +33,8 @@ class ZendAfi_View_Helper_RenderLibraryOpening extends ZendAfi_View_Helper_BaseH ...@@ -33,7 +33,8 @@ class ZendAfi_View_Helper_RenderLibraryOpening extends ZendAfi_View_Helper_BaseH
public function renderOuverturesForLibrary($library) { public function renderOuverturesForLibrary($library) {
if (!$ouverture = $this->getLibraryOuverture($library)) if ((!$ouverture = $this->getLibraryOuverture($library))
|| $ouverture->isClosed())
return $this->renderClosed($this->_('Fermé.') return $this->renderClosed($this->_('Fermé.')
. $this->renderNextOuvertureForLibrary($library)); . $this->renderNextOuvertureForLibrary($library));
...@@ -95,7 +96,7 @@ class ZendAfi_View_Helper_RenderLibraryOpening extends ZendAfi_View_Helper_BaseH ...@@ -95,7 +96,7 @@ class ZendAfi_View_Helper_RenderLibraryOpening extends ZendAfi_View_Helper_BaseH
$time = strtotime('+'.$i.' day', $this->getCurrentTime()); $time = strtotime('+'.$i.' day', $this->getCurrentTime());
if (($ouverture = $this->getLibraryOuvertureOnDate($library, $time)) if (($ouverture = $this->getLibraryOuvertureOnDate($library, $time))
&& !$ouverture->isClosure()) && !$ouverture->isClosed())
break; break;
} }
......
...@@ -126,10 +126,8 @@ class OuverturesControllerIndexActionSiteCranTest extends OuverturesControllerTe ...@@ -126,10 +126,8 @@ class OuverturesControllerIndexActionSiteCranTest extends OuverturesControllerTe
/** @test */ /** @test */
public function ouvertureHoursShouldBeVisible() { public function ouvertureHoursShouldBeVisible() {
$this->assertXPathContentContains('//td', '08:00'); $this->assertXPathContentContains('//td', '08h00 - 12h00');
$this->assertXPathContentContains('//td', '12:00'); $this->assertXPathContentContains('//td', '13h30 - 17h00');
$this->assertXPathContentContains('//td', '13:30');
$this->assertXPathContentContains('//td', '17:00');
} }
...@@ -370,18 +368,70 @@ class OuverturesControllerIndexActionSiteAnnecyTest extends OuverturesController ...@@ -370,18 +368,70 @@ class OuverturesControllerIndexActionSiteAnnecyTest extends OuverturesController
} }
/** @test */
public function pageShouldContainsButtonToCreateOuverture() {
$this->assertXPathContentContains('//button[contains(@data-url, "/ouvertures/add/id_site/3")]',
'Ajouter une plage d\'ouverture');
}
/** @test */
public function pageShouldContainsButtonReturnToLibrariesIndex() {
$this->assertXPathContentContains('//button[contains(@data-url, "/bib")]',
'Retour à la liste des bibliothèques');
}
/** @test */ /** @test */
public function ouvertureAtHeightHalfShouldBeVisible() { public function ouvertureAtHeightHalfShouldBeVisible() {
$this->assertXPathContentContains('//tbody//td[3]', '08:30'); $this->assertXPathContentContains('//tbody//td', '08h30 - 12h00');
$this->assertXPathContentContains('//tbody//td[4]', '12:00'); $this->assertXPathContentContains('//tbody//td', '12h00 - 17h00');
$this->assertXPathContentContains('//tbody//td[5]', '12:00'); }
$this->assertXPathContentContains('//tbody//td[6]', '17:00');
/** @test */
public function editActionShouldBePresent() {
$this->assertXPath('//a[contains(@href, "/ouvertures/edit/id_site/3/id/45")]');
}
/** @test */
public function deleteActionShouldBePresent() {
$this->assertXPath('//a[contains(@href, "/ouvertures/delete/id_site/3/id/45")]');
} }
/** @disabledtest */ /** @test */
function pageShouldContainsButtonToCreateOuverture() { public function duplicateActionShouldBePresent() {
$this->assertXPathContentContains('//div[contains(@onclick, "ouvertures/add/id_site/3")]//td', 'Ajouter une plage d\'ouverture'); $this->assertXPath('//a[contains(@href, "/ouvertures/duplicate/id_site/3/id/45")]');
}
}
class OuverturesControllerDuplicateActionTest extends OuverturesControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/ouvertures/duplicate/id_site/3/id/45');
}
/** @test */
public function shouldRedirectToIndexOfAnnecyOpenings() {
$this->assertRedirectTo('/admin/ouvertures/index/id_site/3');
}
/** @test */
public function shouldNotifyDuplicationSuccess() {
$this->assertFlashMessengerContentContains('Plage d\'ouverture dupliquée');
}
/** @test */
public function annecyShouldHaveTwoOpenings() {
$this->assertEquals(2, Class_Ouverture::countBy(['id_site' => 3]));
} }
} }
...@@ -513,6 +563,12 @@ class OuverturesControllerAddOuvertureCranTest extends OuverturesControllerTestC ...@@ -513,6 +563,12 @@ class OuverturesControllerAddOuvertureCranTest extends OuverturesControllerTestC
} }
/** @test */
public function formShouldContainsCheckboxForClosedAm() {
$this->assertXPath('//form//input[@type="checkbox"][@name="closed_am"]');
}
/** @test */ /** @test */
public function titleShouldBeCranGevrierAjouteUnePlageDouverture() { public function titleShouldBeCranGevrierAjouteUnePlageDouverture() {
$this->assertXPathContentContains('//h1', 'Cran-Gévrier : ajouter une plage d\'ouverture'); $this->assertXPathContentContains('//h1', 'Cran-Gévrier : ajouter une plage d\'ouverture');
...@@ -587,8 +643,10 @@ class OuverturesControllerPostAddOuvertureCranTest extends OuverturesControllerT ...@@ -587,8 +643,10 @@ class OuverturesControllerPostAddOuvertureCranTest extends OuverturesControllerT
parent::setUp(); parent::setUp();
$this->postDispatch('/admin/ouvertures/add/id_site/3', ['debut_matin' => '10:30', $this->postDispatch('/admin/ouvertures/add/id_site/3', ['debut_matin' => '10:30',
'fin_matin' => '11:30', 'fin_matin' => '11:30',
'closed_am' => 0,
'debut_apres_midi' => '14:00', 'debut_apres_midi' => '14:00',
'fin_apres_midi' => '15:00', 'fin_apres_midi' => '15:00',
'closed_pm' => 0,
'jour_semaine' => Class_Ouverture::MARDI, 'jour_semaine' => Class_Ouverture::MARDI,
'jour' => '23/10/2012', 'jour' => '23/10/2012',
'validity_start' => '00/00/0000', 'validity_start' => '00/00/0000',
...@@ -837,4 +895,125 @@ class OuverturesControllerPostValidityRangeErrorsTest extends OuverturesControll ...@@ -837,4 +895,125 @@ class OuverturesControllerPostValidityRangeErrorsTest extends OuverturesControll
$this->assertXPathContentContains('//ul[@class="errors"]/li', $this->assertXPathContentContains('//ul[@class="errors"]/li',
'La date de début doit être plus récente que la date de fin'); 'La date de début doit être plus récente que la date de fin');
} }
}
class OuverturesControllerPostClosedAMTest extends OuverturesControllerTestCase {
protected $_new_ouverture;
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/ouvertures/add/id_site/3', ['debut_matin' => '10:30',
'fin_matin' => '11:30',
'closed_am' => 1,
'debut_apres_midi' => '14:00',
'fin_apres_midi' => '15:00',
'closed_pm' => 1,
'jour_semaine' => Class_Ouverture::MARDI,
'jour' => '23/10/2012',
'validity_start' => '00/00/0000',
'validity_end' => '']);
$this->_new_ouverture = Class_Ouverture::find(46);
}
/** @test */
public function debutMatinShouldBeSetZeroified() {
$this->assertEquals('00:00', Class_Ouverture::find(46)->getDebutMatin());
}
/** @test */
public function finMatinShouldBeSetZeroified() {
$this->assertEquals('00:00', Class_Ouverture::find(46)->getFinMatin());
}
/** @test */
public function debutApresMidiShouldBeSetZeroified() {
$this->assertEquals('00:00', Class_Ouverture::find(46)->getDebutApresMidi());
}
/** @test */
public function finApresMidiShouldBeSetZeroified() {
$this->assertEquals('00:00', Class_Ouverture::find(46)->getFinApresMidi());
}
/**
* @test
* @expectedException Storm_Model_Exception
*/
public function closedAMShouldNotStayInAttributes() {
Class_Ouverture::find(46)->hasClosedAm();
}
/**
* @test
* @expectedException Storm_Model_Exception
*/
public function closedPMShouldNotStayInAttributes() {
Class_Ouverture::find(46)->hasClosedPm();
}
}
class OuverturesControllerEditActionWithClosedAMTest extends OuverturesControllerTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_Ouverture',
['id' => 456465,
'validity_start' => '2017-12-01',
'validity_end' => '2018-01-01',
'debut_matin' => '00:00',
'fin_matin' => '00:00',
'debut_apres_midi' => '00:00',
'fin_apres_midi' => '00:00',
'label' => 'Hiver']);
$this->dispatch('/admin/ouvertures/edit/id/456465/id_site/3', true);
}
/** @test */
public function closedAMShouldBeChecked() {
$this->assertXPath('//input[@type="checkbox"][@name="closed_am"][@checked]');
}
/** @test */
public function closedPMShouldBeChecked() {
$this->assertXPath('//input[@type="checkbox"][@name="closed_pm"][@checked]');
}
}
class OuverturesControllerIndexActionWithClosedAMTest extends OuverturesControllerTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_Ouverture',
['id' => 456465,
'id_site' => 3,
'validity_start' => '2017-12-01',
'validity_end' => '2018-01-01',
'debut_matin' => '00:00',
'fin_matin' => '00:00',
'debut_apres_midi' => '00:00',
'fin_apres_midi' => '00:00',
'label' => 'Hiver']);
$this->dispatch('/admin/ouvertures/index/id_site/3', true);
}
/** @test */
public function pageShouldContainsTwoClosedLabels() {
$this->assertXPathCount('//td[text()="Fermé"]', 2);
}
} }
\ No newline at end of file
...@@ -57,7 +57,7 @@ abstract class ZendAfi_View_Helper_RenderLibraryOpeningTestCase extends ViewHelp ...@@ -57,7 +57,7 @@ abstract class ZendAfi_View_Helper_RenderLibraryOpeningTestCase extends ViewHelp
protected function _renderOpening($library) { protected function _renderOpening($library) {
$helper = new ZendAfi_View_Helper_RenderLibraryOpening(); $helper = new ZendAfi_View_Helper_RenderLibraryOpening();
$helper->setView(new ZendAfi_Controller_Action_Helper_View()); $helper->setView($this->view);
return $helper->renderLibraryOpening($library); return $helper->renderLibraryOpening($library);
} }
...@@ -276,7 +276,6 @@ class ZendAfi_View_Helper_RenderLibraryOpeningOnMondayEveningTest extends ZendAf ...@@ -276,7 +276,6 @@ class ZendAfi_View_Helper_RenderLibraryOpeningOnMondayEveningTest extends ZendAf
} }
/** @test */ /** @test */
public function annecyShouldContainsLibraryIsClosedSince18() { public function annecyShouldContainsLibraryIsClosedSince18() {
$this->assertXPathContentContains($this->_renderOpening($this->annecy), $this->assertXPathContentContains($this->_renderOpening($this->annecy),
...@@ -294,17 +293,13 @@ class ZendAfi_View_Helper_RenderLibraryOpeningOnMondayEveningTest extends ZendAf ...@@ -294,17 +293,13 @@ class ZendAfi_View_Helper_RenderLibraryOpeningOnMondayEveningTest extends ZendAf
/** @test */ /** @test */
public function withExceptionalCloseOnTuesdayMeythetShouldContainsLibraryWillOpenOnMondayAt10() { public function withExceptionalCloseOnTuesdayMeythetShouldContainsLibraryWillOpenOnMondayAt10() {
$this->meythet->addOuverture($this->fixture('Class_Ouverture', $this->meythet->addOuverture(Class_Ouverture::newClosedOn('2015-10-06'))
['id' => 348,
'horaires' => ['00:00', '00:00', '00:00', '00:00'],
'jour' => '2015-10-06']))
->save(); ->save();
$this->assertXPathContentContains($this->_renderOpening($this->meythet), $this->assertXPathContentContains($this->_renderOpening($this->meythet),
'//p', '//p',
utf8_encode('Fermé depuis 18:00. Réouverture Lundi à 10:00')); utf8_encode('Fermé depuis 18:00. Réouverture Lundi à 10:00'));
} }
} }
...@@ -362,38 +357,39 @@ class ZendAfi_View_Helper_RenderLibraryOpeningOnTuesdayMorningTest extends ZendA ...@@ -362,38 +357,39 @@ class ZendAfi_View_Helper_RenderLibraryOpeningOnTuesdayMorningTest extends ZendA
class ZendAfi_View_Helper_RenderLibraryOpeningsOnValidityRangeTest extends ZendAfi_View_Helper_RenderLibraryOpeningTestCase { class ZendAfi_View_Helper_RenderLibraryOpeningsOnValidityRangeTest
extends ZendAfi_View_Helper_RenderLibraryOpeningTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->cran->addOuverture($start_end = $this->fixture('Class_Ouverture', $this->cran->addOuverture($this->fixture('Class_Ouverture',
['id' => 348, ['id' => 348,
'horaires' => ['00:00', '00:00', '14:00', '18:00'], 'horaires' => ['00:00', '00:00', '14:00', '18:00'],
'jour' => '', 'jour' => '',
'validity_start' => '2015-09-01', 'validity_start' => '2015-09-01',
'validity_end' => '2015-12-29', 'validity_end' => '2015-12-29',
'jour_semaine' => Class_Ouverture::MARDI])) 'jour_semaine' => Class_Ouverture::MARDI]))
->addOuverture($end_only = $this->fixture('Class_Ouverture', ->addOuverture($this->fixture('Class_Ouverture',
['id' => 349, ['id' => 349,
'horaires' => ['00:00', '00:00', '15:00', '18:00'], 'horaires' => ['00:00', '00:00', '15:00', '18:00'],
'jour' => '', 'jour' => '',
'validity_end' => '2015-06-30', 'validity_end' => '2015-06-30',
'jour_semaine' => Class_Ouverture::MARDI])) 'jour_semaine' => Class_Ouverture::MARDI]))
->addOuverture($start_only = $this->fixture('Class_Ouverture', ->addOuverture($this->fixture('Class_Ouverture',
['id' => 351, ['id' => 351,
'horaires' => ['11:00', '12:00', '13:00', '18:00'], 'horaires' => ['11:00', '12:00', '13:00', '18:00'],
'jour' => '', 'jour' => '',
'validity_start' => '2015-01-01', 'validity_start' => '2015-01-01',
'jour_semaine' => Class_Ouverture::MARDI])) 'jour_semaine' => Class_Ouverture::MARDI]))
->addOuverture($start_next_year = $this->fixture('Class_Ouverture', ->addOuverture($this->fixture('Class_Ouverture',
['id' => 350, ['id' => 350,
'horaires' => ['00:00', '00:00', '13:00', '18:00'], 'horaires' => ['00:00', '00:00', '13:00', '18:00'],
'jour' => '', 'jour' => '',
'validity_start' => '2016-01-01', 'validity_start' => '2016-01-01',
'jour_semaine' => Class_Ouverture::MARDI])) 'jour_semaine' => Class_Ouverture::MARDI]))
->assertSave(); ->assertSave();
...@@ -457,4 +453,38 @@ class ZendAfi_View_Helper_RenderLibraryOpeningsOnValidityRangeTest extends ZendA ...@@ -457,4 +453,38 @@ class ZendAfi_View_Helper_RenderLibraryOpeningsOnValidityRangeTest extends ZendA
'//p', '//p',
utf8_encode('Réouverture Mardi à 15:00')); utf8_encode('Réouverture Mardi à 15:00'));
} }
} }
\ No newline at end of file
class ZendAfi_View_Helper_RenderLibraryOpeningsWithCurrentlyClosedTest
extends ZendAfi_View_Helper_RenderLibraryOpeningTestCase {
public function setUp() {
parent::setUp();
$this->meythet = $this
->fixture('Class_Bib',
['id' => 4,
'libelle' => 'Meythet',
'closed_on_holidays' => false,
'ouvertures' => [
Class_Ouverture::chaqueLundi('00:00', '00:00', '00:00', '00:00'),
Class_Ouverture::chaqueMardi('00:00', '00:00', '14:30', '16:30'),
Class_Ouverture::chaqueVendredi('09:00', '10:00', '00:00', '00:00'),
Class_Ouverture::newClosedOn('2019-02-25'),
]]);
Class_Ouverture::clearCache();
Class_Bib::clearCache();
}
/** @test */
public function on29_12_2015_SelectedOpeningShouldBeStartEnd() {
ZendAfi_View_Helper_RenderLibraryOpening::setTimeSource(new TimeSourceForTest('2019-02-25 11:45:23'));
$this->assertXPathContentContains($this->_renderOpening($this->meythet),
'//p',
utf8_encode('Fermé. Réouverture Mardi à 14:30'));
}
}
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