diff --git a/application/modules/opac/controllers/DigitalResourceController.php b/application/modules/opac/controllers/DigitalResourceController.php new file mode 100644 index 0000000000000000000000000000000000000000..000e8ec6eec1d6347fb907f9f02342ad7dcd1e7f --- /dev/null +++ b/application/modules/opac/controllers/DigitalResourceController.php @@ -0,0 +1,35 @@ +<?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 DigitalResourceController extends ZendAfi_Controller_Action { + public function typedocIconAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(); + + $response = $this->getResponse(); + $response->clearAllHeaders(); + $response->setHeader('Content-Type', 'image/png'); + + if (is_readable($path = (new Class_DigitalResource())->getPluginDocTypeIcon($this->_getParam('id')))) { + $response->setBody(file_get_contents($path)); + } + } +} diff --git a/library/Class/Album.php b/library/Class/Album.php index 0af50ac1d16e162f11c0cfc0187d0f5c20be8f5c..b47af1709c9aa7efc61b8851c8eb7208f1a18d08 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -1131,7 +1131,7 @@ class Class_Album extends Storm_Model_Abstract { self::ANNEE_MIN, $next_year)); - $this->check(0 < (int)$this->getTypeDocId(), 'L\'album doit avoir un type de document'); + $this->check($this->hasTypeDocId(), 'L\'album doit avoir un type de document'); } diff --git a/library/Class/Album/Renderer.php b/library/Class/Album/Renderer.php index f3e8c18a9d14cbbcd92cd0f1fc4ee3be347320e0..b2f321da2a15ad1ff66f273f4aa5f9d9def38a74 100644 --- a/library/Class/Album/Renderer.php +++ b/library/Class/Album/Renderer.php @@ -29,6 +29,9 @@ class Class_Album_Renderer { public function renderOn($view) { + if ($html = (new Class_DigitalResource())->renderAlbumOn($this->_album, $view)) + return $html; + $mapping = ['tagBooklet' => function($album) { return $album->isLivreNumerique(); }, 'tagLivreNumerique' => function($album) { return $album->isNumilog(); }, 'tagCyberlibrisBook' => function($album) { return $album->isCyberlibris(); }, @@ -48,7 +51,6 @@ class Class_Album_Renderer { 'tagOneDTouch' => function($album) { return $album->isOneDTouch(); }, 'tagWebSite' => function($album) { return $album->isWebSite(); }, 'album_CiteDeLaMusique' => function($album) { return $album->isCiteDeLaMusique(); }, - 'tagAssimil' => function($album) {return $album->isAssimil();}, 'tagAlbumMediaList' => function($album) { return true; }]; foreach($mapping as $helper => $closure) diff --git a/library/Class/Codification.php b/library/Class/Codification.php index 526446b228cfeaae0fab1c0bb0ccad0b68e33f16..9134ddb829768b6d56bf8e3f1f83bf5d8e5abb96 100644 --- a/library/Class/Codification.php +++ b/library/Class/Codification.php @@ -135,7 +135,7 @@ class Class_Codification { case Class_Bib::CODE_FACETTE: return ($bib = Class_Bib::find((int)$id)) ? $bib->getLibelle() : ''; case Class_CodifAnnexe::CODE_FACETTE: return ($annexe = Class_CodifAnnexe::findFirstBy(['code' => addslashes($id)]))? $annexe->getLibelle() : ''; case Class_CodifTags::CODE_FACETTE: return ($tag = Class_CodifTags::find((int)$id)) ? $tag->getLibelle() : ''; - case Class_TypeDoc::CODE_FACETTE: return ($type_doc = Class_TypeDoc::find((int)$id)) ? $type_doc->getLabel() : ''; + case Class_TypeDoc::CODE_FACETTE: return ($type_doc = Class_TypeDoc::find($id)) ? $type_doc->getLabel() : ''; } return ''; } diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 92e2e92073203326d4118dbb1960f7193f9757ec..07c363aa2c4815df78f21b3696e1f135dd2b7562 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -297,10 +297,15 @@ class Class_CriteresRecherche { public function getTypeDoc() { + $digital_resource = new Class_DigitalResource(); + $validator = function($type) use($digital_resource){ + return $digital_resource->isPluginDocType($type) || is_numeric($type); + }; + return implode(',', array_filter(explode(',', $this->getParam('type_doc', 0)), - 'is_numeric')); + $validator)); } diff --git a/library/Class/DigitalResource.php b/library/Class/DigitalResource.php index c700d55a916e51156265766d2a1d85f7ef06dd0d..fe654ddf3ea6cb051bb8062113e3553980c078e7 100644 --- a/library/Class/DigitalResource.php +++ b/library/Class/DigitalResource.php @@ -31,6 +31,65 @@ class Class_DigitalResource extends Class_Entity { } + public function hasRighToAccessPlugin($user, $plugin) { + if (!$this->isPluginDocType($plugin)) + return false; + + if ($this->isAbonne() && !$this->isAbonnementValid()) + return false; + + + } + + + public function renderAlbumOn($album, $view) { + if (!$this->isPluginDocType($type = $album->getTypeDocId())) + return ''; + + if (is_readable($this->getBaseDir() . '/' . $type . '/View/Helper/Album.php')) { + $class_name = $type . '_View_Helper_Album'; + $helper = (new $class_name())->setView($view); + + return $helper->album($album); + } + + return ''; + } + + + public function getDocTypes() { + $types = []; + $this->withPluginsDo( + function($name, $config) use (&$types){ + $types[$this->getDocType($name)] = $config->getDocTypeLabel(); + }); + return $types; + } + + + public function isPluginDocType($type) { + $found = false; + + $this->withPluginsDo( + function($name, $config) use ($type, &$found) { + if ($found) + return ; + + $found = $type == $this->getDocType($name); + }); + + return $found; + } + + + public function getPluginDocTypeIcon($type) { + if (!$this->isPluginDocType($type)) + return; + + return $this->getBaseDir() . '/' . $type . '/images/icon.png'; + } + + public function handlePluginModule($module, $view_renderer) { if (!$this->isPluginModule($module)) return false; @@ -171,7 +230,6 @@ class Class_DigitalResource_Wrapper { class Class_DigitalResource_ConfigProvider { - public function getConfig($digital_resource, $class_name, $plugin) { return new $class_name(new Class_DigitalResource_Wrapper($digital_resource, $plugin)); } diff --git a/library/Class/Indexation/PseudoNoticeFactory.php b/library/Class/Indexation/PseudoNoticeFactory.php index 3c6f8f018225364a38894245ebf5949f9af7e425..4959c456e055738f5fbd757f774426e03d5e4cb6 100644 --- a/library/Class/Indexation/PseudoNoticeFactory.php +++ b/library/Class/Indexation/PseudoNoticeFactory.php @@ -35,7 +35,8 @@ class Class_Indexation_PseudoNoticeFactory { } // bibnum - return (99 < $type_doc) + return ((new Class_DigitalResource())->isPluginDocType($type_doc) + || 99 < $type_doc) ? new Class_Indexation_PseudoNotice_Album($model) : new Class_Indexation_PseudoNotice_Null(); } diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 673228d300f06ceb068008b392d992b856f6d8cb..e634d6e93a35618445e735a3d1a7bf496f2f9f4e 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -82,8 +82,12 @@ class Class_MoteurRecherche { public function visitDigitalLib($flag) { - if ($flag) - $this->setCondition('type_doc >= ' . Class_TypeDoc::NUMERIC_START); + if (!$flag) + return; + + $types = array_keys((new Class_DigitalResource())->getDocTypes()); + $this->setCondition('(type_doc >= ' . Class_TypeDoc::NUMERIC_START + . ' OR type_doc in (\'' . implode('\',\'', $types). '\'))'); } @@ -192,7 +196,7 @@ class Class_MoteurRecherche { public function visitTypeDoc($type_doc) { - $this->setCondition(" type_doc in(" . $type_doc . ")"); + $this->setCondition(" type_doc in('" . $type_doc . "')"); } diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php index 8bfef82b786383557a4438e08b2da6717e5e9767..cf8c268a0068d65bb9be2ba1f3f5faeca72314a1 100644 --- a/library/Class/TypeDoc.php +++ b/library/Class/TypeDoc.php @@ -221,7 +221,6 @@ class Class_TypeDoc extends Storm_Model_Abstract { const JAMENDO = 115; const WEBSITE = 116; const SOUNDCLOUD = 117; - const ASSIMIL = 118; const CITEDELAMUSIQUE = 119; public static function getDefaultTypeDocs() { @@ -251,9 +250,8 @@ class Class_TypeDoc extends Storm_Model_Abstract { self::JAMENDO => 'Jamendo', self::WEBSITE => 'Site web', self::SOUNDCLOUD => 'SoundCloud', - self::ASSIMIL => 'ASSIMIL e-méthode', self::CITEDELAMUSIQUE => 'Cite De La Musique' - ]; + ] + (new Class_DigitalResource())->getDocTypes(); } @@ -299,7 +297,8 @@ class Class_TypeDoc extends Storm_Model_Abstract { if ($id >= self::LIVRE_NUM) $for_album[$id] = $label; } - return $for_album; + + return $for_album + (new Class_DigitalResource())->getDocTypes(); } @@ -311,8 +310,9 @@ class Class_TypeDoc extends Storm_Model_Abstract { } public function isRessourceNumerique() { - return ($this->getId() >= Class_TypeDoc::LIVRE_NUM) - && (!in_array($this->getId(),[static::ARTICLE, static::RSS, static::SITE])); + return (($this->getId() >= Class_TypeDoc::LIVRE_NUM) + && (!in_array($this->getId(),[static::ARTICLE, static::RSS, static::SITE]))) + || (new Class_DigitalResource())->isPluginDocType($this->getId()); } diff --git a/library/ZendAfi/View/Helper/IconeSupport.php b/library/ZendAfi/View/Helper/IconeSupport.php index 6a44d8a1faa6042576972b3cc63a5477b6db2946..13444168dea3df11beca679627e6227733580dad 100644 --- a/library/ZendAfi/View/Helper/IconeSupport.php +++ b/library/ZendAfi/View/Helper/IconeSupport.php @@ -20,30 +20,29 @@ */ class ZendAfi_View_Helper_IconeSupport extends ZendAfi_View_Helper_BaseHelper { - protected $_filename_by_support = array( - 1 => 'famille_livre_small.png', - 2 => 'famille_periodique_small.png', - 3 => 'son_s.png', - 4 => 'famille_video_small.png', - 5 => 'mul_s.png', - 6 => 'support_6.gif', - 7 => 'img_s.png', - 8 => 'per_s_dep.png', - 9 => 'support_9.gif', - 10 => 'support_10.gif', - Class_TypeDoc::LIVRE_NUM => 'livre_num.png', - Class_TypeDoc::DIAPORAMA => 'images.png', - Class_TypeDoc::EPUB => 'epub.png', - Class_TypeDoc::DILICOM => 'pnb.png', - Class_TypeDoc::OAI => 'oai.gif', - Class_TypeDoc::ARTEVOD => 'artevod.png', - Class_TypeDoc::VODECLIC => 'vodeclic.png', - Class_TypeDoc::JAMENDO => 'jamendo_s.png', - Class_TypeDoc::SOUNDCLOUD => 'soundcloud_s.png', - Class_TypeDoc::WEBSITE => 'support_10.gif', - Class_TypeDoc::ASSIMIL => 'assimil_s.png', - Class_TypeDoc::CITEDELAMUSIQUE => 'cite_musique.png' - ); + protected $_filename_by_support = [ + 1 => 'famille_livre_small.png', + 2 => 'famille_periodique_small.png', + 3 => 'son_s.png', + 4 => 'famille_video_small.png', + 5 => 'mul_s.png', + 6 => 'support_6.gif', + 7 => 'img_s.png', + 8 => 'per_s_dep.png', + 9 => 'support_9.gif', + 10 => 'support_10.gif', + Class_TypeDoc::LIVRE_NUM => 'livre_num.png', + Class_TypeDoc::DIAPORAMA => 'images.png', + Class_TypeDoc::EPUB => 'epub.png', + Class_TypeDoc::DILICOM => 'pnb.png', + Class_TypeDoc::OAI => 'oai.gif', + Class_TypeDoc::ARTEVOD => 'artevod.png', + Class_TypeDoc::VODECLIC => 'vodeclic.png', + Class_TypeDoc::JAMENDO => 'jamendo_s.png', + Class_TypeDoc::SOUNDCLOUD => 'soundcloud_s.png', + Class_TypeDoc::WEBSITE => 'support_10.gif', + Class_TypeDoc::CITEDELAMUSIQUE => 'cite_musique.png' + ]; public function iconeSupport($type_doc_id) { @@ -82,6 +81,12 @@ class ZendAfi_View_Helper_IconeSupport extends ZendAfi_View_Helper_BaseHelper { public function imageForSupport($type_doc_id) { + if ((new Class_DigitalResource())->isPluginDocType($type_doc_id)) + return $this->view->url(['module' => 'opac', + 'controller' => 'digital-resource', + 'action' => 'typedoc-icon', + 'id' => $type_doc_id], null, true); + //keep format support_xxx_.gif for backward compatibility foreach(['gif', 'png'] as $extension) { $filename = 'support_' . $type_doc_id . '.' . $extension; diff --git a/library/ZendAfi/View/Helper/TagRessourceNumerique.php b/library/ZendAfi/View/Helper/TagRessourceNumerique.php index 3cd890630e2bc71b99650cc1758a697c6cdabe6f..8d7e824bfc8a3634081394c6ee1d94f0e01f833a 100644 --- a/library/ZendAfi/View/Helper/TagRessourceNumerique.php +++ b/library/ZendAfi/View/Helper/TagRessourceNumerique.php @@ -19,15 +19,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -abstract class ZendAfi_View_Helper_TagRessourceNumerique extends Zend_View_Helper_HtmlElement { - use Trait_Translator; +abstract class ZendAfi_View_Helper_TagRessourceNumerique extends ZendAfi_View_Helper_BaseHelper { public function canAccessRessourceNumerique() { $current_user = Class_Users::getIdentity(); return ($current_user && $this->hasRightAccesRessourcesNumeriques($current_user)); } - abstract function hasRightAccesRessourcesNumeriques($user); + abstract protected function hasRightAccesRessourcesNumeriques($user); -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/digital_resources/Assimil/Batch.php b/library/digital_resources/Assimil/Batch.php index 6340afc26964fd0ad4a920bb4ef5a2ba4a9dd891..80f871cee63df64653dcb9c54890f73163a04cdd 100644 --- a/library/digital_resources/Assimil/Batch.php +++ b/library/digital_resources/Assimil/Batch.php @@ -21,19 +21,12 @@ class Assimil_Batch extends Class_Batch_RessourceNumerique{ - protected $_config; - - public function __construct($config) { - $this->_config = $config; - } - - protected function _getService() { return new Assimil_Service(); } public function isEnabled() { - return $this->_config->isEnabled(); + return Assimil_Config::getInstance()->isEnabled(); } } diff --git a/library/digital_resources/Assimil/Config.php b/library/digital_resources/Assimil/Config.php index 03a27f488a2c2332584dfa05f00d4f1503f44a71..34bbc48af7d3d973b3842f45a8d9ecc532d59721 100644 --- a/library/digital_resources/Assimil/Config.php +++ b/library/digital_resources/Assimil/Config.php @@ -1,19 +1,43 @@ <?php +/** + * Copyright (c) 2012-2016, 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 Assimil_Config extends Class_Entity { use Trait_Translator; + protected static $_instance; + + public static function getInstance() { + return static::$_instance = static::$_instance + ? static::$_instance + : (new Class_DigitalResource())->configFor(basename(__DIR__)); + } + + public function __construct($digital_resource) { $this ->updateAttributes(['Name' => 'ASSIMIL', - 'Batch' => new Assimil_Batch($this), + 'DocTypeLabel' => $this->_('ASSIMIL e-méthode'), + 'Batch' => new Assimil_Batch(), 'AdminVars' => ['ASSIMIL' => Class_AdminVar_Meta::newOnOff($this->_('Activer ou désactiver la ressource numérique Assimil'))->bePrivate()], 'DigitalResource' => $digital_resource]); - - $this->setZfRoutes([(new Class_Entity()) - ->setName('assimil') - ->setPath('assimil/*') - ->setDefaults([])]); } diff --git a/library/digital_resources/Assimil/Service.php b/library/digital_resources/Assimil/Service.php index f0b5f2527c07bfc67656891dfbbe404ff5facd22..e31e38496ff2c73d8354c9afce38e5e8d24308bd 100644 --- a/library/digital_resources/Assimil/Service.php +++ b/library/digital_resources/Assimil/Service.php @@ -33,18 +33,14 @@ class Assimil_Service extends Class_WebService_BibNumerique_Abstract { protected $_parser, $_assimil_albums; - public function __construct($config) { - $this->_config = $config; - } - - protected function getDocType() - return $this->_config->getDocType(); + protected function getDocType() { + return Assimil_Config::getInstance()->getDocType(); } public function isEnabled() { - + return Assimil_Config::getInstance()->isEnabled(); } @@ -55,7 +51,7 @@ class Assimil_Service extends Class_WebService_BibNumerique_Abstract { protected function _deleteNonHarvested() { $harvested_ids = $this->getHarvestedIds(); - (new Storm_Model_Collection(Class_Album::findAllBy(['type_doc_id' => $this->getDocType()]) + (new Storm_Model_Collection(Class_Album::findAllBy(['type_doc_id' => $this->getDocType()]))) ->reject( function($album) use($harvested_ids) { return in_array($album->getIdOrigine(), $harvested_ids); @@ -91,4 +87,3 @@ class Assimil_Service extends Class_WebService_BibNumerique_Abstract { return $this->_assimil_albums; } } -?> diff --git a/library/digital_resources/Assimil/Service/Album.php b/library/digital_resources/Assimil/Service/Album.php index a64a921d084fd6c0ba72111a96c94898edc6a108..eed7c9be8d54c243b46605e343a7be96bdceed9b 100644 --- a/library/digital_resources/Assimil/Service/Album.php +++ b/library/digital_resources/Assimil/Service/Album.php @@ -21,7 +21,6 @@ class Assimil_Service_Album extends Class_WebService_BibNumerique_RessourceNumerique { - public function fillAlbum($album) { $album->setTypeDocId($this->getTypeDoc()); $album->addEditor($this->getEditeur()); @@ -31,12 +30,13 @@ class Assimil_Service_Album extends Class_WebService_BibNumerique_RessourceNumer public function updateAlbum($album) { $album = parent::updateAlbum($album); $album->index(); + return $album; } protected function getTypeDoc() { - return Class_TypeDoc::ASSIMIL; + return Assimil_Config::getInstance()->getDocType(); } @@ -53,5 +53,4 @@ class Assimil_Service_Album extends Class_WebService_BibNumerique_RessourceNumer public function getRessourceCategorieLibelle() { return Assimil_Service::CATEGORY_LABEL; } -} -?> +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagAssimil.php b/library/digital_resources/Assimil/View/Helper/Album.php similarity index 65% rename from library/ZendAfi/View/Helper/TagAssimil.php rename to library/digital_resources/Assimil/View/Helper/Album.php index e60ded9aa2ee450986b304072efc5796c13836f3..edad5ed14d33120ddf1fb6f2b1220289eabaf61b 100644 --- a/library/ZendAfi/View/Helper/TagAssimil.php +++ b/library/digital_resources/Assimil/View/Helper/Album.php @@ -19,16 +19,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ZendAfi_View_Helper_TagAssimil extends ZendAfi_View_Helper_TagRessourceNumerique { +class Assimil_View_Helper_Album extends ZendAfi_View_Helper_TagRessourceNumerique { + protected $_album; + + public function album($album) { + $this->_album = $album; - public function tagAssimil($album) { if (!$this->canAccessRessourceNumerique()) - return $this->view->tag('p', - $this->view->tagAnchor($this->view->url(['module' => 'opac', - 'controller' => 'modules', - 'action' => 'assimil', - 'album' => $album->getId()], null, true), - $this->_('Vous devez être connecté sous un compte avec abonnement valide pour pouvoir accéder à la méthode'))); + return $this->_tag('p', + $this->view->tagAnchor($this->view->url(['module' => 'opac', + 'controller' => 'modules', + 'action' => 'assimil', + 'album' => $album->getId()], null, true), + $this->_('Vous devez être connecté sous un compte avec abonnement valide pour pouvoir accéder à la méthode'))); return $this->view->tagAnchor($album->getExternalUri(), $this->_('Accéder à "%s" dans un nouvel onglet', $album->getTitre()), @@ -36,9 +39,8 @@ class ZendAfi_View_Helper_TagAssimil extends ZendAfi_View_Helper_TagRessourceNum } - function hasRightAccesRessourcesNumeriques($user) { - return $user->hasRightAccessAssimil(); + protected function hasRightAccesRessourcesNumeriques($user) { + return (new Class_DigitalResource()) + ->hasRighToAccessPlugin($user, $this->_album->getTypeDocId()); } - -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/digital_resources/Assimil/controllers/IndexController.php b/library/digital_resources/Assimil/controllers/IndexController.php index d255d0d033294480420414e9dcc391c8db4a4734..1dd9827946f823acb52fc011f7bfa13d28e9ea60 100644 --- a/library/digital_resources/Assimil/controllers/IndexController.php +++ b/library/digital_resources/Assimil/controllers/IndexController.php @@ -23,6 +23,6 @@ class Assimil_Plugin_IndexController extends ZendAfi_Controller_Action { public function indexAction() { $this->view->titre = $this->_('Assimil Plugin'); - $this->view->records_count = Class_Album::countBy(['type_doc_id' => (new Class_DigitalResource())->configFor('Assimil')->getDocType()]); + $this->view->records_count = Class_Album::countBy(['type_doc_id' => Assimil_Config::getInstance()->getDocType()]); } } \ No newline at end of file diff --git a/public/admin/images/supports/assimil_s.png b/library/digital_resources/Assimil/images/icon.png similarity index 100% rename from public/admin/images/supports/assimil_s.png rename to library/digital_resources/Assimil/images/icon.png diff --git a/library/digital_resources/Assimil/tests/AssimilConfigTest.php b/library/digital_resources/Assimil/tests/AssimilConfigTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ead2e1ea4b7c901b257ec06625e21f0cbca15641 --- /dev/null +++ b/library/digital_resources/Assimil/tests/AssimilConfigTest.php @@ -0,0 +1,53 @@ +<?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 AssimilTest extends ModelTestCase { + + protected + $_storm_default_to_volatile = true, + $_config; + + public function setUp() { + parent::setUp(); + $this->_config = Assimil_Config::getInstance(); + } + + + /** @test */ + public function docTypeShouldBeAssimil() { + $this->assertEquals('Assimil', $this->_config->getDocType()); + } + + + /** @test */ + public function withAdminVarOffShouldBeDisabled() { + $this->fixture('Class_AdminVar', ['id' => 'Assimil_ASSIMIL', 'valeur' => '']); + $this->assertFalse($this->_config->isEnabled()); + } + + + /** @test */ + public function withAdminVarOnShouldBeEnabled() { + $this->fixture('Class_AdminVar', ['id' => 'Assimil_ASSIMIL', 'valeur' => '1']); + $this->assertTrue($this->_config->isEnabled()); + } +} \ No newline at end of file diff --git a/tests/library/Class/WebService/AssimilTest.php b/library/digital_resources/Assimil/tests/AssimilServiceTest.php similarity index 78% rename from tests/library/Class/WebService/AssimilTest.php rename to library/digital_resources/Assimil/tests/AssimilServiceTest.php index e94684a3ce1222c67ad528e3a96011ae77886769..2a898088b75f6751c287dd2a3dfe3b8ccc5bb844 100644 --- a/tests/library/Class/WebService/AssimilTest.php +++ b/library/digital_resources/Assimil/tests/AssimilServiceTest.php @@ -19,16 +19,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -abstract class AssimilTestCase extends ModelTestCase { - protected $_storm_default_to_volatile = true, +abstract class AssimilServiceTestCase extends ModelTestCase { + protected + $_storm_default_to_volatile = true, $_e_course; public function setUp() { parent::setUp(); + RessourcesNumeriquesFixtures::activateAssimil(); - $catalogue_xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/assimil.xml'); + $catalogue_xml = file_get_contents(__DIR__. '/assimil.xml'); $this->_http_client = $this->mock(); $this->_http_client @@ -39,8 +41,8 @@ abstract class AssimilTestCase extends ModelTestCase { ->whenCalled('open_url') ->answers('une-image'); - $this->_service = new Class_WebService_BibNumerique_Assimil(); - Class_WebService_BibNumerique_Assimil::setDefaultHttpClient($this->_http_client); + $this->_service = new Assimil_Service(); + Assimil_Service::setDefaultHttpClient($this->_http_client); $this->_service->harvest(); Class_Album::clearCache(); $this->_e_course = Class_Album::find(1); @@ -50,7 +52,7 @@ abstract class AssimilTestCase extends ModelTestCase { -class AssimilHarvestTest extends AssimilTestCase { +class AssimilServiceHarvestTest extends AssimilServiceTestCase { /** @test */ public function nameShouldAssimil() { @@ -102,7 +104,8 @@ class AssimilHarvestTest extends AssimilTestCase { /** @test */ public function albumUrlOrigine() { - $this->assertEquals('https://biblio.assimil.com/assimilweb/FrontControler?nomMethod=catalogue.consulter&idProduit=4054', $this->_e_course->getUrlOrigine()); + $this->assertEquals('https://biblio.assimil.com/assimilweb/FrontControler?nomMethod=catalogue.consulter&idProduit=4054', + $this->_e_course->getUrlOrigine()); } @@ -120,18 +123,25 @@ class AssimilHarvestTest extends AssimilTestCase { /** @test */ public function albumShouldContainsUrlRessource() { - $this->assertEquals('https://biblio.assimil.com/assimilweb/FrontControler?nomMethod=catalogue.consulter&idProduit=4054', $this->_e_course->getRessources()[0]->getUrl()); + $this->assertEquals('https://biblio.assimil.com/assimilweb/FrontControler?nomMethod=catalogue.consulter&idProduit=4054', + $this->_e_course->getRessources()[0]->getUrl()); + } + + + /** @test */ + public function albumsShouldBeIndexed() { + $this->assertCount(26, Class_Notice::findAll()); } } -class AssimilSecondHarvestTest extends AssimilTestCase { +class AssimilServiceSecondHarvestTest extends AssimilServiceTestCase { public function setUp() { parent::setUp(); - $catalogue_xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/assimil_with_24_ressources.xml'); + $catalogue_xml = file_get_contents(__DIR__ . '/assimil_with_24_ressources.xml'); $http_client = $this->mock(); $http_client @@ -142,8 +152,8 @@ class AssimilSecondHarvestTest extends AssimilTestCase { ->whenCalled('open_url') ->answers('une-image'); - $service = new Class_WebService_BibNumerique_Assimil(); - Class_WebService_BibNumerique_Assimil::setDefaultHttpClient($http_client); + $service = new Assimil_Service(); + Assimil_Service::setDefaultHttpClient($http_client); $service->harvest(); Class_Album::clearCache(); } diff --git a/library/digital_resources/Assimil/tests/AssimilTest.php b/library/digital_resources/Assimil/tests/AssimilTest.php index 9c868e00fafa7762c9f91804405ba06163ec8984..3d507da70de1f422a55761b9b46b0e1ae8c0b0d5 100644 --- a/library/digital_resources/Assimil/tests/AssimilTest.php +++ b/library/digital_resources/Assimil/tests/AssimilTest.php @@ -20,7 +20,7 @@ */ -class AssimilTest extends ModelTestCase { +class AssimilConfigTest extends ModelTestCase { protected $_storm_default_to_volatile = true, @@ -28,7 +28,7 @@ class AssimilTest extends ModelTestCase { public function setUp() { parent::setUp(); - $this->_config = (new Class_DigitalResource())->configFor('Assimil'); + $this->_config = Assimil_Config::getInstance(); } diff --git a/tests/fixtures/assimil.xml b/library/digital_resources/Assimil/tests/assimil.xml similarity index 100% rename from tests/fixtures/assimil.xml rename to library/digital_resources/Assimil/tests/assimil.xml diff --git a/tests/fixtures/assimil_with_24_ressources.xml b/library/digital_resources/Assimil/tests/assimil_with_24_ressources.xml similarity index 100% rename from tests/fixtures/assimil_with_24_ressources.xml rename to library/digital_resources/Assimil/tests/assimil_with_24_ressources.xml diff --git a/library/startup.php b/library/startup.php index 24b56a3201689f8df600a09ed2b31630a3f12b3d..b988753f210fc8aed84149babfc5c9cb8f224c5e 100644 --- a/library/startup.php +++ b/library/startup.php @@ -52,7 +52,7 @@ function setupOpac() { setupPagination(); setupRestful(); setupSearch(); - setupDigitalResources(); + setupDigitalResources($front_controller); return $front_controller; } @@ -359,6 +359,6 @@ function setupSearch() { } -function setupDigitalResources() { - (new Class_DigitalResource())->bootstrap(Zend_Controller_Front::getInstance()); +function setupDigitalResources($front_controller) { + (new Class_DigitalResource())->bootstrap($front_controller); } \ No newline at end of file diff --git a/library/Class/WebService/BibNumerique/Assimil/Album.php b/tests/application/modules/opac/controllers/DigitalResourceControllerTest.php similarity index 55% rename from library/Class/WebService/BibNumerique/Assimil/Album.php rename to tests/application/modules/opac/controllers/DigitalResourceControllerTest.php index ff2bc236a7b4d3105af27f7f56a5fa526684533e..20a36c7a292cea93e80817493899007ba757d0bb 100644 --- a/library/Class/WebService/BibNumerique/Assimil/Album.php +++ b/tests/application/modules/opac/controllers/DigitalResourceControllerTest.php @@ -20,38 +20,18 @@ */ -class Class_WebService_BibNumerique_Assimil_Album extends Class_WebService_BibNumerique_RessourceNumerique { - - public function fillAlbum($album) { - $album->setTypeDocId($this->getTypeDoc()); - $album->addEditor($this->getEditeur()); - } - - - public function updateAlbum($album) { - $album = parent::updateAlbum($album); - $album->index(); - return $album; - } - - - protected function getTypeDoc() { - return Class_TypeDoc::ASSIMIL; - } - - - public function getBaseUrl() { - return $this->getExternalUri(); - } +class DigitalResourceControllerTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { + parent::setUp(); - public function isAlreadyHarvested() { - return false; + $this->dispatch('/opac/digital-resource/typedoc-icon/id/Assimil', true); } - public function getRessourceCategorieLibelle() { - return Class_WebService_BibNumerique_Assimil::CATEGORY_LABEL; + /** @test */ + public function shouldReturnAnImage() { + $this->assertContains('toto', $this->_response->getBody()); } -} -?> +} \ No newline at end of file