diff --git a/VERSIONS_HOTLINE/30704 b/VERSIONS_HOTLINE/30704 new file mode 100644 index 0000000000000000000000000000000000000000..4d66abde9adfd39347602efaa8544985d8d16cda --- /dev/null +++ b/VERSIONS_HOTLINE/30704 @@ -0,0 +1 @@ + - ticket #30704 : Supprimer la vignette d'un album ne supprime pas l'information de vignette de la pseudo-notice \ No newline at end of file diff --git a/library/Class/Album.php b/library/Class/Album.php index 3e11201b81787fb0fe9fc0d20fd767e2d8d4047b..3fe056b5c31f4e689372f16ee96dcbe7b46e8dc8 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -532,11 +532,6 @@ class Class_Album extends Storm_Model_Abstract { } - public function getDomaines() { - return []; - } - - /** * @param Zend_Controller_Request_Http $request * @return array @@ -635,10 +630,12 @@ class Class_Album extends Storm_Model_Abstract { public function deleteVignette() { - if ('' != $this->getFichier()) { - $this->getFileSystem()->unlink($this->getVignettePath()); - $this->setFichier('')->save(); - } + if (!$this->getFichier()) + return; + + $this->getFileSystem()->unlink($this->getVignettePath()); + $this->setFichier('')->save(); + $this->index(); } @@ -727,7 +724,6 @@ class Class_Album extends Storm_Model_Abstract { } - public function getFile() { return $this->getFichier(); } diff --git a/library/Class/Article.php b/library/Class/Article.php index cfae7f250dfe8287604964ae3d20ba5e0911163f..8c1b5a8591bb0f09b9a9bf1c44019d72fa19b71c 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -452,7 +452,7 @@ class ArticleLoader extends Storm_Model_Loader { class Class_Article extends Storm_Model_Abstract { - use Trait_TreeViewableItem, Trait_HasManyDomaines, Trait_TimeSource, Trait_Indexable, Trait_CustomFields, Trait_StaticFileWriter; + use Trait_TreeViewableItem, Trait_Indexable, Trait_HasManyDomaines, Trait_TimeSource, Trait_CustomFields, Trait_StaticFileWriter; const END_TAG='{FIN}'; @@ -814,8 +814,6 @@ class Class_Article extends Storm_Model_Abstract { public function beforeSave() { if ($this->isNew() && !$this->getDateCreation()) $this->setDateCreation($this->getDateMaj()); - - $this->unindex(); } diff --git a/library/Class/Indexation/Model/WithManyDomains.php b/library/Class/Indexation/Model/WithManyDomains.php new file mode 100644 index 0000000000000000000000000000000000000000..3f8079f8eda1dbdb15e00b45e934985b34b305a4 --- /dev/null +++ b/library/Class/Indexation/Model/WithManyDomains.php @@ -0,0 +1,80 @@ +<?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 Class_Indexation_Model_WithManyDomains { + protected $_model; + + public function __construct($model) { + $this->_model = $model; + } + + public function index() { + if (!$alpha_key = $this->_model->getAlphaKey()) + return $this; + + $domains_ids = Class_Catalogue::getIds($this->_model->getDomaines()); + $existing = Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key]); + $existing_domains = array_filter(array_map(function ($item) { + return $item->getDomain(); + }, $existing)); + + $existing_ids = array_map(function ($item) { return $item->getId();}, $existing_domains); + + if ($to_delete = array_diff($existing_ids, $domains_ids)) + Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, + 'domain_id' => $to_delete]); + + $to_create = array_diff($domains_ids, $existing_ids); + + foreach($to_create as $domain_id) { + $notice_domain = Class_NoticeDomain::newInstance(['domain_id' => $domain_id, + 'record_alpha_key' => $alpha_key]); + $notice_domain->updateFacette(); + $notice_domain->save(); + } + + foreach(Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key]) as $notice_domain) + $notice_domain->updateFacette(); + + $this->_model + ->setDomaineIds($domains_ids) + ->save(); + + return $this; + } + + + public function unindex() { + if (!$alpha_key = $this->getAlphaKey()) + return $this; + + Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, + 'panier_id' => 0]); + + return $this; + } + + + public function getAlphaKey() { + return $this->_model->getAlphaKey(); + } +} \ No newline at end of file diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index 0defb0b4fb7ff03ce8f0a6952110f5c92b9fd511..aaced575a608bf6aa63ad4b22a02e3e0503e75bc 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -34,90 +34,70 @@ class Class_Indexation_PseudoNotice { public static function index($model) { - $instance = self::newWith($model); + $instance = (new Class_Indexation_PseudoNoticeFactory())->buildFrom($model); return ($instance->isValid()) ? $instance->save() : false; } public static function unindex($model) { - if($notice = $model->getNotice()) - $notice->delete(); + $instance = (new Class_Indexation_PseudoNoticeFactory())->buildFrom($model); + $instance->delete(); - return $model; + return $model; } - public static function newWith($model) { - $type_doc = $model->getTypeDocId(); - - // types simples - $mapping = [Class_TypeDoc::ARTICLE => 'Cms', - Class_TypeDoc::RSS => 'Rss', - Class_TypeDoc::SITE=> 'Sito']; - - if (array_key_exists($type_doc, $mapping)) { - $class_name = 'Class_Indexation_PseudoNotice_' . $mapping[$type_doc]; - return new $class_name($model); - } - - // bibnum - if (99 < $type_doc) - return new Class_Indexation_PseudoNotice_Album($model); - return new Class_Indexation_PseudoNotice_Null(); - } - - public function __construct($model) { $this->_model = $model; $this->_type_doc = $model->getTypeDocId(); $this->_datas = array_change_key_case($model->toArray(), CASE_LOWER); } + public function getId() { return $this->_notice->getId(); } + public function getUnimarc() { return $this->_notice->getUnimarc(); } + public function getCodeBarres() { return $this->_exemplaire->getCodeBarres(); } + public function getFacettes() { return $this->_notice->getFacettes(); } - public function save() { - $this->_prepare(); - if (!$notice = $this->_model->getNotice()) { - $notice = Class_Notice::newInstance(['type_doc' => $this->_type_doc]); - } + public function save() { + $this->_prepareDatas(); - if (!$notice->save()) + if (!$this->_ensureItem()) return false; - $this->_notice = $notice; - $exemplaire = $notice->hasExemplaires() - ? $notice->getExemplaires()[0] - : Class_Exemplaire::newInstance(['id_bib' => $this->_datas['id_bib'], - 'id_notice' => $this->_notice->getId(), - 'id_origine' => $this->_model->getId(), - 'activite' => $this->_('A consulter sur le portail')]); - - if (!$exemplaire->save()) - return false; - $this->_exemplaire = $exemplaire; - $this->_model->updateAttributes([$this->_id_notice => $this->_notice->getId()]); - $this->_model->save(); + $this->_model + ->updateAttributes([$this->_id_notice => $this->_notice->getId()]) + ->save(); $this->_index(); return true; } - protected function _prepare() { + + public function delete() { + if ($notice = $this->_model->getNotice()) + $notice->delete(); + + return $this; + } + + + protected function _prepareDatas() { $intBib = Class_IntBib::findFirstBy(['order' => 'id_bib']); $this->_datas = array_merge( ['id_bib' => $intBib ? $intBib->getId() : 0, 'date_maj' => '', @@ -143,6 +123,38 @@ class Class_Indexation_PseudoNotice { } + protected function _ensureItem() { + if (!$this->_ensureRecord()) + return false; + + if ($this->_notice->hasExemplaires()) { + $this->_exemplaire = $this->_notice->getExemplaires()[0]; + return true; + } + + $this->_exemplaire = Class_Exemplaire::newInstance(['id_bib' => $this->_datas['id_bib'], + 'id_notice' => $this->_notice->getId(), + 'id_origine' => $this->_model->getId(), + 'activite' => $this->_('A consulter sur le portail')]); + + if ($this->_exemplaire->save()) { + $this->_notice->addExemplaire($this->_exemplaire); + return true; + } + + return false; + } + + + protected function _ensureRecord() { + if ($this->_notice = $this->_model->getNotice()) + return true; + + $this->_notice = Class_Notice::newInstance(['type_doc' => $this->_type_doc]); + return $this->_notice->save(); + } + + public function getAuthorsNames() { $names = []; foreach($authors = $this->extractAuthors() as $author) @@ -191,16 +203,9 @@ class Class_Indexation_PseudoNotice { if ($this->dataExist('editeur' , $this->_datas)) $this->_notice->setEditeur($indexation->getfullText($this->_datas["editeur"])); - if ($this->dataExist('fichier', $this->_datas)) { - $url_vignette = $this->_model->getThumbnailUrl(); - $this->_notice->setUrlVignette($url_vignette); - $this->_notice->setUrlImage($url_vignette); - } - if ($this->dataExist('url_image', $this->_datas)) $this->_notice->setUrlImage($this->_datas["url_image"]); - $this->_notice->save(); // exemplaire @@ -215,10 +220,12 @@ class Class_Indexation_PseudoNotice { if ($this->dataExist('cote', $this->_datas)) $cote = $this->_datas['cote']; - $this->_exemplaire - ->setGenre($genre) - ->setCote($cote) - ->save(); + $this->_exemplaire->setGenre($genre) + ->setCote($cote) + ->save(); + + $this->_model->setNotice($this->_notice) + ->save(); } @@ -381,8 +388,8 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ protected $_album; - protected function _prepare() { - parent::_prepare(); + protected function _prepareDatas() { + parent::_prepareDatas(); if ($this->_datas['id_origine']) $this->_datas['url'] = $this->getUrlSite() . 'bib-numerique/notice/ido/' @@ -399,6 +406,15 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ protected function _modelIdAcceptVisitor($visitor) {} + protected function _index() { + $url_vignette = $this->_model->getThumbnailUrl(); + $this->_notice->setUrlVignette($url_vignette); + $this->_notice->setUrlImage($url_vignette); + + parent::_index(); + } + + /** @return array */ public function extractAuthors() { $authors = array_merge(parent::extractAuthors(), @@ -480,46 +496,71 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ - class Class_Indexation_PseudoNotice_Cms extends Class_Indexation_PseudoNotice{ protected $_model_name = 'Class_Article'; protected $_id = 'id_article'; - protected $_label='m1'; + protected $_label = 'm1'; public function save() { parent::save(); - if($record = $this->_model->getNotice()) - (new Class_WebService_Vignette())->updateUrlsFromCacheServer($record); + if (!$record = $this->_model->getNotice()) + return; + + (new Class_WebService_Vignette())->updateUrlsFromCacheServer($record); + (new Class_Indexation_Model_WithManyDomains($this->_model))->index(); } - protected function _prepare() { - parent::_prepare(); - $this->_datas['description'] = strip_tags($this->_datas['contenu']); + + public function delete() { + (new Class_Indexation_Model_WithManyDomains($this->_model))->unindex(); + parent::delete(); } -} -class Class_Indexation_PseudoNotice_Rss extends Class_Indexation_PseudoNotice{ - protected $_model_name = 'Class_Rss'; - protected $_id = 'id_rss'; - protected $_label='m2'; + protected function _prepareDatas() { + parent::_prepareDatas(); + $this->_datas['description'] = strip_tags($this->_datas['contenu']); + } } + class Class_Indexation_PseudoNotice_Sito extends Class_Indexation_PseudoNotice{ protected $_model_name = 'Class_Sitotheque'; protected $_id = 'id_sito'; - protected $_label='m3'; + protected $_label = 'm3'; + + + public function save() { + parent::save(); + if (!$record = $this->_model->getNotice()) + return; + + (new Class_Indexation_Model_WithManyDomains($this->_model))->index(); + } + + + public function delete() { + (new Class_Indexation_Model_WithManyDomains($this->_model))->unindex(); + parent::delete(); + } } + +class Class_Indexation_PseudoNotice_Rss extends Class_Indexation_PseudoNotice{ + protected $_model_name = 'Class_Rss'; + protected $_id = 'id_rss'; + protected $_label = 'm2'; +} + + + class Class_Indexation_PseudoNotice_Null extends Class_Indexation_PseudoNotice{ public function __construct() {} public function isValid() { return false; } -} - -?> +} \ No newline at end of file diff --git a/library/Class/Indexation/PseudoNoticeFactory.php b/library/Class/Indexation/PseudoNoticeFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..3c6f8f018225364a38894245ebf5949f9af7e425 --- /dev/null +++ b/library/Class/Indexation/PseudoNoticeFactory.php @@ -0,0 +1,42 @@ +<?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 Class_Indexation_PseudoNoticeFactory { + public function buildFrom($model) { + $type_doc = $model->getTypeDocId(); + + // types simples + $mapping = [Class_TypeDoc::ARTICLE => 'Cms', + Class_TypeDoc::RSS => 'Rss', + Class_TypeDoc::SITE=> 'Sito']; + + if (array_key_exists($type_doc, $mapping)) { + $class_name = 'Class_Indexation_PseudoNotice_' . $mapping[$type_doc]; + return new $class_name($model); + } + + // bibnum + return (99 < $type_doc) + ? new Class_Indexation_PseudoNotice_Album($model) + : new Class_Indexation_PseudoNotice_Null(); + } +} \ No newline at end of file diff --git a/library/Class/PanierNotice.php b/library/Class/PanierNotice.php index 8171d695f3ab6b9362d134919d630ef6cdbffbcf..eb3547c16fe202f4b8d8696f47a41813f48a45cf 100644 --- a/library/Class/PanierNotice.php +++ b/library/Class/PanierNotice.php @@ -427,7 +427,6 @@ class Class_PanierNotice extends Storm_Model_Abstract { } - public function getPaniersAdminsNotInCatalogueJson() { $users_paniers = []; $paniers = Class_PanierNotice::getLoader()->findAllWithNoCatalogueBelongsToAdmin(); diff --git a/library/Class/Rss.php b/library/Class/Rss.php index 87c3275bf365087e2fe82908785d21d23c3d1ff7..86416719d5845c76cb0015714a8d167199c7d728 100644 --- a/library/Class/Rss.php +++ b/library/Class/Rss.php @@ -448,11 +448,6 @@ class Class_Rss extends Storm_Model_Abstract { } - public function getDomaines() { - return []; - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ARBRE pour lister les cat+ subcat sur lindex admin //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -549,6 +544,4 @@ class Class_Rss extends Storm_Model_Abstract { $visitor->visitTitre($this->getTitre()) ->visitTypeDocId(Class_TypeDoc::RSS); } -} - -?> +} \ No newline at end of file diff --git a/library/Class/Sitotheque.php b/library/Class/Sitotheque.php index ee1c1e0aeac089991a691660e2a748034f726dde..3579f40216442d6efd1709cff105b4e38f70fcef 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -119,8 +119,7 @@ class SitothequeLoader extends Storm_Model_Loader { class Class_Sitotheque extends Storm_Model_Abstract { - use Trait_Translator, Trait_TreeViewableItem, Trait_HasManyDomaines, Trait_Indexable, Trait_CustomFields, - Trait_TimeSource; + use Trait_Translator, Trait_TreeViewableItem, Trait_HasManyDomaines, Trait_Indexable, Trait_CustomFields, Trait_TimeSource; protected $_loader_class = 'SitothequeLoader'; @@ -147,9 +146,9 @@ class Class_Sitotheque extends Storm_Model_Abstract { 'referenced_in' => 'id_notice'])); } + public function beforeSave() { $this->setDateMaj($this->getCurrentDateTime()); - $this->unindex(); } diff --git a/library/Trait/Indexable.php b/library/Trait/Indexable.php index 79898db10e4bb8bfb31d3ad6a2cbcfde9c870e9c..587fbc2169b1dd0f9d5c051aed41c9df9d459262 100644 --- a/library/Trait/Indexable.php +++ b/library/Trait/Indexable.php @@ -21,76 +21,28 @@ trait Trait_Indexable { - public function index() { - if (!$this->hasToBeIndexed()) { - Class_Indexation_PseudoNotice::unindex($this); - return $this; - } - Class_Indexation_PseudoNotice::index($this); - return $this->indexIntoDomain(); - } - - - protected function indexIntoDomain() { - if(!$alpha_key = $this->getAlphaKey()) { - return $this; - } - - $domains_ids = Class_Catalogue::getIds($this->getDomaines()); - - $existing = Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key]); - - $existing_domains = array_filter(array_map(function ($item) { - return $item->getDomain(); - }, $existing)); - - $existing_ids = array_map(function ($item) { return $item->getId();}, $existing_domains); - - if ($to_delete = array_diff($existing_ids, $domains_ids)) - Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, - 'domain_id' => $to_delete]); - - $to_create = array_diff($domains_ids, $existing_ids); - - foreach($to_create as $domain_id) { - $notice_domain = Class_NoticeDomain::newInstance(['domain_id' => $domain_id, - 'record_alpha_key' => $alpha_key]); - $notice_domain->updateFacette(); - $notice_domain->save(); - } - - foreach(Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key]) as $notice_domain) - $notice_domain->updateFacette(); - - $this->setDomaineIds($domains_ids)->save(); - - return $this; - } - public function hasToBeIndexed() { return true; } - public function unindex() { - $alpha_key = $this->getAlphaKey(); + public function index() { + $this->hasToBeIndexed() + ? Class_Indexation_PseudoNotice::index($this) + : Class_Indexation_PseudoNotice::unindex($this); - $domains_ids = Class_Catalogue::getIds($this->getDomaines()); - if (empty($domains_ids)) { - Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, - 'panier_id' => 0]); - } + return $this; + } - $domains_in_db_ids = Class_Catalogue::getIds(Class_NoticeDomain::getDomainsForRecordAlphaKey($alpha_key)); - if ($to_delete = array_diff($domains_in_db_ids, $domains_ids)) - Class_NoticeDomain::deleteBy(['domain_id' => $to_delete]); + public function unindex() { + Class_Indexation_PseudoNotice::unindex($this); + return $this; } public function getAlphaKey() { return (new Class_Notice_ClefAlpha($this))->keyString(); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php index 6e83ade7dc51a1c1fdc47acbf9f1e5dbd67f0631..4355036ae833a65aaf73a5b92d4ad39729e8099c 100644 --- a/library/ZendAfi/Form/Album.php +++ b/library/ZendAfi/Form/Album.php @@ -256,7 +256,7 @@ class ZendAfi_Form_Album extends ZendAfi_Form { 'escape' => false, 'basePath' => $album->getBasePath(), 'baseUrl' => $album->getBaseUrl(), - 'thumbnailUrl' => $album->getThumbnailUrl(), + 'thumbnailUrl' => $album->getBaseUrl(), 'actionUrl' => $this->getView()->url(['action' => 'album-delete-vignette'])]); $vignette_element diff --git a/library/ZendAfi/Form/Album/Ressource.php b/library/ZendAfi/Form/Album/Ressource.php index e3492794629ce8d8395f8bd2cee280bd0d19c3e3..e488cb52945ff99fdae7de9e279cbf56977a912d 100644 --- a/library/ZendAfi/Form/Album/Ressource.php +++ b/library/ZendAfi/Form/Album/Ressource.php @@ -134,7 +134,7 @@ class ZendAfi_Form_Album_Ressource extends ZendAfi_Form { $element ->setBasePath($model->getOriginalsPath()) ->setBaseUrl($model->getThumbnailsUrl()) - ->setThumbnailUrl($model->getThumbnailUrl()); + ->setThumbnailUrl($model->getThumbnailsUrl()); } return $this->addElement($element); } diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index 4562794294abdd58e784e8ea899ea0abc32af172..2ce15ecdb2b4369201afe56e2457f7dac69eeceb 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -3260,3 +3260,54 @@ class Admin_AlbumControllerWebsiteWithPosterResourceDeletePosterTest ['./userfiles/album/17/big/media/framasoft.org.png'])); } } + + + +class Admin_AbstractControllerAlbumDeleteVignetteTest extends Admin_AlbumControllerTestCase { + protected $_file_system, $_album; + + public function setUp() { + parent::setUp(); + + $this->_album = $this->fixture('Class_Album', + ['id' => 347, + 'titre' => 'Godot Game Engine', + 'fichier' => 'godot.png', + 'status' => Class_Album::STATUS_VALIDATED, + 'visible' => 1, + ]); + + $this->_album->index(); + + $this->_file_system = $this->mock() + ->whenCalled('unlink')->answers(true); + Class_Album::setFileSystem($this->_file_system); + + $this->dispatch('/admin/album/album-delete-vignette/id/347', true); + } + + + public function tearDown() { + Class_Album::setFileSystem(null); + parent::tearDown(); + } + + + /** @test */ + public function godotShouldNotHaveThumbnailAnymore() { + $this->assertEquals('', $this->_album->getFichier()); + } + + + /** @test */ + public function thumbnailFileShouldHaveBeenDelete() { + $this->assertTrue($this->_file_system->methodHasBeenCalledWithParams('unlink', + ['./userfiles/album/347/godot.png'])); + } + + + /** @test */ + public function godotRecordShouldNotHaveThumbnailAnymore() { + $this->assertEquals('', $this->_album->getNotice()->getUrlVignette()); + } +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index e65d3e03c4712cd5429e23caec3887d966d10a8d..743e7149b1827c2b5f8bfb7c364e9f09648c719a 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -879,7 +879,11 @@ class CmsControllerArticleConcertEditArticleWithQuotesActionTest extends CmsCont class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPermissionTestCase { - protected $_tomorrow, $_storm_default_to_volatile = true; + protected + $_tomorrow, + $_storm_default_to_volatile = true, + $_record, $_article; + public function setUp() { parent::setUp(); @@ -943,14 +947,12 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer 'contenu' => ' ', 'date_creation' => '2010-12-25']); - $this->fixture('Class_NoticeDomain', ['id' => 1, 'domain_id' => 10, 'panier_id' => 0, 'record_alpha_key' => 'ERIKTRUFFAZLADYLANDQUARTETENCONCERT-4-TOM----8']); - $post_datas= ['titre' => 'Erik Truffaz - Ladyland quartet en concert', 'auteur' => $this->fixture('Class_Users', ['id' => 1, @@ -968,7 +970,10 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer 'domaine_ids' => ['10'], 'id_items' => ['1']]; - $this->postDispatch('/admin/cms/edit/id/4',$post_datas); + $this->postDispatch('/admin/cms/edit/id/4', $post_datas); + + $this->_article = Class_Article::find(4); + $this->_record = $this->_article->getNotice(); } @@ -981,32 +986,34 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer /** @test */ public function erikTruffazShouldBeIndexed() { - $this->assertNotNull(Class_Notice::findFirstBy(['alpha_titre' =>'ERIK TRUFFAZ LADYLAND QUARTET EN CONCERT'])); + $this->assertNotNull($this->_record); } /** @test */ public function clefAlphaShouldBeAsExpected() { $this->assertEquals('ERIKTRUFFAZLADYLANDQUARTETENCONCERT-4-TOM----8', - Class_Article::find(4)->getAlphaKey()); + $this->_article->getAlphaKey()); } /** @test */ public function erikTruffazShouldBeLinkedToExpectedDomain() { - $this->assertEquals(10, Class_NoticeDomain::findFirstBy(['record_alpha_key' => 'ERIKTRUFFAZLADYLANDQUARTETENCONCERT-4-TOM----8'])->getDomainId()); + $this->assertEquals(10, + Class_NoticeDomain::findFirstBy(['record_alpha_key' => 'ERIKTRUFFAZLADYLANDQUARTETENCONCERT-4-TOM----8']) + ->getDomainId()); } /** @test */ public function erikTruffazShouldBeLinkedToExpectedDomainByFacet() { - $this->assertContains('Q10', Class_Notice::findFirstBy(['alpha_titre' =>'ERIK TRUFFAZ LADYLAND QUARTET EN CONCERT'])->getFacettes()); + $this->assertContains('Q10', $this->_record->getFacettes()); } /** @test */ public function articleShouldNotHaveIdItems() { - $this->assertTrue(Class_Article::find(4)->isAttributeEmpty('id_items')); + $this->assertTrue($this->_article->isAttributeEmpty('id_items')); } @@ -1014,31 +1021,31 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer /** @test */ function titreShouldBeUpdatedToErikTruffazLadyland() { $this->assertEquals('Erik Truffaz - Ladyland quartet en concert', - Class_Article::find(4)->getTitre()); + $this->_article->getTitre()); } /** @test */ function dateDebutShouldBe2011_03_01() { - $this->assertContains('2011-03-01', Class_Article::find(4)->getDebut()); + $this->assertContains('2011-03-01', $this->_article->getDebut()); } /** @test */ function dateFinShouldBe2011_03_26() { - $this->assertContains($this->_tomorrow->format('Y-m-d'), Class_Article::find(4)->getFin()); + $this->assertContains($this->_tomorrow->format('Y-m-d'), $this->_article->getFin()); } /** @test */ function eventDebutShouldBe2011_03_02_at_08_35() { - $this->assertContains('2011-03-02 08:35', Class_Article::find(4)->getEventsDebut()); + $this->assertContains('2011-03-02 08:35', $this->_article->getEventsDebut()); } /** @test */ function eventFinShouldBe2011_03_05_at_10_42() { - $this->assertContains('2011-03-05 10:42', Class_Article::find(4)->getEventsFin()); + $this->assertContains('2011-03-05 10:42', $this->_article->getEventsFin()); } @@ -1046,59 +1053,59 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer function dateMAJShouldBeToday() { $today = new Zend_Date(); $this->assertContains($today->toString('yyyy-MM-dd'), - Class_Article::find(4)->getDateMaj()); + $this->_article->getDateMaj()); } /** @test */ function dateCreationShouldBe2010_12_25() { $this->assertContains('2010-12-25', - Class_Article::find(4)->getDateCreation()); + $this->_article->getDateCreation()); } /** @test */ function contenuShouldHaveFixedImageURL() { $this->assertEquals('Ici: <img src="' . Class_Url::baseUrl() . '/images/bonlieu.jpg" />', - Class_Article::find(4)->getContenu()); + $this->_article->getContenu()); } /** @test */ function descriptionShouldHaveRelativeImageURL() { $this->assertEquals('Affiche: <img src="' . Class_Url::baseUrl() . '/images/concert.jpg" />', - Class_Article::find(4)->getDescription()); + $this->_article->getDescription()); } /** @test */ function derniereModificationShouldBeNow() { - $this->assertContains( date('Y-m-d'), - Class_Article::find(4)->getDateMaj()); + $this->assertContains(date('Y-m-d'), + $this->_article->getDateMaj()); } /** @test */ public function articleAuteurShouldBeTom() { - $this->assertEquals(Class_Article::find(4)->getNomCompletAuteur(), 'tom'); + $this->assertEquals($this->_article->getNomCompletAuteur(), 'tom'); } /** @test */ function categorieShouldBeEvenements() { - $this->assertEquals($this->cat_evenements, Class_Article::find(4)->getCategorie()); + $this->assertEquals($this->cat_evenements, $this->_article->getCategorie()); } /** @test */ public function lieuShouldBeBonlieu() { - $this->assertEquals($this->lieu_bonlieu, Class_Article::find(4)->getLieu()); + $this->assertEquals($this->lieu_bonlieu, $this->_article->getLieu()); } /** @test */ public function domainesShouldBeOnlyHistoire() { - $this->assertEquals(['10'], Class_Article::find(4)->getDomaineIdsAsArray()); + $this->assertEquals(['10'], $this->_article->getDomaineIdsAsArray()); } @@ -1110,7 +1117,8 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer /** @test */ public function articleRecordThumbnailShouldBeSet() { - $this->assertContains('temp/vignettes_titre/ERIKTRUFFAZLADYLANDQUARTETENCONCERT-4-TOM----8.jpg', Class_Article::find(4)->getNotice()->getUrlVignette()); + $this->assertContains('temp/vignettes_titre/ERIKTRUFFAZLADYLANDQUARTETENCONCERT-4-TOM----8.jpg', + $this->_record->getUrlVignette()); } } diff --git a/tests/application/modules/opac/controllers/PanierControllerTest.php b/tests/application/modules/opac/controllers/PanierControllerTest.php index 80d6e0f7f4ecdd007d44a1e6f958109e3a510772..1bcc5a710cbbeae399f37c0e55e4108d521096b5 100644 --- a/tests/application/modules/opac/controllers/PanierControllerTest.php +++ b/tests/application/modules/opac/controllers/PanierControllerTest.php @@ -1764,10 +1764,10 @@ class PanierControllerUnindexedByDeleteFullCartTest extends PanierControllerUnin $this->fixture('Class_Article', ['id' => 1, 'titre' => 'Article', - 'contenu' => 'Mon contenu']); - - Class_Article::find(1)->setDomaineIds(1)->save(); - Class_Article::find(1)->index(); + 'contenu' => 'Mon contenu', + 'domaine_ids' => '1', + 'status' => Class_Article::STATUS_VALIDATED]) + ->index(); $panier = Class_PanierNotice::find(2); $panier->addNotice(Class_Article::find(1)->getNotice())->save(); @@ -1780,7 +1780,7 @@ class PanierControllerUnindexedByDeleteFullCartTest extends PanierControllerUnin /** @test */ public function articleShouldStillBeInDomain() { $this->assertNotNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => Class_Article::find(1)->getAlphaKey(), - 'domain_id' => 1])); + 'domain_id' => 1])); } diff --git a/tests/library/Class/ArticleTest.php b/tests/library/Class/ArticleTest.php index dabfc3b3daab0d4b097ccc3d82672107f133f196..900c5d276e335d9c29586f4a3f63a044305fd8b6 100644 --- a/tests/library/Class/ArticleTest.php +++ b/tests/library/Class/ArticleTest.php @@ -1221,12 +1221,13 @@ class ArticleIndexAllTest extends ModelTestCase { -class ArticleUnindexTest extends Storm_Test_ModelTestCase { +class ArticleUnindexTest extends ModelTestCase { + protected + $_storm_default_to_volatile = true, + $_first, $_second; + public function setUp() { parent::setUp(); - Class_Exemplaire::beVolatile(); - Class_Notice::beVolatile(); - Class_NoticeDomain::beVolatile(); $this->fixture('Class_Catalogue', ['id' => 1, @@ -1236,24 +1237,28 @@ class ArticleUnindexTest extends Storm_Test_ModelTestCase { ['id' => 2, 'libelle' => 'My domain2']); - $this->fixture('Class_Article', - ['id' => 1, - 'titre' => 'My Cms First Step', - 'contenu' => 'My Cms First Step', - 'indexation' => 1, - 'domaine_ids' => '1;2']); + $this->_first = $this->fixture('Class_Article', + ['id' => 1, + 'titre' => 'My Cms First Step', + 'contenu' => 'My Cms First Step', + 'indexation' => 1, + 'domaine_ids' => '1;2']); - $this->fixture('Class_Article', - ['id' => 2, - 'titre' => 'My Cms second Step', - 'contenu' => 'My Cms second Step', - 'indexation' => 1, - 'domaine_ids' => '1;2']); + $this->_second = $this->fixture('Class_Article', + ['id' => 2, + 'titre' => 'My Cms second Step', + 'contenu' => 'My Cms second Step', + 'indexation' => 1, + 'domaine_ids' => '1;2']); + + $this->_first->index(); + $this->_second->index(); + + $this->_first->setDomaineIds(1)->save(); + $this->_first->index(); - Class_Article::find(1)->index(); - Class_Article::find(2)->index(); - Class_Article::find(1)->setDomaineIds(1)->save(); - Class_Article::find(2)->setDomaineIds('')->save(); + $this->_second->setDomaineIds('')->save(); + $this->_second->index(); } diff --git a/tests/library/Class/Indexation/PseudoNoticeTest.php b/tests/library/Class/Indexation/PseudoNoticeTest.php index 56232eb5f5cc4e1d2775272bb0c353c50731801a..f994407c2a147cea28a2ab6d1a69b0ed76551dda 100644 --- a/tests/library/Class/Indexation/PseudoNoticeTest.php +++ b/tests/library/Class/Indexation/PseudoNoticeTest.php @@ -19,12 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -abstract class Class_Indexation_PseudoNoticeTestCase extends Storm_Test_ModelTestCase { - public function setUp() { - parent::setUp(); - Class_Notice::beVolatile(); - Class_Exemplaire::beVolatile(); - } +abstract class Class_Indexation_PseudoNoticeTestCase extends ModelTestCase { + protected $_storm_default_to_volatile = true; } @@ -114,9 +110,7 @@ class Class_Indexation_PseudoNoticeSitothequeFromRawSQLTest extends Class_Indexa 'description' => 'Top notch site', 'tags' => 'VOD']); - /** as done in Cosmogramme */ - Class_Indexation_PseudoNotice::newWith($sito)->save(); - + $sito->index(); $this->_notice = Class_Notice::find(1); } @@ -146,8 +140,9 @@ class Class_Indexation_PseudoNoticeCmsTest extends Class_Indexation_PseudoNotice $article = $this->fixture('Class_Article', ['id' => 43, 'titre' => 'Festival Animation', - 'contenu' => 'à Annecy']); - Class_Indexation_PseudoNotice::newWith($article)->save(); + 'contenu' => 'à Annecy', + 'status']); + $article->beValidated()->index(); $this->_notice = Class_Notice::find(1); } @@ -179,8 +174,7 @@ class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_Pseud 'description' => 'Top notch site', 'tags' => 'VOD']); - Class_Indexation_PseudoNotice::newWith($this->_sito)->save(); - + $this->_sito->index(); $this->_notice = $this->_sito->getNotice(); } @@ -212,10 +206,10 @@ class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_Pseud -class Class_Indexation_PseudoNoticeArticleTest extends Storm_Test_ModelTestCase { +class Class_Indexation_PseudoNoticeArticleTest extends Class_Indexation_PseudoNoticeTestCase { public function setUp() { parent::setUp(); - Class_Exemplaire::beVolatile(); + $this->fixture('Class_NoticeDomain', ['id' => 189, 'domain_id' => 17, @@ -225,8 +219,6 @@ class Class_Indexation_PseudoNoticeArticleTest extends Storm_Test_ModelTestCase ['id' => 17, 'libelle' => 'my cata']); - Class_Notice::beVolatile(); - $this->fixture('Class_Article', ['id' => 1, 'titre' => 'My Artcile', @@ -250,9 +242,12 @@ class Class_Indexation_PseudoNoticeArticleTest extends Storm_Test_ModelTestCase -class Class_Indexation_PseudoNoticeArticleUpdateTest extends Storm_Test_ModelTestCase { +class Class_Indexation_PseudoNoticeArticleUpdateTest extends Class_Indexation_PseudoNoticeTestCase { public function setUp() { parent::setUp(); + + $this->fixture('Class_Profil', ['id' => 1]); + $record = $this->fixture('Class_Notice', ['id' => 15, 'titres' => 'Should not be deleted']); @@ -296,18 +291,18 @@ class Class_Indexation_PseudoNoticeArticleUpdateTest extends Storm_Test_ModelTes -class Class_Indexation_PseudoNoticeRssUpdateTest extends Storm_Test_ModelTestCase { +class Class_Indexation_PseudoNoticeRssUpdateTest extends Class_Indexation_PseudoNoticeTestCase { public function setUp() { parent::setUp(); $record = $this->fixture('Class_Notice', - ['id' => 15, - 'titres' => 'Should not be deleted']); + ['id' => 15, + 'titres' => 'Should not be deleted']); $rss = $this->fixture('Class_Rss', - ['id' => 1, - 'titre' => 'Should update record with id 15', - 'contenu' => 'Index me should update my record', - 'notice' => $record]); + ['id' => 1, + 'titre' => 'Should update record with id 15', + 'contenu' => 'Index me should update my record', + 'notice' => $record]); $rss->index(); } @@ -341,41 +336,41 @@ class Class_Indexation_PseudoNoticeRssUpdateTest extends Storm_Test_ModelTestCas -class Class_Indexation_PseudoNoticeSitothequeUpdateTest extends Storm_Test_ModelTestCase { +class Class_Indexation_PseudoNoticeSitothequeUpdateTest extends Class_Indexation_PseudoNoticeTestCase { + protected $_sito; + public function setUp() { parent::setUp(); - Class_Notice::beVolatile(); - Class_Exemplaire::beVolatile(); - $sitotheque = $this->fixture('Class_Sitotheque', - ['id' => 1, - 'url' => 'http://www.bokeh-library-portal.org', - 'titre' => 'Should update record with id 15', - 'contenu' => 'Index me should update my record']); - $sitotheque->index(); - $sitotheque->index(); + + $this->_sito = $this->fixture('Class_Sitotheque', + ['id' => 1, + 'url' => 'http://www.bokeh-library-portal.org', + 'titre' => 'Should update record with id 15', + 'contenu' => 'Index me should update my record']); + $this->_sito->index(); + $this->_sito->index(); } /** @test */ public function sitoGetNoticeShouldNotBeNull() { - $record = Class_Sitotheque::find(1)->getNotice(); - $this->assertEquals('SHOULD CHOUL UPDATE UPDAT RECORD REKOR WITH OUI 15', $record->getTitres()); + $this->assertEquals('SHOULD CHOUL UPDATE UPDAT RECORD REKOR WITH OUI 15', + $this->_sito->getNotice()->getTitres()); } /** @test */ public function sitoHasNoticeShouldBeTrue() { - $this->assertTrue(Class_Sitotheque::find(1)->hasNotice()); + $this->assertTrue($this->_sito->hasNotice()); } /** @test */ - public function sitoSetdNoticeShouldSetIt() { + public function sitoSetNoticeShouldSetItsId() { $record = $this->fixture('Class_Notice', - ['id' => 15, - 'titres' => 'Should not be deleted']); - Class_Sitotheque::find(1)->setNotice($record); - $this->assertEquals(15, Class_Sitotheque::find(1)->getIdNotice()); + ['id' => 15, 'titres' => 'Should not be deleted']); + $this->_sito->setNotice($record); + $this->assertEquals(15, $this->_sito->getIdNotice()); } @@ -387,27 +382,27 @@ class Class_Indexation_PseudoNoticeSitothequeUpdateTest extends Storm_Test_Model /** @test */ public function onlyOneRecordShouldBePresent() { - $this->assertCount(1, Class_Notice::findAll()); + $this->assertEquals(1, Class_Notice::count()); } /** @test */ public function onlyOneItemShouldBePresent() { - $this->assertCount(1, Class_Exemplaire::findAll()); + $this->assertEquals(1, Class_Exemplaire::count()); } /** @test */ public function deleteArticleShouldDeleteRecord() { - Class_Sitotheque::find(1)->delete(); - $this->assertNull(Class_Notice::find(15)); + $this->_sito->delete(); + $this->assertEquals(0, Class_Notice::count()); } } -class Class_Indexation_PseudoNoticeAlbumUpdateTest extends Storm_Test_ModelTestCase { +class Class_Indexation_PseudoNoticeAlbumUpdateTest extends Class_Indexation_PseudoNoticeTestCase { public function setUp() { parent::setUp(); $record = $this->fixture('Class_Notice', @@ -453,8 +448,7 @@ class Class_Indexation_PseudoNoticeAlbumUpdateTest extends Storm_Test_ModelTestC -class Class_Indexation_PseudoNoticeSacramentariumTest - extends Class_Indexation_PseudoNoticeTestCase { +class Class_Indexation_PseudoNoticeSacramentariumTest extends Class_Indexation_PseudoNoticeTestCase { public function setUp() { parent::setUp(); diff --git a/tests/library/Class/SitothequeTest.php b/tests/library/Class/SitothequeTest.php index 06d267be0648cc4aba8a5a601598c486c34f3845..e7b008a40ac121cd43e72a2aca044ede9bde530c 100644 --- a/tests/library/Class/SitothequeTest.php +++ b/tests/library/Class/SitothequeTest.php @@ -46,9 +46,7 @@ class SitothequeIndexAllTest extends ModelTestCase { public function setUp() { parent::setUp(); - Class_Notice::beVolatile(); - Class_NoticeDomain::beVolatile(); - Class_Exemplaire::beVolatile(); + $this->fixture('Class_Catalogue', ['id' => 1, 'libelle' => 'My domain']); @@ -120,12 +118,13 @@ class SitothequeIndexAllTest extends ModelTestCase { -class SitothequeUnindexTest extends Storm_Test_ModelTestCase { +class SitothequeUnindexTest extends ModelTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { parent::setUp(); - Class_Exemplaire::beVolatile(); - Class_Notice::beVolatile(); - Class_NoticeDomain::beVolatile(); + $this->fixture('Class_Catalogue', ['id' => 1, 'libelle' => 'My domain']); @@ -135,15 +134,16 @@ class SitothequeUnindexTest extends Storm_Test_ModelTestCase { 'libelle' => 'My domain news']); - $this->fixture('Class_Sitotheque', - ['id' => 1, - 'url' => 'http://web.afi-sa.net', - 'titre' => 'My website', - 'description' => 'My Cms First Step', - 'domaine_ids' => '1;2']); + $sito = $this->fixture('Class_Sitotheque', + ['id' => 1, + 'url' => 'http://web.afi-sa.net', + 'titre' => 'My website', + 'description' => 'My Cms First Step', + 'domaine_ids' => '1;2']); + $sito->index(); - Class_Sitotheque::find(1)->index(); - Class_Sitotheque::find(1)->setDomaineIds('1')->save(); + $sito->setDomaineIds('1')->save(); + $sito->index(); } /** @test */