diff --git a/VERSIONS_WIP/30973 b/VERSIONS_WIP/30973 new file mode 100644 index 0000000000000000000000000000000000000000..0483eb17d0603a0032fe405e92381a78538aeed7 --- /dev/null +++ b/VERSIONS_WIP/30973 @@ -0,0 +1 @@ + - ticket #30973 : Ajout d'un tableau récapitulatif des utilisations des ressources PNB dans l'interface d'administration. \ No newline at end of file diff --git a/application/modules/admin/controllers/AlbumController.php b/application/modules/admin/controllers/AlbumController.php index a84742522318889e575b67bbb84ad6d5ee5a5490..c212ce2007f7bbdd0f5032a37135d2c982a9d5f1 100644 --- a/application/modules/admin/controllers/AlbumController.php +++ b/application/modules/admin/controllers/AlbumController.php @@ -70,13 +70,13 @@ class Admin_AlbumController extends ZendAfi_Controller_Action { } - public function importDilicomAction() { - $this->view->titre = $this->_('Import des offres Dilicom/PNB'); + public function dilicomAction() { + $this->view->titre = $this->_('PNB Dilicom'); $form = $this->_formImportDilicom(); $this->view->form_import_dilicom = $form; if (!$this->_request->isPost()) - return; + return $this->view->dilicom_items = Class_Album_Item::findAll(); if ($form->isValid($this->_request->getPost()) && $form->offers->receive()) { $xml = file_get_contents($form->offers->getFileName()); @@ -95,6 +95,11 @@ class Admin_AlbumController extends ZendAfi_Controller_Action { } + public function dilicomExportCsvAction() { + $this->_helper->csv('dilicom_csv', Class_Album_Item::findAll()); + } + + public function importeadAction() { $this->view->titre = 'Import/Export EAD'; @@ -122,7 +127,7 @@ class Admin_AlbumController extends ZendAfi_Controller_Action { ->newForm(['id' => 'import_dilicom', 'class' => 'form']) ->setMethod('post') ->setAttrib('enctype', 'multipart/form-data') - ->setAction($this->view->url(['action' => 'import-dilicom'])) + ->setAction($this->view->url(['action' => 'dilicom'])) ->addElement($this->view->newFormElementFile('offers', 'xml'), 'offers') ->addElement('submit', 'submit', ['label' => $this->_('Importer le fichier XML')]); } diff --git a/application/modules/admin/controllers/IndexController.php b/application/modules/admin/controllers/IndexController.php index 2fdbe8da7df5cfc9a50274c2d7eb8a232002e9d0..c12ea844fabd464d15c179169bea9c056236ac42 100644 --- a/application/modules/admin/controllers/IndexController.php +++ b/application/modules/admin/controllers/IndexController.php @@ -70,6 +70,7 @@ class Admin_IndexController extends ZendAfi_Controller_Action { $this->view->url(['action' => 'adminvar'])); if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) { + xdebug_break(); $new_valeur = $form->getAdminVarValue(); $var->setValeur($new_valeur); diff --git a/application/modules/admin/views/scripts/album/dilicom.phtml b/application/modules/admin/views/scripts/album/dilicom.phtml new file mode 100644 index 0000000000000000000000000000000000000000..30818ccb98f4904fa26b60f50d296f3581aa034b --- /dev/null +++ b/application/modules/admin/views/scripts/album/dilicom.phtml @@ -0,0 +1,33 @@ +<?php +$title = function($model, $attrib) { + return $this->tagAnchor($this->url(['module' => 'admin', + 'controller' => 'album', + 'action' => 'edit_album', + 'id' => $model->getAlbumId()], null, true), + $model->getTitle()); +}; + +echo $this->tag('h2', $this->_('Utilisation des ressources PNB Dilicom')) . + $this->tagAnchor($this->url(['module' => 'admin', + 'controller' => 'album', + 'action' => 'dilicom-export-csv'], null, true), + $this->_('Exporter le tableau en CSV')). + $this->tagModelTable($this->dilicom_items, + [$this->_('Titre'), + $this->_('Nombre de prêts'), + $this->_('Nombre de prêts simultanés'), + $this->_('Durée de prêt en jours'), + $this->_('Nombre de jours restant sur la licence')], + ['title', + 'quantity_on_total', + 'live_quantity', + 'duration', + 'license_expiration'], + null, + 'pnb_dilicom', + null, + ['title' => $title], + true). +$this->tag('h2', $this->_('Import des offres Dilicom/PNB')). +$this->form_import_dilicom; +?> diff --git a/application/modules/admin/views/scripts/album/import-dilicom.phtml b/application/modules/admin/views/scripts/album/import-dilicom.phtml deleted file mode 100644 index 58ab1dc734421661400f852ddf19f1402498515a..0000000000000000000000000000000000000000 --- a/application/modules/admin/views/scripts/album/import-dilicom.phtml +++ /dev/null @@ -1 +0,0 @@ -<?php echo $this->form_import_dilicom; ?> diff --git a/library/Class/Album.php b/library/Class/Album.php index 1ed6fb0ba1d5b3b549a68584340c4a7904ce8438..877be8dc88752c3f0e7890779843ed63c5107aca 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -65,7 +65,7 @@ class AlbumLoader extends Storm_Model_Loader { class Class_Album extends Storm_Model_Abstract { - use Trait_TimeSource, Trait_Indexable, Trait_StaticFileSystem; + use Trait_TimeSource, Trait_Indexable, Trait_StaticFileSystem, Trait_Translator; const BASE_PATH = 'album/'; const THUMBS_PATH = 'thumbs/'; @@ -89,6 +89,8 @@ class Class_Album extends Storm_Model_Abstract { const STATUS_DRAFT = 1; const STATUS_VALIDATED = 3; + const RIGHT_PUBLIC_DOMAIN_KEY = 1; + const RIGHT_OTHER_KEY = 2; protected static $DEFAULT_THUMBNAIL_VALUES; @@ -1600,5 +1602,10 @@ class Class_Album extends Storm_Model_Abstract { public function renderOn($view) { return (new Class_Album_Renderer($this))->renderOn($view); } + + + public static function getPublicDomain() { + return (new self())->_('Domaine public'); + } } ?> \ No newline at end of file diff --git a/library/Class/Album/Item.php b/library/Class/Album/Item.php index bcc3fc242718668bfbb1dc4a7f65159c73867709..4da14b919bd7eae88b82512ba9ecfe61b032fd0d 100644 --- a/library/Class/Album/Item.php +++ b/library/Class/Album/Item.php @@ -24,5 +24,44 @@ class Class_Album_Item extends Storm_Model_Abstract { $_table_name = 'album_item', $_belongs_to = ['album' => ['model' => 'Class_Album']], $_default_attribute_values = ['loan_count' => 0]; + + + public function getTitle() { + return $this->getAlbum()->getTitre(); + } + + + public function getQuantityOnTotal() { + return $this->getQuantity() . ' / ' . $this->getAlbumUsageConstraints()->getLoanQuantity(); + } + + + public function getLiveQuantity() { + return $this->getLoanCount() . ' / ' . $this->getAlbumUsageConstraints()->getLoanAllowedNumberOfUsers(); + } + + + public function getDuration() { + return $this->getAlbumUsageConstraints()->getLoanDuration(); + } + + + public function getLicenseExpiration() { + return $this->getAlbumUsageConstraints()->getAvailabilityRemainingDaysBeforeEndDate(); + } + + + protected function getAlbumUsageConstraints() { + return $this->getAlbum()->getUsageConstraints(); + } + + + public function toCsv() { + return [$this->getTitle(), + $this->getQuantityOnTotal(), + $this->getLiveQuantity(), + $this->getDuration(), + $this->getLicenseExpiration()]; + } } ?> \ No newline at end of file diff --git a/library/Class/Album/UsageConstraint.php b/library/Class/Album/UsageConstraint.php index dd9f90c3dc88980249b76cbe656ddf8bc8b9c18f..796f9db2db2670d1ff0e747954d7103bef7cea03 100644 --- a/library/Class/Album/UsageConstraint.php +++ b/library/Class/Album/UsageConstraint.php @@ -38,13 +38,15 @@ class Class_Album_UsageConstraint extends Storm_Model_Abstract { DURATION = 'duration', QUANTITY = 'quantity', MAX_NB_OF_USERS = 'max_number_of_users', + ORDER_DATE = 'order_date', END_DATE = 'end_date'; protected $_table_name = 'album_usage_constraints', $_loader_class = 'Class_Album_UsageConstraintLoader', $_belongs_to = ['album' => ['model' => 'Class_Album']], - $_default_attribute_values = ['serialized_datas' => ''], + $_default_attribute_values = ['serialized_datas' => '', + 'usage_type' => null], $_datas; public function beforeSave() { @@ -71,6 +73,9 @@ class Class_Album_UsageConstraint extends Storm_Model_Abstract { public function getDuration() { $pnb_duration = (int)$this->getDatas()->get(self::DURATION); + if (!$this->isLoanConstraint()) + return $pnb_duration; + $max_duration = (int)Class_AdminVar::get('DILICOM_PNB_MAX_LOAN_DURATION'); if (!$max_duration) return $pnb_duration; @@ -90,6 +95,17 @@ class Class_Album_UsageConstraint extends Storm_Model_Abstract { } + public function getOrderDate() { + return $this->getDatas()->get(self::ORDER_DATE); + } + + + public function setOrderDate($value) { + $this->getDatas()->set(self::ORDER_DATE, $value); + return $this; + } + + public function setDuration($value) { $this->getDatas()->set(self::DURATION, $value); return $this; @@ -203,13 +219,8 @@ class Class_Album_UsageConstraint extends Storm_Model_Abstract { public function getEndDate() { - return $this->getDatas()->get(self::END_DATE); - } - - - public function setEndDate() { - $this->getDatas()->set(self::END_DATE, date(DATE_ISO8601, ($this->getCurrentTime() + ($this->getDuration() * 24 * 3600)))); - return $this; + return date(DATE_ISO8601, + strtotime($this->getOrderDate()) + ($this->getDuration() * 24 * 3600)); } diff --git a/library/Class/Album/UsageConstraints.php b/library/Class/Album/UsageConstraints.php index 743be1838f637f05c80844871aedb6d7c8659123..c20bd628f0232c74d9cc895df0a6ec96689fcd93 100644 --- a/library/Class/Album/UsageConstraints.php +++ b/library/Class/Album/UsageConstraints.php @@ -21,6 +21,8 @@ class Class_Album_UsageConstraints extends Storm_Model_Collection_Abstract { + use Trait_TimeSource; + public function getLoanConstraint() { return ($constraint = $this->detect(function($c) {return $c->isLoanConstraint();})) ? $constraint @@ -41,7 +43,12 @@ class Class_Album_UsageConstraints extends Storm_Model_Collection_Abstract { public function getLoanOrderLineId() { - return $this->getLoanConstraint()->getOrderLineId(); + return $this->getAvailabilityConstraint()->getOrderLineId(); + } + + + public function getLoanOrderDate() { + return $this->getAvailabilityConstraint()->getOrderDate(); } @@ -75,6 +82,11 @@ class Class_Album_UsageConstraints extends Storm_Model_Collection_Abstract { } + public function getAvailabilityRemainingDaysBeforeEndDate() { + return (int) floor((strtotime($this->getAvailabilityEndDate()) - $this->getTimeSource()->time()) / (3600 * 24)); + } + + public function isAValidOffer() { return $this->getAvailabilityConstraint()->isAValidOffer(); } diff --git a/library/Class/Loan/Pnb.php b/library/Class/Loan/Pnb.php index 2b49c9ee73ebe39f7aa75f8206470678c74494df..2a22690a71508db808d0b0dd036526127c425c9b 100644 --- a/library/Class/Loan/Pnb.php +++ b/library/Class/Loan/Pnb.php @@ -21,7 +21,10 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader { public function findAllOngoingOfUser($user) { - $loans = $this->findAllOngoingBy(['user_id' => $user->getId()]); + $loans = + array_merge( + $this->findAllOngoingBy(['subscriber_id' => $user->getIdabon()]), + $this->findAllOngoingBy(['user_id' => $user->getId()])); (new Class_WebService_BibNumerique_Dilicom_Hub()) ->updateLoansReturnDate($loans); diff --git a/library/Class/NatureDoc.php b/library/Class/NatureDoc.php index c26bf4fd3fa128b29f03b0832438dc8c59449ad7..bb53ed9ebc94fb171a92a61cbcbb1bfb951bd71d 100644 --- a/library/Class/NatureDoc.php +++ b/library/Class/NatureDoc.php @@ -16,11 +16,11 @@ * * 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 NatureDocLoader { - /** Les types de 1 à 12 correspondent au vocabulaire DCMI + /** Les types de 1 à 12 correspondent au vocabulaire DCMI * http://dublincore.org/documents/dcmi-type-vocabulary/#H7 */ public function langForLabel($libelle) { @@ -34,7 +34,7 @@ class NatureDocLoader { $id_labels = []; foreach($instances as $nature_doc) $id_labels[$nature_doc->getId()] = $nature_doc->getLibelle(); - + return $id_labels; } @@ -60,8 +60,11 @@ class NatureDocLoader { public function findAll() { $instances = []; - $lines = explode("\r\n", - Class_CosmoVar::find('nature_docs')->getListe()); + if(!$nature_doc = Class_CosmoVar::find('nature_docs')) + return $instances; + + $lines = explode("\r\n", + $nature_doc->getListe()); foreach($lines as $line) { $colon_pos = strpos($line, ':'); @@ -69,7 +72,7 @@ class NatureDocLoader { $instances[$id] = (new Class_NatureDoc())->updateAttributes(['id' => $id, 'libelle' => substr($line, $colon_pos+1)]); } - + return $instances; } } diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index d7eb99da60d09b8b021b20f2580095bff15d9db7..2eda53c4314dc700a29dfe0849aa725fb92a9b81 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -703,11 +703,18 @@ class Class_ScriptLoader { /** * @return ScriptLoader */ - public function loadTableSorter() { - return $this + public function loadTableSorter($pager = false) { + $this ->addOPACScript('tablesorter/js/jquery.tablesorter.min') ->addStyleSheet(BASE_URL."/public/opac/js/tablesorter/css/theme.default.css") ->addJQueryReady('$(".tablesorter").tablesorter()'); + + if ($pager) + $this + ->addOPACScript('tablesorter/addons/pager/jquery.tablesorter.pager.min') + ->addStyleSheet(BASE_URL."/public/opac/js/tablesorter/addons/pager/jquery.tablesorter.pager.css") + ->addJQueryReady('$(".tablesorter").tablesorterPager({container: $(".model_table_pager"),output: "{startRow} - {endRow} / {totalRows} ",fixedHeight: true,removeRows: false})'); + return $this; } diff --git a/library/Class/WebService/BibNumerique/Dilicom/Book.php b/library/Class/WebService/BibNumerique/Dilicom/Book.php index 05317bdca1a23f103374bb46f034af46baf9676a..3194f3dfa3282f88ea7d2b2c9bc44a07a9c62c48 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/Book.php +++ b/library/Class/WebService/BibNumerique/Dilicom/Book.php @@ -25,6 +25,7 @@ class Class_WebService_BibNumerique_Dilicom_Book extends Class_WebService_BibNum $_isbn, $_subtitle, $_order_line_id, + $_order_date, $_collections = [], $_usage_constraints = []; @@ -35,14 +36,16 @@ class Class_WebService_BibNumerique_Dilicom_Book extends Class_WebService_BibNum ->setISBN($this->_isbn) ->setSousTitre($this->_subtitle) ->addEditor($this->getEditeur()) + ->setDroits(Class_Album::RIGHT_OTHER_KEY) ->setUsageConstraints($this->_usage_constraints) ->addItem(new Class_Album_Item()); if ($this->_order_line_id) $album ->getUsageConstraints() - ->getLoanConstraint() - ->setOrderLineId($this->_order_line_id); + ->getAvailabilityConstraint() + ->setOrderLineId($this->_order_line_id) + ->setOrderDate($this->_order_date); array_map([$album, 'addCollection'], $this->_collections); } @@ -58,6 +61,11 @@ class Class_WebService_BibNumerique_Dilicom_Book extends Class_WebService_BibNum } + public function setOrderDate($data) { + $this->_order_date = $data; + } + + public function addCollection($collection) { $this->_collections []= $collection; } diff --git a/library/Class/WebService/BibNumerique/Dilicom/Hub.php b/library/Class/WebService/BibNumerique/Dilicom/Hub.php index 20ff11a3b5e9c55fad9e85cf2ef25e9b3da6b2f0..78f93afe6214d489bcfe3b73342fba0f70a1468a 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/Hub.php +++ b/library/Class/WebService/BibNumerique/Dilicom/Hub.php @@ -41,11 +41,13 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac public function updateStatus($album) { $content = $this->getLoanStatus($album); - if (isset($content->loanResponseLine[0]) - && ($simultaneous_users_remaining = $content->loanResponseLine[0]->nus1)) { + if (isset($content->loanResponseLine[0])) { + $simultaneous_users_remaining = $content->loanResponseLine[0]->nus1; $item = $album->getItems()[0]; + $item->setLoanCount($album->getUsageConstraints()->getLoanMaxNumberOfUsers() - $simultaneous_users_remaining); $item->setQuantity($album->getUsageConstraints()->getLoanQuantity() - $content->loanResponseLine[0]->nta); + $item->save(); } return $content; @@ -124,6 +126,8 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac return (object) ['link' => (object) ['url' => $loan->getLoanLink()], 'returnMessage' => []]; + $this->updateStatus($album); + if (!$album->getUsageConstraints()->hasSimultaneousLoanRemaining()) return (object) ['returnMessage' => [$this->_('Emprunt impossible. Le nombre d\'emprunts simultanés est atteint.')]]; @@ -158,11 +162,13 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac $content = json_decode($response); - $loan->setLoanLink($content->link->url)->save(); - - if($content->returnMessage) + if ($content->returnMessage) { $loan->delete(); + return $content; + } + $loan->setLoanLink($content->link->url)->save(); + $this->updateStatus($album); return $content; } diff --git a/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php b/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php index 9f1cc83ff5359bed01ba31e6be6b4aefdc451def..708840895c94b7569cef0f799a8980fac377d3cf 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php +++ b/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php @@ -212,7 +212,6 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { public function endEPubUsageLimit() { if ($this->_current_usage_unit == self::USAGE_UNIT_DAYS) { $this->_current_usage_constraint->setDuration($this->_current_quantity); - $this->_current_usage_constraint->setEndDate(); return; } diff --git a/library/Class/WebService/BibNumerique/Dilicom/PNBOffersFile.php b/library/Class/WebService/BibNumerique/Dilicom/PNBOffersFile.php index 72d3f0e71da829c0c8eea3b1415e0a0a6e803662..ecc04d7de956f7cccc905a67c10ce4c7f273c77c 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/PNBOffersFile.php +++ b/library/Class/WebService/BibNumerique/Dilicom/PNBOffersFile.php @@ -58,6 +58,11 @@ class Class_WebService_BibNumerique_Dilicom_PNBOffersFile { } + public function endOrderDate($data) { + end($this->_books)->setOrderDate($data); + } + + public function endean13($data) { end($this->_books)->setISBN($data); } diff --git a/library/ZendAfi/Controller/Action/Helper/Csv.php b/library/ZendAfi/Controller/Action/Helper/Csv.php new file mode 100644 index 0000000000000000000000000000000000000000..f8e52b8a0136bdd74d18416cc901aeea651c823d --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/Csv.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 ZendAfi_Controller_Action_Helper_Csv extends Zend_Controller_Action_Helper_Abstract { + + public function direct($filename, $data) { + Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); + + $csv = $this->encodeCsv($data); + + $filename = $filename . '.csv'; + + $response = $this->getResponse(); + $response->clearAllHeaders(); + + $response->setHeader('Content-Type', 'text/csv; name="'.$filename.'"', true); + $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"', true); + $response->setBody($csv); + } + + + protected function encodeCsv($data) { + return (new ZendAfi_View_Helper_Csv())->csv($data); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php index ef8cc3776c74d78fe2e2f110452c13c6d9618e2c..5bb42858de8062c6a1e898e03d41b8cd1abd8c4a 100644 --- a/library/ZendAfi/Form/Album.php +++ b/library/ZendAfi/Form/Album.php @@ -20,11 +20,6 @@ */ class ZendAfi_Form_Album extends ZendAfi_Form { - const RIGHT_PUBLIC_DOMAIN_KEY = 1; - const RIGHT_OTHER_KEY = 2; - const RIGHT_PUBLIC_DOMAIN = 'Domaine public'; - - protected $_simple_elements = ['titre', 'cat_id', 'type_doc_id', @@ -124,10 +119,11 @@ class ZendAfi_Form_Album extends ZendAfi_Form { public function init() { parent::init(); + Class_ScriptLoader::getInstance() ->addInlineScript('function toggleAlbumRights() { var target = $("#droits_precision").parent().parent(); - (' . self::RIGHT_OTHER_KEY . ' == $("input[name=\'droits\']:checked").val()) ? + (' . Class_Album::RIGHT_OTHER_KEY . ' == $("input[name=\'droits\']:checked").val()) ? target.show() : target.hide(); }') @@ -290,11 +286,11 @@ class ZendAfi_Form_Album extends ZendAfi_Form { * @return ZendAfi_Form_Album */ public function addRightsFor($album) { - $current = (self::RIGHT_PUBLIC_DOMAIN == $album->getDroits() || $album->isNew()) - ? self::RIGHT_PUBLIC_DOMAIN_KEY - : self::RIGHT_OTHER_KEY; + $current = (Class_Album::getPublicDomain() == $album->getDroits() || $album->isNew()) + ? Class_Album::RIGHT_PUBLIC_DOMAIN_KEY + : Class_Album::RIGHT_OTHER_KEY; - $current_precision = (self::RIGHT_PUBLIC_DOMAIN != $album->getDroits()) + $current_precision = (Class_Album::getPublicDomain() != $album->getDroits()) ? $album->getDroits() : ''; @@ -303,15 +299,15 @@ class ZendAfi_Form_Album extends ZendAfi_Form { ['label' => 'Droits', 'value' => $current, 'separator' => '', - 'multiOptions' => [self::RIGHT_PUBLIC_DOMAIN_KEY => self::RIGHT_PUBLIC_DOMAIN, - self::RIGHT_OTHER_KEY => $this->_('Autre, Précisez')]]) + 'multiOptions' => [Class_Album::RIGHT_PUBLIC_DOMAIN_KEY => Class_Album::getPublicDomain(), + Class_Album::RIGHT_OTHER_KEY => $this->_('Autre, Précisez')]]) ->addElement('text', 'droits_precision', ['label' => '', 'value' => $current_precision, 'style' => 'width:440px;']) - ->addElement('usageConstraints', 'usage_constraints', ['label' => 'Utilisations', + ->addElement('usageConstraints', 'usage_constraints', ['label' => 'Contraintes', 'value' => $album->getUsageConstraints()]); } @@ -359,14 +355,10 @@ class ZendAfi_Form_Album extends ZendAfi_Form { public function isPublicDomain() { - return self::RIGHT_PUBLIC_DOMAIN == $this->droits->getValue(); + return Class_Album::getPublicDomain() == $this->droits->getValue(); } - public function getPublicDomain() { - return self::RIGHT_PUBLIC_DOMAIN; - } - public function populateFrbrUrl($url) { $values = ['frbr_type' => [], 'frbr_url' => [$url]]; $this->frbr_multi diff --git a/library/ZendAfi/Validate/Dilicom/IpAdresses.php b/library/ZendAfi/Validate/Dilicom/IpAdresses.php index a7abfe37f35605974313e883a77eafd4587300e3..ec2e36066efb55dbdc16a39f5d3f486f9b6982b4 100644 --- a/library/ZendAfi/Validate/Dilicom/IpAdresses.php +++ b/library/ZendAfi/Validate/Dilicom/IpAdresses.php @@ -45,7 +45,7 @@ class ZendAfi_Validate_Dilicom_IpAdresses extends Zend_Validate_Abstract{ $this->_setValue(implode(',', $result->returnMessage)); - if ('OK' !== $result->returnStatus) { + if (!in_array($result->returnStatus, ['OK', 'WARNING'])) { $this->_error(self::DECLARE_IP_FAIL); return false; } diff --git a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php index 277f0d9376d571bcc602825999545cf7f73d5664..c3280182c57b0494296b61d34ea3e2c1bf2e455b 100644 --- a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php +++ b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php @@ -159,7 +159,7 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base Class_AdminVar::isBibNumEnabled() && $this->filterAdmin($this->user)) - .$this->addMenu("pnb_16.png", $this->translate()->_("Import offres Dilicom"), "/admin/album/import-dilicom", + .$this->addMenu("pnb_16.png", $this->translate()->_("PNB Dilicom"), "/admin/album/dilicom", Class_AdminVar::isDilicomPNBEnabled() && $this->filterAdmin($this->user)) diff --git a/library/ZendAfi/View/Helper/Album/UsageConstraints.php b/library/ZendAfi/View/Helper/Album/UsageConstraints.php index cfc5f7803e11f4cd9ed71c142c97e1e05f887db6..5602b71f569fc6add1f17a62e1a08a6f22f00fff 100644 --- a/library/ZendAfi/View/Helper/Album/UsageConstraints.php +++ b/library/ZendAfi/View/Helper/Album/UsageConstraints.php @@ -73,9 +73,12 @@ class ZendAfi_View_Helper_Album_UsageConstraints extends Zend_View_Helper_HtmlEl if (!isset($this->_data_labels)) $this->_data_labels = [ - 'duration' => $this->view->_('Durée (j)'), - 'quantity' => $this->view->_('Quantité'), - 'max_number_of_users' => $this->view->_('Nombre d\'utilisateurs') + Class_Album_UsageConstraint::DURATION => $this->view->_('Durée (j)'), + Class_Album_UsageConstraint::QUANTITY => $this->view->_('Quantité'), + Class_Album_UsageConstraint::ORDER_DATE => $this->view->_('Date de commande'), + Class_Album_UsageConstraint::END_DATE => $this->view->_('Date de fin'), + Class_Album_UsageConstraint::ORDER_LINE_ID => $this->view->_('Numéro de commande'), + Class_Album_UsageConstraint::MAX_NB_OF_USERS => $this->view->_('Nombre d\'utilisateurs') ]; return $this->_data_labels[$id]; diff --git a/library/ZendAfi/View/Helper/Csv.php b/library/ZendAfi/View/Helper/Csv.php new file mode 100644 index 0000000000000000000000000000000000000000..6bee99f57f218119385c63bd2d784a80609b0f12 --- /dev/null +++ b/library/ZendAfi/View/Helper/Csv.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 ZendAfi_View_Helper_Csv extends ZendAfi_View_Helper_BaseHelper { + public function csv($data) { + $fp_csv = fopen('php://memory', 'r+'); + + foreach($data as $element) + fputcsv($fp_csv, $element->toCsv(), ';'); + + rewind($fp_csv); + return stream_get_contents($fp_csv); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagDilicomWidget.php b/library/ZendAfi/View/Helper/TagDilicomWidget.php index 0ea70e2326b5113bcef18e8290e8c52e785ab907..bca19dee6af65aca8ec03b2b917be44ff24b655a 100644 --- a/library/ZendAfi/View/Helper/TagDilicomWidget.php +++ b/library/ZendAfi/View/Helper/TagDilicomWidget.php @@ -28,8 +28,6 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement $this->_album = $album; (new Class_WebService_BibNumerique_Dilicom_Hub())->updateStatus($album); - $infos = $this->view->tag('p', $this->getInfos()); - $iframe = $this->view->tag('iframe', null, ['src' => $this->_album->getExternalURI(), @@ -40,8 +38,7 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement $this->_user = Class_Users::getIdentity(); if (!$this->_user || $this->_user->hasRightAccessDilicom()) - $links = $infos - . $this->getConsultBookAnchor() + $links = $this->getConsultBookAnchor() . $this->getLoanBookAnchor(); return $links . $iframe; @@ -52,7 +49,7 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement return $this->getDilicomAnchor(['controller' => 'bib-numerique', 'action' => 'consult-book-ajax', 'id' => $this->_album->getId()], - $this->view->_('Consulter le livre en ligne'), + $this->view->_('Consulter le livre en ligne (depuis la médiathèque)'), ['data-popup' => 'true']); } @@ -66,23 +63,12 @@ class ZendAfi_View_Helper_TagDilicomWidget extends Zend_View_Helper_HtmlElement } - protected function getInfos() { - $item = Class_Album_Item::findFirstBy(['album_id' => $this->_album->getId()]); - - return sprintf('Nombre d\'emprunts total: %d / %d, Nombre d\'emprunts en cours: %d / %d', - $item->getQuantity(), - $this->_album->getUsageConstraints()->getLoanQuantity(), - $item->getLoanCount(), - $this->_album->getUsageConstraints()->getLoanAllowedNumberOfUsers()); - } - - protected function getDilicomAnchor($url, $label, $attribs = []) { return $this->view->tag('div', $this->view->tagAnchor($url, $label, - array_merge(['style' => 'padding: 5px;margin: 5px; border: 1px solid #aaa; border-radius: 3px;display: inline-block;'], - $attribs))); + $attribs), + ['class' => 'dilicom-action']); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagModelTable.php b/library/ZendAfi/View/Helper/TagModelTable.php index 9718d112ea03a157bfd4454cbc6f2cdc8ac116e4..4a1c7b0028503aa181b244b112b1c80276be5965 100644 --- a/library/ZendAfi/View/Helper/TagModelTable.php +++ b/library/ZendAfi/View/Helper/TagModelTable.php @@ -18,7 +18,7 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { +class ZendAfi_View_Helper_TagModelTable extends ZendAfi_View_Helper_BaseHelper { /** @var boolean */ protected $_hasActions = false; /** @var int */ @@ -39,32 +39,71 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { 'relations'); */ - public function tagModelTable($models, $cols, $attribs, $actions, $id, $group_by = null, $callbacks = []) { - Class_ScriptLoader::getInstance()->loadTableSorter(); + public function tagModelTable($models, $cols, $attribs, $actions, $id, $group_by = null, $callbacks = [], $pager = false) { + Class_ScriptLoader::getInstance()->loadTableSorter($pager); $this->_hasActions = 0 < count($actions); $this->_cols_count = count($attribs) + ($this->_hasActions ? 1 : 0); - return $this->tag('table', - $this->head($cols) - .$this->tbody($models, $attribs, $actions, $group_by, $callbacks), + $html = $this->_tag('table', + $this->head($cols) + .$this->tbody($models, $attribs, $actions, $group_by, $callbacks), ['id' => $id, 'class' => 'models tablesorter']); + + return $html . $this->_getPager($pager); + } + + + protected function _getPager($pager) { + if(!$pager) + return ''; + + $first = $this->_tag('span', '|<<' , ['class' => 'first', + 'style' => 'cursor:pointer']); + + $previous = $this->_tag('span', '<' , ['class' => 'first', + 'style' => 'cursor:pointer']); + + $page_display = $this->_tag('input', '', ['class' => 'pagedisplay']); + + $next = $this->_tag('span', '>' , ['class' => 'next', + 'style' => 'cursor:pointer']); + + $last = $this->_tag('span', '>>|' , ['class' => 'last', + 'style' => 'cursor:pointer']); + + $select = $this->view->formSelect('pagesize', + '', + ['class' => 'pagesize'], + ['10' => 10, + '20' => 20, + '30' => 30]); + $html = $first . + $previous . + $page_display. + $next . + $last . + $select; + + $form = $this->_tag('form', $html); + + return $this->_tag('div', $form, ['class' => 'pager model_table_pager']); } public function head($cols) { $cols_html = ''; foreach ($cols as $col) - $cols_html .= $this->tag('th', $col); + $cols_html .= $this->_tag('th', $col); - $actions = $this->_hasActions ? $this->tag('th', $this->view->_('Actions'), + $actions = $this->_hasActions ? $this->_tag('th', $this->view->_('Actions'), ['class' => 'actions', 'data-sorter' => 'false', 'style' => 'width:80px;']) : ''; - return $this->tag('thead', - $this->tag('tr', $cols_html . $actions)); + return $this->_tag('thead', + $this->_tag('tr', $cols_html . $actions)); } @@ -83,9 +122,8 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { $groups['no_group'] = $models; } - return $this - ->tag('tbody', - $this->renderGroupsAsTableRows($groups, $attribs, $actions, $callbacks)); + return $this->_tag('tbody', + $this->renderGroupsAsTableRows($groups, $attribs, $actions, $callbacks)); } @@ -94,8 +132,8 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { foreach ($groups as $name => $groupModels) { if ('no_group' != $name && '' != $name) - $rows .= $this->tag('tr', - $this->tag('td', + $rows .= $this->_tag('tr', + $this->_tag('td', $this->view->escape($name), ['style' => 'background-color:#888;color:white;font-size:120%;padding:2px 10px;font-weight:bold;', 'colspan' => $this->_cols_count])); @@ -124,13 +162,13 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { foreach ($attribs as $attrib) { $callback = (array_key_exists($attrib, $callbacks)) ? $callbacks[$attrib] : $default_callback; - $cols .= $this->tag('td', $callback($model, $attrib)); + $cols .= $this->_tag('td', $callback($model, $attrib)); } $actions = ($this->_hasActions) ? - $this->tag('td', $this->renderModelActions($model, $actions)) : ''; + $this->_tag('td', $this->renderModelActions($model, $actions)) : ''; - return $this->tag('tr', $cols . $actions); + return $this->_tag('tr', $cols . $actions); } @@ -162,12 +200,5 @@ class ZendAfi_View_Helper_TagModelTable extends Zend_View_Helper_HtmlElement { 'id' => $model->getId()), is_a($content, 'Closure') ? $content($model) : $content); } - - - /** shortcut to $this->view->tag() */ - protected function tag() { - return call_user_func_array([$this->view, 'tag'], func_get_args()); - } } - ?> diff --git a/public/opac/css/global.css b/public/opac/css/global.css index 5eda721668d96e20445648507a8e0b84e359741d..960b40298a1e7e304246647a67dc26614713485c 100644 --- a/public/opac/css/global.css +++ b/public/opac/css/global.css @@ -3177,9 +3177,26 @@ a.loan-export { #opac-dialog div.popup-content { padding: 5px; + max-width: 500px; + text-align: center; +} + +#opac-dialog div.popup-content p { + text-align: justify; } #opac-dialog div.popup-content, #opac-dialog div.popup-content * { vertical-align: middle; +} + + +.dilicom-action { + padding: 5px; + margin: 10px; + border: 1px solid #aaa; + border-radius: 3px; + display: inline-block; + font-weight:bold; + font-size: 1.1em; } \ No newline at end of file diff --git a/scripts/dilicom_update_all.php b/scripts/dilicom_update_all.php new file mode 100644 index 0000000000000000000000000000000000000000..0975a7bcf1c70ddb4c2d9f7dd6a62f4cb5a9555e --- /dev/null +++ b/scripts/dilicom_update_all.php @@ -0,0 +1,10 @@ +<?php +error_reporting(E_ERROR | E_PARSE); +require(__DIR__.'/../console.php'); +$hub = new Class_WebService_BibNumerique_Dilicom_Hub(); +$items = Class_Album_Item::findAll(); +foreach($items as $item) { + $content = $hub->updateStatus($item->getAlbum()); + echo 'updated [' . $content->returnStatus . '] ' .$item->getAlbum()->getTitre()."\n"; +} +?> \ No newline at end of file diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index a9d088908c85ab0e42a260b471c1a6e8e97bbddc..29948e1cf7b1202303957c4c4b52d0fd75185c8d 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -276,13 +276,14 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe return is_array($data) && isset($data[ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION]); }); - foreach($messages as $message){ - if (false!==strpos($message[ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION]['message'], + foreach($messages as $flash_message){ + if (false!==strpos($flash_message[ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION]['message'], $value)) return; } - $this->fail("Flash messenger does not contains: \n".$value."\nbut:\n".implode('. ', $messages)."\n".$message); + $content = print_r($messages, true); + $this->fail("Flash messenger does not contains: \n".$value."\nbut:\n".$content."\n".$message); } diff --git a/tests/application/modules/admin/controllers/AdminIndexControllerTest.php b/tests/application/modules/admin/controllers/AdminIndexControllerTest.php index e4e5b415c647190e45e3e9484a28227b5e0a0453..5938cfe307509afac31d27b748e3e04073350edc 100644 --- a/tests/application/modules/admin/controllers/AdminIndexControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminIndexControllerTest.php @@ -534,8 +534,12 @@ abstract class AdminIndexControllerDilicomPnbIpAdressesTestCase extends Admin_Ab ->whenCalled('setAuth')->answers(null) ->whenCalled('open_url')->answers(json_encode(['returnStatus' => 'OK', 'returnMessage' => []])); + + Class_AdminVar::set('DILICOM_PNB_IP_ADRESSES', ''); + RessourcesNumeriquesFixtures::activateDilicom(); + Class_WebService_BibNumerique_Dilicom_Hub::setDefaultHttpClient($this->_http); } @@ -604,8 +608,8 @@ class AdminIndexControllerAdminVarDilicomDeclareIpPostTest extends AdminIndexCon $this->postDispatch('/admin/index/adminvaredit/cle/DILICOM_PNB_IP_ADRESSES', ['cle' => 'DILICOM_PNB_IP_ADRESSES', - 'valeurs' => ['xxx', - '123.156.15.3']]); + 'values' => ['xxx', + '123.156.15.3']]); $this->assertXPathContentContains('//div//ul[@class="errors"]/li', 'xxx is not a valid address'); } @@ -617,8 +621,8 @@ class AdminIndexControllerAdminVarDilicomDeclareIpPostTest extends AdminIndexCon $this->postDispatch('/admin/index/adminvaredit/cle/DILICOM_PNB_IP_ADRESSES', ['cle' => 'DILICOM_PNB_IP_ADRESSES', - 'valeurs' => ['xxx', - '123.156.15.3']]); + 'values' => ['xxx', + '123.156.15.3']]); $this->assertXPathContentContains('//div//ul[@class="errors"]/li', 'configuration du PNB Dilicom incomplète'); } @@ -631,11 +635,26 @@ class AdminIndexControllerAdminVarDilicomDeclareIpPostTest extends AdminIndexCon $this->postDispatch('/admin/index/adminvaredit/cle/DILICOM_PNB_IP_ADRESSES', ['cle' => 'DILICOM_PNB_IP_ADRESSES', - 'valeur' => ['xxx', + 'values' => ['xxx', '123.156.15.3']]); $this->assertXPathContentContains('//div//ul[@class="errors"]/li', 'échec de communication avec le serveur PNB Dilicom'); } + + + /** @test */ + public function hubWarningMessageShouldNotPreventSave() { + $this->_http->whenCalled('open_url') + ->answers(json_encode(['requestId' => 'xxx', + 'returnStatus' => 'WARNING', + 'returnMessage' => ['xxx is already declared']])); + + $this->postDispatch('/admin/index/adminvaredit/cle/DILICOM_PNB_IP_ADRESSES', + ['cle' => 'DILICOM_PNB_IP_ADRESSES', + 'values' => ['123.156.15.3']]); + + $this->assertEquals('123.156.15.3', Class_AdminVar::get('DILICOM_PNB_IP_ADRESSES')); + } } diff --git a/tests/application/modules/admin/controllers/AlbumControllerDilicomPNBTest.php b/tests/application/modules/admin/controllers/AlbumControllerDilicomPNBTest.php index ef8a301933cf36237be404f89c364d027ec21679..5d2ef1490dd08ed9127d2e34b3f890cc00f778cb 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerDilicomPNBTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerDilicomPNBTest.php @@ -19,30 +19,121 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class AlbumControllerDilicomPNBEditTest extends Admin_AbstractControllerTestCase { +abstract class Admin_AlbumControllerDilicomPNBTestCase extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { parent::setUp(); $this->fixture('Class_Album', ['id' => 23, 'titre' => 'Being human being', + 'type_doc_id' => Class_TypeDoc::DILICOM, 'usage_constraints' => - [ - $this->fixture('Class_Album_UsageConstraint', - ['id' => 1, - 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, - 'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 45, - Class_Album_UsageConstraint::QUANTITY => 30, - Class_Album_UsageConstraint::MAX_NB_OF_USERS => 15])]), - - $this->fixture('Class_Album_UsageConstraint', - ['id' => 2, - 'usage_type' => Class_Album_UsageConstraint::DEVICE_SHARE_CONSTRAINT, - 'serialized_datas' => json_encode([Class_Album_UsageConstraint::QUANTITY => 6])]) - ] - ]); + [ + $this->fixture('Class_Album_UsageConstraint', + ['id' => 1, + 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, + 'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 45, + Class_Album_UsageConstraint::QUANTITY => 30, + Class_Album_UsageConstraint::MAX_NB_OF_USERS => 15])]), + + $this->fixture('Class_Album_UsageConstraint', + ['id' => 2, + 'usage_type' => Class_Album_UsageConstraint::DEVICE_SHARE_CONSTRAINT, + 'serialized_datas' => json_encode([Class_Album_UsageConstraint::QUANTITY => 6])]), + + + $this->fixture('Class_Album_UsageConstraint', + ['id' => 3, + 'usage_type' => Class_Album_UsageConstraint::AVAILABILITY_CONSTRAINT, + 'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 2345, + Class_Album_UsageConstraint::ORDER_LINE_ID => '12385', + Class_Album_UsageConstraint::END_DATE => '2015-03-30'])]) + ] + ]); + + $this->fixture('Class_Album_Item', + ['id' => 1, + 'quantity' => '10', + 'loan_count' => '2', + 'album_id' => 23]); + + $this->fixture('Class_Album_Item', + ['id' => 2, + 'quantity' => '20', + 'loan_count' => '5', + 'album_id' => 23]); + + } +} + + + +class AlbumControllerDilicomPNBImportDilicomTest extends Admin_AlbumControllerDilicomPNBTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/album/dilicom', true); + } + + + /** @test */ + public function tableSorterPagerJsShouldBeLoaded() { + $this->assertXPath('//script[contains(@src, "tablesorter/addons/pager/jquery.tablesorter.pager.min")]'); + } + + + /** @test */ + public function tableSorterPagerCSSShouldBeLoaded() { + $this->assertXPath('//link[contains(@href, "/public/opac/js/tablesorter/addons/pager/jquery.tablesorter.pager.css")]'); + } + + + /** @test */ + public function tableSorterPagerShouldBeActivated() { + $this->assertXPathContentContains('//script', + 'tablesorterPager({container:'); + } + + /** @test */ + public function beingHumanTitleShouldBeInTalbe() { + $this->assertXPathContentContains('//table//tr/td/a[contains(@href, "/edit_album/id/23")]', 'Being human being'); + } + + + /** @test */ + public function nbOfLoansShouldBe30() { + $this->assertXPathContentContains('//table//tr/td', '10 / 30'); + } + + + /** @test */ + public function nbOfLiveLoansShouldBe2() { + $this->assertXPathContentContains('//table//tr/td', '2 / 15'); + } + + + /** @test */ + public function nbOfRemainingDaysInLicenseShouldBe45() { + $this->assertXPathContentContains('//table//tr/td', '45'); + } + + + /** @test */ + public function exportCSVAnchorShouldBePresent() { + $this->assertXPathContentContains('//div[@class="modules"]/a[contains(@href, "/admin/album/dilicom-export-csv")]', 'Exporter le tableau en CSV'); + } +} + + + +class AlbumControllerDilicomPNBEditTest extends Admin_AlbumControllerDilicomPNBTestCase { + public function setUp() { + parent::setUp(); $this->dispatch('/admin/album/editalbum/id/23', true); } @@ -77,6 +168,18 @@ class AlbumControllerDilicomPNBEditTest extends Admin_AbstractControllerTestCase } + /** @test */ + public function dddldtShouldContainsDateDeFin() { + $this->assertXPathContentContains('//fieldset//dl/dd/dl/dt', 'Date de fin'); + } + + + /** @test */ + public function dddldtShouldContainsNumeroCommande() { + $this->assertXPathContentContains('//fieldset//dl/dd/dl/dt', 'Numéro de commande'); + } + + /** @test */ public function dtInUsageShouldContainsAuthorizedDevices() { $this->assertXPathContentContains('//fieldset//dl//dt', 'Appareils autorisés'); @@ -114,4 +217,69 @@ class AlbumControllerDilicomPNBEditPostTest extends Admin_AbstractControllerTest } } -?> \ No newline at end of file + + +class AlbumControllerDilicomPNBImportDilicomPaginatorTest extends Admin_AlbumControllerDilicomPNBTestCase { + public function setUp() { + parent::setUp(); + $this->generateDilicomAlbums(); + $this->dispatch('admin/album/dilicom', true); + } + + + /** @test */ + public function contextShouldExpectation() { + $this->assertXPathContentContains('//div[@class="pager model_table_pager"]', '1', $this->_response->getBody()); + } + + + protected function generateDilicomAlbums() { + for($id=50; $id<=75; $id++) { + $this->fixture('Class_Album', + ['id' => $id, + 'titre' => 'Being human n°' . $id, + 'type_doc_id' => Class_TypeDoc::DILICOM, + 'usage_constraints' => + [ + $this->fixture('Class_Album_UsageConstraint', + ['id' => 1000 + $id, + 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, + 'serialized_datas' => json_encode([Class_Album_UsageConstraint::DURATION => 45, + Class_Album_UsageConstraint::QUANTITY => 30, + Class_Album_UsageConstraint::MAX_NB_OF_USERS => 15])]), + + $this->fixture('Class_Album_UsageConstraint', + ['id' => 100 + $id, + 'usage_type' => Class_Album_UsageConstraint::DEVICE_SHARE_CONSTRAINT, + 'serialized_datas' => json_encode([Class_Album_UsageConstraint::QUANTITY => 6])]) + ] + ]); + } + } +} + + + +class Admin_AlbumControllerDilicomPNBExportCsvTest extends Admin_AlbumControllerDilicomPNBTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('admin/album/dilicom-export-csv', true); + } + + + /** @test */ + public function filenameShouldBeDilicomCsv() { + $this->assertContains(['name' => 'Content-Type', + 'value' => 'text/csv; name="dilicom_csv.csv"', + 'replace' => true], $this->_response->getHeaders()); + } + + + /** @test */ + public function csvShouldContainsAlbumsItems() { + $this->assertEquals('"Being human being";"10 / 30";"2 / 15";45;-14429 +"Being human being";"20 / 30";"5 / 15";45;-14429 +', $this->_response->getBody()); + } +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index f9d229f90449267365ba0510f506930757e06076..607ef737d4b2c370d79648cc1639243986dbf112 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -2633,19 +2633,31 @@ class Admin_AlbumControllerImportEADTest extends Admin_AlbumControllerTestCase { class Admin_AlbumControllerImportDilicomTest extends Admin_AlbumControllerTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/admin/album/import-dilicom', true); + $this->dispatch('/admin/album/dilicom', true); } /** @test */ - public function titleShouldBeImportOffresPNB() { - $this->assertXPathContentContains('//h1', 'Import des offres Dilicom/PNB'); + public function titleShouldBeImportPnbDilicom() { + $this->assertXPathContentContains('//h1', 'PNB Dilicom'); + } + + + /** @test */ + public function importOffresPnbDilicomShouldBePresent() { + $this->assertXPathContentContains('//h2', 'Import des offres Dilicom/PNB'); + } + + + /** @test */ + public function usedRessourcesShouldBePresent() { + $this->assertXPathContentContains('//h2', 'Utilisation des ressources PNB Dilicom'); } /** @test */ public function formImportOffersShouldContainsFileInputForXML() { - $this->assertXPath('//form[contains(@action, "admin/album/import-dilicom")]//input[@type="file"][@name="offers"]'); + $this->assertXPath('//form[contains(@action, "admin/album/dilicom")]//input[@type="file"][@name="offers"]'); } diff --git a/tests/application/modules/admin/controllers/IndexControllerTest.php b/tests/application/modules/admin/controllers/IndexControllerTest.php index 652d3ed1fe7d528477d6eed0bb9764b73ce61aea..92ad891ff35aebdeabfd04462cad4266c2a9e63e 100644 --- a/tests/application/modules/admin/controllers/IndexControllerTest.php +++ b/tests/application/modules/admin/controllers/IndexControllerTest.php @@ -18,10 +18,20 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + require_once 'AdminAbstractControllerTestCase.php'; +abstract class Admin_IndexControllerTestCase extends Admin_AbstractControllerTestCase { + protected + $_storm_default_to_volatile = true, + $_cms_menu_path = '//div[@class="menuGaucheAdmin"][.//td[text()="Gestionnaire de contenu"]]', + $_bibnum_menu_path = '//div[@class="menuGaucheAdmin"][.//td[text()="Bibliothèque numérique"]]'; +} + + + +class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { -class IndexControllerIndexTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); $this->fixture('Class_AdminVar', @@ -51,6 +61,7 @@ class IndexControllerIndexTest extends Admin_AbstractControllerTestCase { $this->assertXPathContentContains('//div/b', 'http://bokeh-library-portal.org'); } + /** @test */ public function channelAccessShouldPresent() { $this->assertXPathContentContains('//div[@class="modules"]/h2', 'Salle de discussion #Bokeh :'); @@ -83,17 +94,7 @@ class IndexControllerIndexTest extends Admin_AbstractControllerTestCase { -abstract class IndexControllerIndexSitothequeTestCase extends Admin_AbstractControllerTestCase { - protected - $_storm_default_to_volatile = true, - $_cms_menu_path = '//div[@class="menuGaucheAdmin"][.//td[text()="Gestionnaire de contenu"]]', - $_bibnum_menu_path = '//div[@class="menuGaucheAdmin"][.//td[text()="Bibliothèque numérique"]]'; - -} - - - -class IndexControllerIndexDefaultSitothequeTest extends IndexControllerIndexSitothequeTestCase { +class Admin_IndexControllerSitothequeTest extends Admin_IndexControllerTestCase { public function setUp() { parent::setUp(); $this->dispatch('/admin/index/index'); @@ -115,7 +116,7 @@ class IndexControllerIndexDefaultSitothequeTest extends IndexControllerIndexSito -class IndexControllerIndexSitothequeInAlbumsTest extends IndexControllerIndexSitothequeTestCase { +class Admin_IndexControllerSitothequeInAlbumsTest extends Admin_IndexControllerTestCase { public function setUp() { parent::setUp(); $this->fixture('Class_AdminVar', ['id' => 'BIBNUM', 'valeur' => '1']); @@ -138,7 +139,7 @@ class IndexControllerIndexSitothequeInAlbumsTest extends IndexControllerIndexSit -class IndexControllerHeartBeatTest extends Admin_AbstractControllerTestCase { +class Admin_IndexControllerHeartBeatTest extends Admin_IndexControllerTestCase { /** @test */ public function adminPageShouldContainsHeartbeatScript() { $this->dispatch('/admin/index/index', true); @@ -155,7 +156,7 @@ class IndexControllerHeartBeatTest extends Admin_AbstractControllerTestCase { -class IndexControllerClearCacheActionTest extends Admin_AbstractControllerTestCase { +class Admin_IndexControllerClearCacheActionTest extends Admin_IndexControllerTestCase { public function setUp() { parent::setUp(); Storm_Cache::beVolatile(); @@ -168,3 +169,28 @@ class IndexControllerClearCacheActionTest extends Admin_AbstractControllerTestCa $this->assertRedirectTo('/admin/index/adminvar'); } } + + + +class Admin_IndexControllerDilicomTest extends Admin_IndexControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_AdminVar', + ['id' => 'DILICOM_PNB_GLN_CONTRACTOR', + 'clef' => 'DILICOM_PNB_GLN_CONTRACTOR', + 'valeur' => 1]); + + $this->fixture('Class_AdminVar', + ['id' => 'DILICOM_PNB_SERVER_URL', + 'clef' => 'DILICOM_PNB_SERVER_URL', + 'valeur' => 1]); + + $this->dispatch('/admin/index/index', true); + } + +/** @test */ + public function PnbDilicomnShouldBePresent() { + $this->assertXPathContentContains($this->_bibnum_menu_path . '//a', 'PNB Dilicom'); + } +} \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php index 15ee9fcca23e85a806b43a897cff0778c1020641..45247d9063076d71cae03a714802e12f42a546e8 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php @@ -43,6 +43,7 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT $this->florence = $this->fixture('Class_Users', ['id' => '123456', 'login' => 'flo', + 'idabon' => 'x234', 'password' => 'flo']); $this->zend_cache = Storm_Test_ObjectWrapper::mock(); @@ -70,6 +71,9 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT ->with('test-gln', 'test-gln-pass') ->answers(null) + ->whenCalled('open_url') + ->answers('') + ->whenCalled('open_url') ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5') ->answers(DilicomFixtures::getEndedLoansResponse()) @@ -150,7 +154,7 @@ abstract class AbonneControllerPretsListThreePretsTestCase extends AbstractAbonn $this->fixture('Class_Loan_Pnb', ['id' => 5, - 'user_id' => $this->florence->getId(), + 'subscriber_id' => $this->florence->getIdabon(), 'ongoing' => true, 'expected_return_date' => '2022-05-02T18:14:14+02:00', 'album' => $this->fixture('Class_Album', @@ -160,6 +164,20 @@ abstract class AbonneControllerPretsListThreePretsTestCase extends AbstractAbonn 'titre' => 'Pinocchio'])->addAuthor('Collodi') ]); + + $this->fixture('Class_Loan_Pnb', + ['id' => 6, + 'user_id' => $this->florence->getId(), + 'ongoing' => true, + 'expected_return_date' => '2020-01-01T18:14:14+02:00', + 'album' => $this->fixture('Class_Album', + ['id' => 5, + 'notice_id' => 6, + 'id_origine' => 'Dilicom-88817217', + 'titre' => 'Peter Pan']) + ]); + + $this->florence ->setFicheSigb(['type_comm' => 2, //OPSYS 'fiche' => $emprunteur, @@ -366,21 +384,30 @@ class AbonneControllerPretsListThreePretsTest extends AbonneControllerPretsListT /** @test */ - public function pinocchioPnbLoanReturnDateShouldBeAsExpected() { + public function pinocchioPnbLoanReturnDateShouldBe2022() { $this->assertXPathContentContains('//tbody//td[@class="date_retour"]', '2022-05-02T18:14:14+02:00'); } + + + /** @test */ + public function peterPanPnbLoanReturnDateShouldBe2020() { + $this->assertXPathContentContains('//tbody//td[@class="date_retour"]', + '2020-01-01T18:14:14+02:00'); + } } + + class AbonneControllerPretsListThreePretsPnbEarlyReturnTest extends AbonneControllerPretsListThreePretsTestCase { public function setUp() { parent::setUp(); $this->_http ->whenCalled('open_url') - ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5') + ->with('/v2/pnb-numerique/json/getEndedLoans?glnContractor=777&loanId[0]=5&loanId[1]=6') ->answers(DilicomFixtures::getEndedLoansResponse(['{"loanId":"5","returnDate":"2015-09-18T14:30:00+02:00"}'])) ->beStrict(); @@ -391,7 +418,7 @@ class AbonneControllerPretsListThreePretsPnbEarlyReturnTest extends AbonneContro /** @test */ public function pnbTitleShouldNotBePresent() { $this->assertNotXpathContentContains('//h2', - utf8_encode('Prêts numériques en cours')); + 'Prêts numériques en cours'); } diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php index a0aa0de6477255cf8400944a1bcd5601f70f8eed..dd93e5b2a79114db72d350d0d628729be2a311c6 100644 --- a/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php +++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerDilicomTest.php @@ -67,14 +67,14 @@ abstract class BibNumeriqueContollerDilicomTestCase extends AbstractControllerTe 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, Class_Album_UsageConstraint::MAX_NB_OF_USERS => 40, Class_Album_Usageconstraint::QUANTITY => 50, - Class_Album_UsageConstraint::DURATION => '100', - 'order_line_id' => 'x321']), + Class_Album_UsageConstraint::DURATION => '100']), $this->fixture('Class_Album_UsageConstraint', ['id' => 2, 'album_id' => 3, 'usage_type' => Class_Album_UsageConstraint::AVAILABILITY_CONSTRAINT, + Class_Album_UsageConstraint::ORDER_LINE_ID => 'x321', Class_Album_UsageConstraint::DURATION => '100', - Class_Album_UsageConstraint::END_DATE => '2018-04-01 00:00:00'])]]); + Class_Album_UsageConstraint::ORDER_DATE => '2015-04-01 00:00:00'])]]); RessourcesNumeriquesFixtures::activateDilicom(); @@ -85,7 +85,12 @@ abstract class BibNumeriqueContollerDilicomTestCase extends AbstractControllerTe $this->_http ->whenCalled('setAuth') ->with('afi-bib', 'secretPassword') - ->answers(null); + ->answers(null) + + ->whenCalled('open_url') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->answers(DilicomFixtures::getLoanStatusResponse()); + $this->_time_source = new TimeSourceForTest('2014-05-02 14:14:14'); Class_WebService_BibNumerique_Dilicom_Hub::setTimeSource($this->_time_source); @@ -317,10 +322,24 @@ class BibNumeriqueControllerDilicomLoanBookActionTest extends BibNumeriqueContol Class_AdminVar::set('DILICOM_PNB_LOAN_COUNT_LIMIT', 0); + $update_status_url = 'https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321'; + $this->_http ->whenCalled('open_url') ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/loanBook?glnContractor=123456789&orderLineId=x321&accessMedium=DOWNLOAD&glnColl=afi-bib&loanerColl=2345889&localization=EX_SITU&loanEndDate=2014-08-10T14%3A14%3A14%2B0200&ean13=435465&loanId=1') ->answers(DilicomFixtures::loanBookResponse()) + + + ->whenCalled('open_url') + ->with($update_status_url) + ->willDo(function() use ($update_status_url) + { + $this->_http + ->whenCalled('open_url') + ->with($update_status_url) + ->answers(DilicomFixtures::getLoanStatusAfterLoanResponse()); + return DilicomFixtures::getLoanStatusResponse(); + }) ->beStrict(); $this->dispatch('/bib-numerique/loan-book/id/3', true); @@ -343,6 +362,12 @@ class BibNumeriqueControllerDilicomLoanBookActionTest extends BibNumeriqueContol public function loanUrlShouldHaveBeenSaved() { $this->assertEquals('https://pnb-dilicom.centprod.com/v2//link/3025594195810/LOAN/WIKI001/9782021153057-NUMOIY0785CYO0IGCV83DE9DOAOC1Y1O.do', Class_Loan_Pnb::findFirstBy(['record_origin_id' => 'Dilicom-88817216'])->getLoanLink()); } + + + /** @test */ + public function itemQuantityShouldEqualsTwentySeven() { + $this->assertEquals(27, $this->book->getItems()[0]->getQuantity()); + } } @@ -456,7 +481,13 @@ abstract class BibNumeriqueContollerDilicomSecondUserTestCase extends BibNumeriq class BibNumeriqueControllerDilicomLoanBookActionWithASecondUserAndLoanCountExcededTest extends BibNumeriqueContollerDilicomSecondUserTestCase { public function setUp() { parent::setUp(); - Class_Album_Item::find(1)->setLoanCount(40)->save(); + + $this->_http + ->whenCalled('open_url') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->answers(DilicomFixtures::getLoanStatusNoSimultaneousLoanLeftResponse()) + ->beStrict(); + $this->dispatch('/bib-numerique/loan-book/id/3', true); } @@ -541,11 +572,23 @@ class BibNumeriqueControllerDilicomLoanBookActionUserLoanCountExceededTest exten class BibNumeriqueControllerDilicomLoanBookActionWithASecondUserAndQuantityExcededTest extends BibNumeriqueContollerDilicomSecondUserTestCase { public function setUp() { parent::setUp(); - Class_Album_Item::find(1)->setQuantity(50)->save(); + $this->_http + ->whenCalled('open_url') + ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') + ->answers(DilicomFixtures::getLoanStatusNoQuantityLeftResponse()); + $this->dispatch('/bib-numerique/loan-book/id/3', true); } + + + /** @test */ + public function albumShouldHaveBeenUpdateThroughHubGetLoanStatus() { + $this->assertContains('getLoanStatus', $this->_http->getFirstAttributeForLastCallOn('open_url')); + } + + /** @test */ public function responseShouldRedirectToReferer() { $this->assertRedirectTo('/recherche/viewnotice/id/3'); diff --git a/tests/fixtures/DilicomFixtures.php b/tests/fixtures/DilicomFixtures.php index d71f9ffc70df58033803496c0d5bf21b05a9bce7..4d2dcea1299e52723345139121f254a7a26615fd 100644 --- a/tests/fixtures/DilicomFixtures.php +++ b/tests/fixtures/DilicomFixtures.php @@ -97,6 +97,60 @@ class DilicomFixtures { } + public static function getLoanStatusAfterLoanResponse() { + return '{ + "date" : "2014-08-14T11:32:12.786+02:00", + "returnStatus" : "OK", + "returnMessage" : [ ], + "loanResponseLine" : [ { + "returnStatus" : "OK", + "orderLineId" : "537119f5975a1d3260801864", + "nta" : 23, + "nus1" : 4, + "nus2" : 30, + "beginDate" : "2014-05-12T20:59:03+02:00", + "endDate" : "2015-05-12T20:59:03+02:00" + } ] +}'; + } + + + public static function getLoanStatusNoQuantityLeftResponse() { + return '{ + "date" : "2014-08-14T11:32:12.786+02:00", + "returnStatus" : "OK", + "returnMessage" : [ ], + "loanResponseLine" : [ { + "returnStatus" : "OK", + "orderLineId" : "537119f5975a1d3260801864", + "nta" : 0, + "nus1" : 5, + "nus2" : 30, + "beginDate" : "2014-05-12T20:59:03+02:00", + "endDate" : "2015-05-12T20:59:03+02:00" + } ] +}'; + } + + + public static function getLoanStatusNoSimultaneousLoanLeftResponse() { + return '{ + "date" : "2014-08-14T11:32:12.786+02:00", + "returnStatus" : "OK", + "returnMessage" : [ ], + "loanResponseLine" : [ { + "returnStatus" : "OK", + "orderLineId" : "537119f5975a1d3260801864", + "nta" : 24, + "nus1" : 0, + "nus2" : 30, + "beginDate" : "2014-05-12T20:59:03+02:00", + "endDate" : "2015-05-12T20:59:03+02:00" + } ] +}'; + } + + public static function getLoanStatusErrorResponse() { return '{ "date" : "2014-08-14T11:32:12.786+02:00", @@ -133,13 +187,13 @@ class DilicomFixtures { 'album_id' => 3, 'usage_type' => Class_Album_UsageConstraint::LOAN_CONSTRAINT, Class_Album_UsageConstraint::MAX_NB_OF_USERS => 50, - Class_Album_Usageconstraint::QUANTITY => 50, - 'order_line_id' => 'x321']), + Class_Album_Usageconstraint::QUANTITY => 50]), $this->fixture('Class_Album_UsageConstraint', ['id' => 2, 'album_id' => 3, 'usage_type' => Class_Album_UsageConstraint::AVAILABILITY_CONSTRAINT, - Class_Album_UsageConstraint::DURATION => '100', - Class_Album_UsageConstraint::END_DATE => '2018-04-01 00:00:00'])]]); + Class_Album_UsageConstraint::DURATION => '10000', + Class_Album_UsageConstraint::ORDER_DATE => '2015-04-01 00:00:00', + 'order_line_id' => 'x321'])]]); } } \ No newline at end of file diff --git a/tests/library/Class/WebService/Dilicom/HubTest.php b/tests/library/Class/WebService/Dilicom/HubTest.php index d95a58598f3a753816a4cfcdb77cee0df9e04f2d..852889e25c293d0454f0db0e760e3c7d104e8e52 100644 --- a/tests/library/Class/WebService/Dilicom/HubTest.php +++ b/tests/library/Class/WebService/Dilicom/HubTest.php @@ -93,6 +93,8 @@ class Class_Webservice_Dilicom_HubUpdateStatusSuccessfulTest extends Class_Webse public function setUp() { parent::setUp(); + $this->_wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Album_Item'); + $this->_http ->whenCalled('open_url') ->with('https://pnb-test.centprod.com/v2/pnb-numerique/json/getLoanStatus?glnContractor=123456789&orderLineId[0]=x321') @@ -114,6 +116,12 @@ class Class_Webservice_Dilicom_HubUpdateStatusSuccessfulTest extends Class_Webse public function loanQuantityRemainingShouldBe24OnSuccessfulUpdate() { $this->assertEquals(24, $this->loan_constraint->quantityOfLoansRemaining()); } + + + /** @test */ + public function itemSaveShouldHaveBeenCalled() { + $this->assertTrue($this->_wrapper->methodHasBeenCalled('save')); + } } diff --git a/tests/library/Class/WebService/Dilicom/ONIXParserTest.php b/tests/library/Class/WebService/Dilicom/ONIXParserTest.php index 22a50ce786cee18243d359706901b5185b9dd063..89cd3c50e209ba9c4176e29d702c26056a3fe91d 100644 --- a/tests/library/Class/WebService/Dilicom/ONIXParserTest.php +++ b/tests/library/Class/WebService/Dilicom/ONIXParserTest.php @@ -92,6 +92,13 @@ class DilicomONIXParserTest extends Storm_Test_ModelTestCase { } + /** @test */ + public function albumRightShouldBeOther() { + $album = $this->_book->import(); + $this->assertEquals(Class_Album::RIGHT_OTHER_KEY, $album->getDroits()); + } + + /** * @depends importAlbumTypeDocShouldBeDILICOM * @test diff --git a/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php b/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php index fae8ec30035cbd47a95c18a795fad18190fd536e..2c7a774bc9547a5620aefc18f14249dc9feed9d5 100644 --- a/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php +++ b/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php @@ -36,9 +36,6 @@ abstract class DilicomPNBOfferParserTestCase extends Storm_Test_ModelTestCase { Storm_Model_Loader::defaultToVolatile(); Class_Album_UsageConstraint::setTimeSource(new TimeSourceForTest('2014-05-02 14:14:14')); - - $this->fixture('Class_AdminVar', ['id' => 'DILICOM_PNB_MAX_LOAN_DURATION', - 'valeur' => '']); } } @@ -48,7 +45,7 @@ abstract class DilicomPNBOfferParserTestCase extends Storm_Test_ModelTestCase { class DilicomPNBOfferParserTest extends DilicomPNBOfferParserTestCase { public function setUp() { parent::setUp(); - + Class_Album_UsageConstraints::setTimeSource(new TimeSourceForTest('2015-11-24 09:00:00')); $this->_books = Class_WebService_BibNumerique_Dilicom_PNBOffersFile::booksFromXML($this->_xml); } @@ -139,6 +136,17 @@ class DilicomPNBOfferParserTest extends DilicomPNBOfferParserTestCase { $album->getUsageConstraints()->getLoanOrderLineId()); } + + /** + * @depends firstAlbumShouldBePlusJamaisSansElle + * @test + */ + public function firstAlbumLoanOrderDateShouldBe2015_02_20($album) { + $this->assertEquals('2015-02-20T15:40:01.866+01:00', + $album->getUsageConstraints()->getLoanOrderDate()); + } + + /** * @depends firstAlbumShouldBePlusJamaisSansElle * @test @@ -161,12 +169,12 @@ class DilicomPNBOfferParserTest extends DilicomPNBOfferParserTestCase { * @depends firstAlbumShouldBePlusJamaisSansElle * @test */ - public function firstAlbumAvailabilityEndDateBeAsExpected($album) { - $this->assertEquals('2019-05-01T14:14:14+0200', $album->getUsageConstraints()->getAvailabilityEndDate()); + public function firstAlbumAvailabilityEndDateBeShouldBe2020_19_02($album) { + $this->assertEquals('2020-02-19T15:40:01+0100', $album->getUsageConstraints()->getAvailabilityEndDate()); } - /** + /** * @depends firstAlbumShouldBePlusJamaisSansElle * @test */ @@ -176,6 +184,16 @@ class DilicomPNBOfferParserTest extends DilicomPNBOfferParserTestCase { } + /** + * @depends firstAlbumShouldBePlusJamaisSansElle + * @test + */ + public function albumLicenseShouldBeAvailableFor1548Days($album) { + $this->assertEquals(1548, + $album->getUsageConstraints()->getAvailabilityRemainingDaysBeforeEndDate()); + } + + /** @test */ public function secondAlbumShouldBeJournalDunDegonfle() { $album = $this->_books[1]->import(); @@ -269,5 +287,15 @@ class DilicomPNBOfferParserWithLoanDurationVariableTest extends DilicomPNBOfferP $album = $this->_books[0]->import(); $this->assertEquals(21, $album->getUsageConstraints()->getLoanDuration()); } + + + /** + * @test + */ + public function firstAlbumAvailabilityEndDateBeShouldBe2020_02_19() { + $album = $this->_books[0]->import(); + $this->assertEquals('2020-02-19T15:40:01+0100', $album->getUsageConstraints()->getAvailabilityEndDate()); + } + } ?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php b/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php index 5a5a2eb0b17b9abbdfaddef7a3973254be3288d5..d7a7234ad4843ce87872030fe47a732ff729e700 100644 --- a/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php +++ b/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php @@ -85,7 +85,7 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdminVariableAsAdminTest extends ZendA /** @test */ public function menuImportDilicomShouldNotBeVisibleWhenOptionDILICOM_PNB_isDisabled() { $this->assertNotXPath($this->helper->menuGaucheAdmin(), - '//a[contains(@href, "/admin/album/import-dilicom")]'); + '//a[contains(@href, "/admin/album/dilicom")]'); } @@ -93,7 +93,7 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdminVariableAsAdminTest extends ZendA public function menuImportDilicomShouldBeVisibleWhenOptionDILICOM_PNB_isEnabled() { RessourcesNumeriquesFixtures::activateDilicom(); $this->assertXPath($this->helper->menuGaucheAdmin(), - '//a[contains(@href, "/admin/album/import-dilicom")]'); + '//a[contains(@href, "/admin/album/dilicom")]'); } diff --git a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php index 204e1fe3bac567effbe1b6adce8779e21fd0dbf7..73e177480e4524f42329cb3ff3db918113e5a02d 100644 --- a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php +++ b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php @@ -379,24 +379,4 @@ class ZendAfi_View_Helper_RenderAlbumDilicomPNBTest extends ZendAfi_View_Helper_ '//a[contains(@href, "/bib-numerique/loan-book-ajax/id/3")]', 'Emprunter le livre au format EPUB'); } - - - /** @test */ - public function albumShouldHaveBeenUpdateThroughHubGetLoanStatus() { - $this->assertContains('getLoanStatus', $this->_http->getFirstAttributeForLastCallOn('open_url')); - } - - - /** @test */ - public function currentLoansCountShouldBe45OutOf50() { - $this->assertXPathContentContains($this->_html, '//p', 'Nombre d\'emprunts en cours: 45 / 50'); - } - - - /** @test */ - public function withMaxLoanLimitOf47CurrentLoansCountShouldBe45OutOf47() { - Class_AdminVar::set('DILICOM_PNB_LOAN_COUNT_LIMIT', 47); - $this->_html = $this->_helper->renderAlbum($this->book); - $this->assertXPathContentContains($this->_html, '//p', 'Nombre d\'emprunts en cours: 45 / 47'); - } }