diff --git a/VERSIONS_WIP/72435 b/VERSIONS_WIP/72435 new file mode 100644 index 0000000000000000000000000000000000000000..1fd7f9909824ce54ef5160e103df60143f769f21 --- /dev/null +++ b/VERSIONS_WIP/72435 @@ -0,0 +1 @@ + - ticket #72435 : Cosmogramme : Ajout de l'import de fichiers d'autorités (sans affichage pour l'instant) \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php index b1c7897270f206d2c22fd7d080581d34fd1d5af3..8f0b4313a41a869b0efb18d2b66174ccaaf0181a 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php @@ -677,7 +677,6 @@ class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileCon class Cosmo_DataProfileControllerAddActionTest extends Cosmo_DataProfileControllerTestCase { - public function setUp() { parent::setUp(); $this->dispatch('/cosmo/data-profile/add', true); @@ -688,12 +687,17 @@ class Cosmo_DataProfileControllerAddActionTest extends Cosmo_DataProfileControll public function formShouldBePresent() { $this->assertXPath('//form'); } + + + /** @test */ + public function authorityTypeShouldBeAvailable() { + $this->assertXPath('//form//select[@id="type_fichier"]//option[@value="' . Class_IntProfilDonnees::FT_AUTHORITY . '"]'); + } } class Cosmo_DataProfileControllerDeleteActionTest extends Cosmo_DataProfileControllerTestCase { - public function setUp() { parent::setUp(); $this->dispatch('/cosmo/data-profile/delete/id/56', true); diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/RunLogControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/RunLogControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..afee485c2a052ef56cc153bf5a7e506972251a88 --- /dev/null +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/RunLogControllerTest.php @@ -0,0 +1,117 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 RunLogControllerByDateTest extends CosmoControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_CosmoVar', + ['id' => 'type_fichier', + 'liste' => "0:notices\r\n1:abonnés\r\n2:prêts\r\n3:reservations\r\n4:paniers\r\n5:autorités"]); + + $this->fixture('Class_CosmoVar', + ['id' => 'import_type_operation', + 'liste' => "0:Import incrémentiel\r\n1:Suppression d'exemplaires\r\n2:Import total\r\n3:Suppression fichier d'entête Pergame"]); + + $this->fixture('Class_Cosmogramme_Integration', + ['id' => 10439, + 'traite' => '2018-11-06', + 'fichier' => 'integre1212.pan', + 'pointeur_reprise' => 0, + 'nb_erreurs' => 0, + 'nb_warnings' => 0, + 'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL, + 'bib' => $this->fixture('Class_IntBib', ['id' => 3, 'nom_court' => 'test']), + 'profil_donnees' => $this->fixture('Class_IntProfilDonnees', + ['id' => 678, + 'type_fichier' => Class_IntProfilDonnees::FT_AUTHORITY]) + ]); + + $filesystem = $this->mock() + ->whenCalled('file_exists')->answers(true) + ->whenCalled('filesize')->answers(2299270) + ; + Class_Cosmogramme_Integration::setFileSystem($filesystem); + + $this->dispatch('/cosmo/run-log/by-date/date/2018-11-06', true); + } + + + public function tearDown() { + Class_Cosmogramme_Integration::setFileSystem(null); + parent::tearDown(); + } + + + /** @test */ + public function titleShouldBeJournalDesIntegrations() { + $this->assertXPathContentContains('//h1', 'Journal des intégrations du mardi 6 novembre 2018'); + } + + + /** @test */ + public function linkToSyntheseShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/run-log/synthese/id/10439/date/2018-11-06")]'); + } + + + /** @test */ + public function dateShouldBePresent() { + $this->assertXPathContentContains('//td', 'mardi 6 novembre 2018'); + } + + + /** @test */ + public function libraryShouldBePresent() { + $this->assertXPathContentContains('//td', 'test'); + } + + + /** @test */ + public function fileTypeShouldBeAuthorities() { + $this->assertXPathContentContains('//td', 'autorités'); + } + + + /** @test */ + public function operationTypeShouldBeTotal() { + $this->assertXPathContentContains('//td', 'Import total'); + } + + + /** @test */ + public function fileShouldBeIntegre1212DotPan() { + $this->assertXPathContentContains('//td', 'integre1212.pan'); + } + + + /** @test */ + public function fileSizeShouldBe2245Ko() { + $this->assertXPathContentContains('//td', '2 245'); + } + + + /** @test */ + public function fileDownloadLinkShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/run-log/download/id/10439/date/2018-11-06")]'); + } +} diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index 3cb54cbaa47293c35058d73d621af2eb818a4962..b0423497b3aa92b176d0c1299fd0a4dd604d0541 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -171,6 +171,10 @@ if ($_REQUEST['reprise'] == 'oui') { if (!$should_skip_records) { + $log->log('<h4>Traitement des autorités</h4>'); + setVariable('traitement_phase', 'Intégration des autorités'); + startIntegrationPhase('authority'); + // ---------------------------------------------------------------- // Integration des notices (PHASE 0) // ---------------------------------------------------------------- diff --git a/cosmogramme/sql/patch/patch_358.php b/cosmogramme/sql/patch/patch_358.php new file mode 100644 index 0000000000000000000000000000000000000000..37db87cf35c3bdf2ad3dceb0a4e66e05943aa0e4 --- /dev/null +++ b/cosmogramme/sql/patch/patch_358.php @@ -0,0 +1,12 @@ +<?php +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); + +$try = function ($query) use($adapter) { + try { + $adapter->query($query); + } catch(Exception $e) {} +}; + +$try('ALTER TABLE notices add column type int not null default 1, add KEY type (type)'); +$try('ALTER TABLE exemplaires add column type int not null default 1, add KEY type (type)'); +$try("UPDATE `variables` SET liste='0:notices\r\n1:abonnés\r\n2:prêts\r\n3:reservations\r\n4:paniers\r\n5:autorités' WHERE clef='type_fichier'"); \ No newline at end of file diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 6d822fe0d1030d4f00d2b21fa2672ad6fa913ebb..4f295276b1f751c05fa33f779ed636da5d091371 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -340,7 +340,8 @@ class CatalogueLoader extends Storm_Model_Loader { $sql = 'select %s from notices' . $join . - Class_MoteurRecherche::getConditionsForRequest(implode(' and ', array_filter($conditions)), $this->noticesLinked($catalogue)); + (new Class_MoteurRecherche)->getConditionsForRequest(array_filter($conditions), + $this->noticesLinked($catalogue)); return ['req_liste' => sprintf($sql, $fields ? implode(',', $fields) : '*') . $order_by . $limite, @@ -441,8 +442,9 @@ class CatalogueLoader extends Storm_Model_Loader { $condition = (array_isset("only_img", $preferences) && $preferences["only_img"] == 1) - ? " and url_vignette > '' and url_vignette != '" . Class_WebService_Vignette::NO_DATA . "' " + ? " and url_vignette > '' and url_vignette != '" . Class_WebService_Vignette::NO_DATA . "'" : ''; + $condition .= ' and type=1 '; $join = (array_isset("avec_avis", $preferences) && $preferences["avec_avis"] == 1) ? ' INNER JOIN notices_avis ON notices.clef_oeuvre=notices_avis.clef_oeuvre ' diff --git a/library/Class/Cosmogramme/Integration/PhaseAuthority.php b/library/Class/Cosmogramme/Integration/PhaseAuthority.php new file mode 100644 index 0000000000000000000000000000000000000000..2a988f84f5d90bb584310b4eefa36dec5ea4ba15 --- /dev/null +++ b/library/Class/Cosmogramme/Integration/PhaseAuthority.php @@ -0,0 +1,109 @@ +<?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 + */ + +require_once('cosmogramme/php/classes/classe_notice_integration.php'); + +class Class_Cosmogramme_Integration_PhaseAuthority + extends Class_Cosmogramme_Integration_PhaseOnDataSource { + + const MY_ID = 0; + + protected function _init($phase) {} + + + /** one line of file has been read and should be processed here */ + protected function _processLine($line, $integration) { + $line->withDataDo( + function($data) use ($integration){ + $this->importRecord($data, $integration); + }); + } + + + public function importRecord($data, $integration) { + $result = (new Class_Cosmogramme_Integration_Record_Authority($integration))->import($data); + $this->_incrementCount($result->getStatus()); + + if ($result->isReject() && ($message = $result->getMessage())) + $this->_log->error($message); + } + + + /** in case of full import, implements what is needed to be done */ + protected function _clean($integration) { + $data_source = $integration->getDataSource(); + if (!$data_source->isHttp() + && !$this->getFileSystem()->filesize($data_source->getUri())) { + $this->_log->error($this->_('Le fichier d\'import total est vide : aucun exemplaire supprimé.')); + return; + } + + $id_int_bib = $integration->getIdBib(); + $this->_log->info($this->_('Préparation des données')); + + $nb = $this->_markItemsToBeDeleted($id_int_bib); + $this->_log->success($this->_('%d exemplaire(s) marqué(s) pour suppression', + $nb)); + } + + + protected function _markItemsToBeDeleted($id_int_bib) { + $total = 0; + + while ($items = Class_Exemplaire::findAllBy(['type' => Class_Notice::TYPE_AUTHORITY, + 'id_int_bib' => $id_int_bib, + 'to_delete' => false, + 'limit' => 1000])) { + array_map(function($item) { $item->setToDelete(true)->save(); }, + $items); + $total += count($items); + } + + return $total; + } + + + /** should return true if $line must not be processed */ + protected function _shouldIgnoreLine($line, $integration) {} + + + /** return true if given profil parameters are correct for this phase */ + protected function _validateProfil($profil) { + return $profil->isAuthorityRecords(); + } + + + /** hooked called after the file has been fully processed */ + protected function _afterFileProcessed($integration) { + $args = ['type' => Class_Notice::TYPE_AUTHORITY, + 'id_int_bib' => $integration->getIdBib(), + 'to_delete' => true]; + + $nb = Class_Exemplaire::countBy($args); + Class_Exemplaire::deleteBy($args); + $this->_log->success($this->_('%d exemplaire(s) supprimé(s)', $nb)); + } + + + protected function _headerOfHook($integration) { + return ''; + } +} diff --git a/library/Class/Cosmogramme/Integration/PhaseNotice.php b/library/Class/Cosmogramme/Integration/PhaseNotice.php index df330376e2705f14621f7383c40a77dbcb974724..967541dae04fbb74d6edb2c7ee141cd3b96a054d 100644 --- a/library/Class/Cosmogramme/Integration/PhaseNotice.php +++ b/library/Class/Cosmogramme/Integration/PhaseNotice.php @@ -81,7 +81,8 @@ class Class_Cosmogramme_Integration_PhaseNotice protected function _markItemsToBeDeleted($id_int_bib) { $total = 0; - while( $items = Class_Exemplaire::findAllBy(['id_int_bib' => $id_int_bib, + while( $items = Class_Exemplaire::findAllBy(['type' => Class_Notice::TYPE_BIBLIOGRAPHIC, + 'id_int_bib' => $id_int_bib, 'to_delete' => false, 'limit' => 1000])) { array_map(function($item) { $item->setToDelete(true)->save(); }, @@ -104,7 +105,8 @@ class Class_Cosmogramme_Integration_PhaseNotice /** hooked called after the file has been fully processed */ protected function _afterFileProcessed($integration) { - $args = ['id_int_bib' => $integration->getIdBib(), + $args = ['type' => Class_Notice::TYPE_BIBLIOGRAPHIC, + 'id_int_bib' => $integration->getIdBib(), 'to_delete' => true]; $nb = Class_Exemplaire::countBy($args); diff --git a/library/Class/Cosmogramme/Integration/Record/Authority.php b/library/Class/Cosmogramme/Integration/Record/Authority.php new file mode 100644 index 0000000000000000000000000000000000000000..1d596dd64dabc38288ca89114e374d323726ebdf --- /dev/null +++ b/library/Class/Cosmogramme/Integration/Record/Authority.php @@ -0,0 +1,228 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Cosmogramme_Integration_Record_Authority { + use Trait_TimeSource, Trait_Translator; + + protected + $_reader, + $_integration, + $_authority_type, + $_codif_provider; + + public function __construct($integration) { + $this->_integration = $integration; + $this->_reader = new Class_NoticeUnimarc_Writer(); + $this->_indexation = Class_Indexation::getInstance(); + $this->_authority_type = new Class_Cosmogramme_Integration_Record_AuthorityType(); + } + + + public function import($data) { + $this->_reader->setNotice($data, $this->_encoding()); + + if (!$id_origine = $this->_getId()) + return $this->_rejectWith($this->_('Autorité sans 001')); + + if ($this->_isRepeatedTitle()) + return $this->_rejectWith($this->_('Autorité avec vedette répétée (%s)', $id_origine)); + + if (!$title = $this->_getTitle()) + return $this->_rejectWith($this->_('Autorité sans vedette (%s)', $id_origine)); + + $record = ['unimarc' => $data, + 'type' => Class_Notice::TYPE_AUTHORITY, + 'type_doc' => $this->_getAuthorityType(), + 'titres' => $this->_indexation->getFulltext($this->_addRejectsTo($title)), + 'alpha_titre' => $this->_indexation->codeAlphaTitre($title), + 'annee' => $this->_getCreationYear(), + 'facettes' => implode(' ', $this->_getFacets())]; + + $this->_save($id_origine, $record); + $this->_saveCodifFor($record['type_doc'], $title); + + return Class_Cosmogramme_Integration_Record_AuthorityResult::newInsert(); + } + + + protected function _rejectWith($message) { + return Class_Cosmogramme_Integration_Record_AuthorityResult::newRejectWith($message); + } + + + protected function _encoding() { + return $this->_integration->getProfilDonnees()->getAccents(); + } + + + protected function _getFacets() { + $facets = []; + + $fields = Class_Cosmogramme_Integration_Record_AuthorityRelation::possibleFields(); + foreach($fields as $field) + $facets = array_merge($facets, $this->_facetsFromField($field)); + + return $facets; + } + + + protected function _facetsFromField($field) { + $facets = []; + foreach($this->_reader->get_subfield($field) as $relation) + $facets[] = $this->_facetFromRelated($relation, $field); + + return array_filter($facets); + } + + + protected function _facetFromRelated($relation, $field) { + $relation = $this->_reader->decoupe_bloc_champ($relation); + $relation = new Class_Cosmogramme_Integration_Record_AuthorityRelation($relation, $field); + if (!$relation->isValid()) + return; + + $record = $this->_save($relation->id(), + ['type' => Class_Notice::TYPE_AUTHORITY, + 'type_doc' => $relation->authorityType(), + 'titres' => $this->_indexation->getFulltext($relation->label()), + 'alpha_titre' => $this->_indexation->codeAlphaTitre($relation->label())]); + + $this->_saveCodifFor($relation->authorityType(), $relation->label()); + + return $relation->facet(); + } + + + protected function _save($id_origine, $record) { + $attribs = ['type' => Class_Notice::TYPE_AUTHORITY, + 'id_origine' => $id_origine, + 'id_int_bib' => $this->_getIdBib()]; + + return ($item = Class_Exemplaire::findFirstBy($attribs)) + ? $this->_update($item, $record) + : $this->_insert($attribs, $record); + } + + + protected function _insert($item, $record) { + $new_record = Class_Notice::newInstance($record); + $new_record + ->setDateMaj($this->getTimeSource()->dateDayAndHours()) + ->save(); + + Class_Exemplaire::newInstance($item) + ->setNotice($new_record) + ->save(); + + return $new_record; + } + + + protected function _update($item, $record) { + $item->setToDelete(false)->save(); + if (!$existing_record = $item->getNotice()) + return; + + if (array_key_exists('unimarc', $record) + && '' != $record['unimarc']) + $existing_record->updateAttributes($record); + + $existing_record + ->setDateMaj($this->getTimeSource()->dateDayAndHours()); + + $existing_record->save(); + + return $existing_record; + } + + + protected function _saveCodifFor($type, $label) { + if ('j' == $type) + $this->getCodifProvider()->getTopic($label); + } + + + protected function _addRejectsTo($title) { + $parts = [$title]; + + $rejects = $this->_authority_type->valuesFrom('4', 'a', $this->_reader); + foreach($rejects as $reject) + $parts[] = $reject; + + return implode(' ', $parts); + } + + + public function getStatut() { + return $this->_statut; + } + + + protected function _getTitle() { + return $this->_authority_type->valueFromFirstIn('2', 'a', $this->_reader); + } + + + protected function _isRepeatedTitle() { + return $this->_authority_type->isRepeatedIn('2', 'a', $this->_reader); + } + + + protected function _getAuthorityType() { + $detected = $this->_authority_type->codeFromFirstIn('2', $this->_reader); + return $detected ? $detected : $this->_reader->labelPart(9, 1); + + } + + + protected function _getCreationYear() { + return ($field = current($this->_reader->get_subfield('100', 'a'))) + ? substr($field, 0, 4) + : ''; + } + + + protected function _getId() { + return current($this->_reader->get_subfield('001')); + } + + + protected function _getIdBib() { + return $this->_integration->getIdBib(); + } + + + protected function getCodifProvider() { + if (null == $this->_codif_provider) + $this->_codif_provider = (new Class_Cosmogramme_Integration_CodifProvider) + ->setIndexation($this->_indexation); + + return $this->_codif_provider; + } + + + /** @category testing */ + public function setCodifProvider($provider) { + $this->_codif_provider = $provider; + return $this; + } +} diff --git a/library/Class/Cosmogramme/Integration/Record/AuthorityRelation.php b/library/Class/Cosmogramme/Integration/Record/AuthorityRelation.php new file mode 100644 index 0000000000000000000000000000000000000000..bfb23eb88b7738a1c1ef1aafd3bfe1758c01cc05 --- /dev/null +++ b/library/Class/Cosmogramme/Integration/Record/AuthorityRelation.php @@ -0,0 +1,80 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Cosmogramme_Integration_Record_AuthorityRelation { + const + FIELD_ID = '3', + FIELD_TYPE = '5', + FIELD_LABEL = 'a'; + + protected + $_id, + $_type = 'z', + $_label, + $_authority_type; + + public static function possibleFields() { + return (new Class_Cosmogramme_Integration_Record_AuthorityType) + ->variantsOf(['4', '5']); + } + + + public function __construct($datas, $field) { + if (!$datas) + return; + + $map = [static::FIELD_ID => '_id', + static::FIELD_TYPE => '_type', + static::FIELD_LABEL => '_label']; + + foreach($datas as $pair) + if (array_key_exists($pair['code'], $map)) + $this->{$map[$pair['code']]} = $pair['valeur']; + + $this->_authority_type = (new Class_Cosmogramme_Integration_Record_AuthorityType) + ->codeFromField($field); + } + + + public function isValid() { + return $this->_id && $this->_label; + } + + + public function id() { + return $this->_id; + } + + + public function label() { + return $this->_label; + } + + + public function facet() { + return $this->_type . $this->_id; + } + + + public function authorityType() { + return $this->_authority_type; + } +} diff --git a/library/Class/Cosmogramme/Integration/Record/AuthorityResult.php b/library/Class/Cosmogramme/Integration/Record/AuthorityResult.php new file mode 100644 index 0000000000000000000000000000000000000000..7ad29b0e1204e453f953f10f25f98109f224b1c5 --- /dev/null +++ b/library/Class/Cosmogramme/Integration/Record/AuthorityResult.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Cosmogramme_Integration_Record_AuthorityResult { + const + RECORD_REJECT = 0, + RECORD_INSERT = 1; + + protected + $_status, + $_message = ''; + + + public static function newRejectWith($message) { + return new static(static::RECORD_REJECT, $message); + } + + + public static function newInsert() { + return new static(static::RECORD_INSERT); + } + + + public function __construct($status, $message='') { + $this->_status = $status; + $this->_message = $message; + } + + + public function isReject() { + return static::RECORD_REJECT === $this->_status; + } + + + public function getStatus() { + return $this->_status; + } + + + public function getMessage() { + return $this->_message; + } +} diff --git a/library/Class/Cosmogramme/Integration/Record/AuthorityType.php b/library/Class/Cosmogramme/Integration/Record/AuthorityType.php new file mode 100644 index 0000000000000000000000000000000000000000..2b704179aa21ac4ec5f633b1a6051bb9eb3848f7 --- /dev/null +++ b/library/Class/Cosmogramme/Integration/Record/AuthorityType.php @@ -0,0 +1,103 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Cosmogramme_Integration_Record_AuthorityType { + protected $_map = + [ + '00' => 'a',// = nom de personne + '10' => 'b',// = nom de collectivité + '15' => 'c',// = nom de territoire ou nom géographique + '16' => 'd',// = marque + '20' => 'e',// = famille + '30' => 'f',// = titre uniforme + '35' => 'g',// = rubrique de classement + '40' => 'h',// = auteur / titre + '45' => 'i',// = auteur / rubrique de classement + '50' => 'j',// = matière nom commun + '60' => 'k',// = lieu d’édition + '80' => 'l',// = forme, genre ou caractéristiques physiques + ]; + + + public function codeFromField($field) { + if (!$field) + return ''; + + $key = substr($field, 1); + + return array_key_exists($key, $this->_map) + ? $this->_map[$key] + : ''; + } + + + public function codeFromFirstIn($prefix, $reader) { + foreach($this->_map as $zone => $type) + if ($reader->get_subfield($prefix . $zone)) + return $type; + } + + + public function valueFromFirstIn($prefix, $subfield, $reader) { + foreach($this->_variantsOfOne($prefix) as $field) + if ($result = $reader->get_subfield($field, $subfield)) + return current($result); + } + + + public function isRepeatedIn($prefix, $subfield, $reader) { + foreach($this->_variantsOfOne($prefix) as $field) + if ($result = $reader->get_subfield($field, $subfield)) + return 1 < count($result); + } + + + public function valuesFrom($prefix, $subfield, $reader) { + $values = []; + foreach($this->_variantsOfOne($prefix) as $field) + if ($result = $reader->get_subfield($field, $subfield)) + $values = array_merge($values, $result); + + return $values; + } + + + public function variantsOf($prefixes) { + $variants = []; + foreach($prefixes as $prefix) + $variants = array_merge($variants, $this->_variantsOfOne($prefix)); + + return $variants; + } + + + protected function _variantsOfOne($prefix) { + return array_map(function($zone) use($prefix) { return $prefix . $zone; }, + array_keys($this->_map)); + } + + + public function withZonesDo($closure) { + foreach($this->_map as $zone => $type) + $closure($zone, $type); + } +} \ No newline at end of file diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php index db1c6ac582afb9d8eaed7a900aa2b4659a89a05a..ff22fc58a85d2dda4419b5dce43a5b7c4367f49d 100644 --- a/library/Class/Exemplaire.php +++ b/library/Class/Exemplaire.php @@ -91,7 +91,8 @@ class Class_Exemplaire extends Storm_Model_Abstract { 'activite' => null, 'date_nouveaute' => '', 'to_delete' => false, - 'id_int_bib' => 0]; + 'id_int_bib' => 0, + 'type' => Class_Notice::TYPE_BIBLIOGRAPHIC]; protected $_sigb_exemplaire; diff --git a/library/Class/IntProfilDonnees.php b/library/Class/IntProfilDonnees.php index 161307b1d541f20713ad2c8fe0731ebd05b9f573..f7654f4491d973d9d66c4dc490ecd534f5f3b56f 100644 --- a/library/Class/IntProfilDonnees.php +++ b/library/Class/IntProfilDonnees.php @@ -57,6 +57,7 @@ class IntProfilDonneesLoader extends Storm_Model_Loader { public function getFileTypes() { return [Class_IntProfilDonnees::FT_RECORDS => $this->_('Notices'), + Class_IntProfilDonnees::FT_AUTHORITY => $this->_('Autorités'), Class_IntProfilDonnees::FT_PATRONS => $this->_('Abonnés'), Class_IntProfilDonnees::FT_LOANS => $this->_('Prêts'), Class_IntProfilDonnees::FT_HOLDS => $this->_('Réservations'), @@ -235,6 +236,7 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { FT_LOANS = 2, FT_HOLDS = 3, FT_BASKETS = 4, + FT_AUTHORITY = 5, ENCODING_UTF8 = 0, ENCODING_ISO2709 = 1, ENCODING_WINDOWS_ANSI = 2, @@ -851,6 +853,11 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract { } + public function isAuthorityRecords() { + return self::FT_AUTHORITY == $this->getTypeFichier(); + } + + public function isBaskets() { return self::FT_BASKETS == $this->getTypeFichier(); } diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 50e08a9b8638d04ec397500606c644da3a97193c..47a9f79fa63f2c1e3247ca47eaea7bae26bc04e8 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -21,7 +21,8 @@ class Class_MoteurRecherche { use Trait_Singleton, Trait_Translator, Trait_TimeSource, Trait_SearchCriteriaVisitor; - private $ix; // Classe d'indexation + /** Classe d'indexation */ + private $ix; protected $all_facettes, @@ -31,26 +32,27 @@ class Class_MoteurRecherche { $fil_ariane, $rubriques, $_domain_conditions = null, - $conditions = '', + $_conditions = [], $_with_operator_conditions = [], $_or_conditions = '', $_filter_domain_conditions = '', - $_limit; - - protected $_extensible = true; + $_limit, + $_type_condition, + $_extensible = true; public function __construct() { $this->ix = new Class_Indexation(); + $this->_type_condition = 'type=' . Class_Notice::TYPE_BIBLIOGRAPHIC; } public function getConditions() { - return $this->conditions; + return $this->_conditions; } - public function getorConditions() { + public function getOrConditions() { return $this->_or_conditions; } @@ -173,10 +175,7 @@ class Class_MoteurRecherche { if(!$condition) return $this; - if ($this->conditions != '') - $this->conditions .= ' and '; - - $this->conditions .= $condition; + $this->_conditions[] = $condition; return $this; } @@ -264,7 +263,7 @@ class Class_MoteurRecherche { public function visitFacetteDomainForOrConditions($domain_id) { - $this->setOrConditions(self::prepareFacetteDomainForOrConditions($domain_id)); + $this->setOrConditions($this->prepareFacetteDomainForOrConditions($domain_id)); } @@ -341,26 +340,33 @@ class Class_MoteurRecherche { } - public static function getConditionsForRequest($ands = '', $ors = '', $filter = '') { - if(!$ands && !$ors) - return ''; + public function getConditionsForRequest($ands = [], $ors = '', $filter = '') { + if (!$ands && !$ors) + return ' Where ' . $this->_type_condition; - if(!$ors && !$filter) - return ' Where ' . $ands; + $ands = implode(' and ', $ands); - if(!$ors && $filter) - return ' Where (' . $ands . ')' . $filter; + if (!$ors && !$filter) + return $this->_whereAndType($ands); - if(!$ands && !$filter) - return ' Where ' . $ors; + if (!$ors && $filter) + return $this->_whereAndType('(' . $ands . ')' . $filter); - if(!$ands && $filter) - return ' Where (' . $ors . ')' . $filter; + if (!$ands && !$filter) + return $this->_whereAndType($ors); - if(!$filter) - return ' Where (' . $ands . ')'.' or '. $ors; + if (!$ands && $filter) + return $this->_whereAndType('(' . $ors . ')' . $filter); - return ' Where ((' . $ands . ')'.' or '. $ors . ')' . $filter; + if (!$filter) + return $this->_whereAndType('(' . $ands . ') or '. $ors); + + return $this->_whereAndType('((' . $ands . ') or '. $ors . ')' . $filter); + } + + + protected function _whereAndType($clauses) { + return ' Where (' . $clauses . ') and ' . $this->_type_condition; } @@ -376,7 +382,7 @@ class Class_MoteurRecherche { if (is_array($search_engine->buildWherePartQuery())) return; - $this->_domain_conditions = $search_engine->getConditions(); + $this->_domain_conditions = implode(' and ', $search_engine->getConditions()); } @@ -387,8 +393,8 @@ class Class_MoteurRecherche { if(is_array($search_engine->buildWherePartQuery())) return; - $this->setFilterDomainConditions(self::getConditionsForRequest($search_engine->getConditions(), - $search_engine->getOrConditions())); + $this->setFilterDomainConditions($this->getConditionsForRequest($search_engine->getConditions(), + $search_engine->getOrConditions())); } @@ -404,7 +410,7 @@ class Class_MoteurRecherche { public function visitSearchSettings($criteres_recherche) { $this->criteres_recherche = $criteres_recherche; - $this->conditions = ''; + $this->_conditions = []; $this->_with_operator_conditions = []; $this->all_facettes = ''; $this->nb_mots = 0; @@ -431,19 +437,21 @@ class Class_MoteurRecherche { $operators_conditions = '(' . (strpos($first_condition['operator'], 'not') ? 'not ' : '') . $first_condition['condition']; foreach ($this->_with_operator_conditions as $condition) $operators_conditions .= ' ' . $condition['operator'] . ' ' . $condition['condition']; + $operators_conditions .= ')'; - $this->conditions = implode(' and ', array_filter([$this->conditions, $operators_conditions])); - return $this; + return $this->setCondition($operators_conditions); } public function buildWherePartQuery() { $this->injectWithOperatorConditions(); - if(!is_null($this->_domain_conditions)) { + if (!is_null($this->_domain_conditions)) { $this->setCondition($this->_domain_conditions); - return self::getConditionsForRequest($this->conditions, $this->_or_conditions, $this->_filter_domain_conditions); + return $this->getConditionsForRequest($this->getConditions(), + $this->_or_conditions, + $this->_filter_domain_conditions); } if ($this->multi_facets) @@ -452,18 +460,18 @@ class Class_MoteurRecherche { if ($this->all_facettes) $this->setCondition("MATCH(facettes) AGAINST('" . trim($this->all_facettes)."' IN BOOLEAN MODE)"); - if($this->criteres_recherche->hasEmptyDomain() - && !$this->criteres_recherche->isSearchInBasket()){ + if ($this->criteres_recherche->hasEmptyDomain() + && !$this->criteres_recherche->isSearchInBasket()) return ['statut' => 'erreur', 'erreur' => $this->_('Domaine non paramétré')]; - } - if($this->criteres_recherche->isEmptySelection()){ + if ($this->criteres_recherche->isEmptySelection()) return ['statut' => 'erreur', 'erreur' => $this->_('La sélection courante est vide')]; - } - return self::getConditionsForRequest($this->conditions, $this->_or_conditions, $this->_filter_domain_conditions); + return $this->getConditionsForRequest($this->getConditions(), + $this->_or_conditions, + $this->_filter_domain_conditions); } @@ -677,7 +685,7 @@ class Class_MoteurRecherche { ->visitMultiFacets($this->multi_facets) ->visitDomainConditions($this->_domain_conditions) ->visitFilterDomainConditions($this->_filter_domain_conditions) - ->visitConditions($this->conditions) + ->visitConditions($this->getConditions()) ->visitConditionsWithOperator($this->_with_operator_conditions) ->visitOrConditions($this->_or_conditions) ->visitCompleteWhere($this->buildWherePartQuery()) diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 9226dc793f0d660c4554076ffb6f8db63b886737..8ffb455ef70a0629e3c19eced89b7f2ba7492c49 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -159,6 +159,10 @@ class NoticeLoader extends Storm_Model_Loader { class Class_Notice extends Storm_Model_Abstract { use Trait_TimeSource, Trait_Translator; + const + TYPE_BIBLIOGRAPHIC = 1, + TYPE_AUTHORITY = 2; + protected $_loader_class = 'NoticeLoader'; protected $_table_name = 'notices'; protected $_table_primary = 'id_notice'; @@ -200,7 +204,8 @@ class Class_Notice extends Storm_Model_Abstract { 'url_vignette' => '', 'url_image' => '', 'date_creation' => '', - 'created_at' => null]; + 'created_at' => null, + 'type' => self::TYPE_BIBLIOGRAPHIC]; public function __construct() { diff --git a/library/Class/Notice/BarcodeDoubleFinder.php b/library/Class/Notice/BarcodeDoubleFinder.php index 849ae20086c2672e293aa7f89ce42e88e786b1ba..552f5d78f26348cf738ea799d74f50ead572b5bc 100644 --- a/library/Class/Notice/BarcodeDoubleFinder.php +++ b/library/Class/Notice/BarcodeDoubleFinder.php @@ -34,16 +34,16 @@ class Class_Notice_BarcodeDoubleFinder extends Class_Notice_DoubleFinder { } - protected function _getRecordIdByItem($conditions) { - if ($id = parent::_getRecordIdByItem($conditions)) - return $id; + protected function _getRecordIdByItemFilters() { + $filters = parent::_getRecordIdByItemFilters(); + $filters[] = [$this, '_filterSigbLoanable']; + return $filters; + } - $founds = Class_Exemplaire::findAllBy($conditions); - if (empty($founds)) - return; - foreach($founds as $found) - if ($found->isSigbLoanable()) - return $found->getIdNotice(); + protected function _filterSigbLoanable($items) { + foreach($items as $item) + if ($item->isSigbLoanable()) + return $item; } } \ No newline at end of file diff --git a/library/Class/Notice/DoubleFinder.php b/library/Class/Notice/DoubleFinder.php index 5517ad0fbb6269e1bf4667d0ca12caaafea66db8..628c45bbb43a52f6452646a95ff4adf63ee4b4cd 100644 --- a/library/Class/Notice/DoubleFinder.php +++ b/library/Class/Notice/DoubleFinder.php @@ -107,16 +107,29 @@ class Class_Notice_DoubleFinder { protected function _getRecordIdByItem($conditions) { + $conditions['type'] = Class_Notice::TYPE_BIBLIOGRAPHIC; $founds = Class_Exemplaire::findAllBy($conditions); if (empty($founds)) return; - foreach($founds as $found) - if ($this->_data->gettype_doc() == $found->getTypeDoc()) + foreach($this->_getRecordIdByItemFilters() as $filter) + if ($found = $filter($founds)) return $found->getIdNotice(); } + protected function _getRecordIdByItemFilters() { + return [ [$this, '_filterSameDoctype'] ]; + } + + + protected function _filterSameDoctype($items) { + foreach($items as $item) + if ($this->_data->gettype_doc() == $item->getTypeDoc()) + return $item; + } + + protected function findByIds() { foreach ($this->recordAttributes() as $attr) if ($id = $this->findById($attr)) @@ -152,7 +165,8 @@ class Class_Notice_DoubleFinder { if(!$key || !$value) return; - $founds = Class_Notice::findAllBy([$key => $value]); + $founds = Class_Notice::findAllBy(['type' => Class_Notice::TYPE_BIBLIOGRAPHIC, + $key => $value]); if(empty($founds)) return; diff --git a/library/Class/NoticeUnimarc.php b/library/Class/NoticeUnimarc.php index 85dcfdf4b402ba22a87d18af3b30bcd37743866c..91eddde21929950f8450d1824a6be57dc85a5599 100644 --- a/library/Class/NoticeUnimarc.php +++ b/library/Class/NoticeUnimarc.php @@ -234,4 +234,9 @@ class Class_NoticeUnimarc { return implode(' ', $datas); } + + + public function labelPart($start, $length) { + return substr($this->guide, $start, $length); + } } diff --git a/library/Class/Systeme/Include.php b/library/Class/Systeme/Include.php index 07044a43c1703675b89a7e3f14c508573f810b47..b9d2f78cd7d91fafd0e8f2fc2da3c201dbedadab 100644 --- a/library/Class/Systeme/Include.php +++ b/library/Class/Systeme/Include.php @@ -16,7 +16,7 @@ * * 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 Class_Systeme_Include { protected static $_instance; @@ -42,5 +42,3 @@ class Class_Systeme_Include { return true; } } - -?> diff --git a/library/ZendAfi/View/Helper/SearchInspector.php b/library/ZendAfi/View/Helper/SearchInspector.php index 77065a406d6d20cf416760d4f3b3cb00fee7248a..b81710a2f2eda5463e60f2778c7577e0a025ef2e 100644 --- a/library/ZendAfi/View/Helper/SearchInspector.php +++ b/library/ZendAfi/View/Helper/SearchInspector.php @@ -74,7 +74,7 @@ class ZendAfi_View_Helper_SearchInspector extends ZendAfi_View_Helper_BaseHelper public function visitConditions($value) { - $this->_datas[$this->_('Clauses simples')] = $value; + $this->_datas[$this->_('Clauses simples')] = implode(' and ', $value); return $this; } diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php index 49a7d8076e06c171d3d37d2f17640ad4387a9ce2..4cd4b1029934b878e0a876024a0ee0772f81ed72 100644 --- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php +++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php @@ -607,7 +607,7 @@ class CatalogueControllerActionTesterTest extends AbstractControllerTestCase { /** @test */ public function pageShouldDisplayRequest() { - $this->assertContains("select * from notices Where MATCH(facettes) AGAINST(' +(B1) +( D78308*)' IN BOOLEAN MODE) and notices.type_doc IN ('1', '3', '4', '5') and annee >= '2012' and annee <= '2012' order by alpha_titre LIMIT 0,20", + $this->assertContains("select * from notices Where (MATCH(facettes) AGAINST(' +(B1) +( D78308*)' IN BOOLEAN MODE) and notices.type_doc IN ('1', '3', '4', '5') and annee >= '2012' and annee <= '2012') and type=1 order by alpha_titre LIMIT 0,20", $this->_response->getBody()); } diff --git a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php index 73ba3dcf243a5a1959f09bbd141bff0b900d7260..f6e1de88be9556f93c6e7c7d49a98afbe72504b9 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAtomTest.php @@ -86,13 +86,13 @@ class RechercheControllerAtomEmptyTest extends RechercheControllerAtomTestCase { protected function _prepareSql($sql) { $sql->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+S1 +G123' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+S1 +G123' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) ->answers([]) ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST(' (HARRY HARRYS ARI) (POTTER POTTERS POT)') and MATCH(facettes) AGAINST('+S1 +G123' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST(' (HARRY HARRYS ARI) (POTTER POTTERS POT)') and MATCH(facettes) AGAINST('+S1 +G123' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) ->answers([]) diff --git a/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php b/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php index e49aa5c4c82719b968daac3e8048a9359fb6954a..f562f6107a9b48bf546a46ecd21f2e8ef15818a7 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php @@ -65,7 +65,7 @@ class RechercheControllerJsonEmptyResultTest extends RechercheControllerJsonTest protected function _prepareSql($sql) { $sql->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices', true, false) + ->with('select id_notice, facettes from notices Where type=1', true, false) ->answers([]); } @@ -140,7 +140,7 @@ class RechercheControllerJsonWithResultTest extends RechercheControllerJsonTestC protected function _prepareSql($sql) { $sql->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices', true, false) + ->with('select id_notice, facettes from notices Where type=1', true, false) ->answers([ ['234', ''], ['10141532', ''] @@ -401,7 +401,7 @@ class RechercheControllerJsonWithFromTest extends RechercheControllerJsonTestCas protected function _prepareSql($sql) { $sql->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices Where date_maj >\'2016-08-31\'', true, false) + ->with('select id_notice, facettes from notices Where (date_maj >\'2016-08-31\') and type=1', true, false) ->answers([ ['234', ''], ['10141532', ''] @@ -463,7 +463,7 @@ class RechercheControllerJsonWithWrongFromTest extends RechercheControllerJsonTe protected function _prepareSql($sql) { $sql->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices', true, false) + ->with('select id_notice, facettes from notices Where type=1', true, false) ->answers([]) ->whenCalled('execute') diff --git a/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php b/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php index 839e6c48f0539005b302a83259521edfa6a86b08..a995f3d649cef62ed97134bd0a8cd4b723089d9e 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php @@ -78,7 +78,7 @@ class RechercheControllerPrintActionWithRecordsTest extends AbstractControllerTe $mock_sql = $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' POMME') * 1.5) + (MATCH(auteurs) AGAINST(' POMME')) desc", + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' POMME') * 1.5) + (MATCH(auteurs) AGAINST(' POMME')) desc", true, false) ->answers([ diff --git a/tests/application/modules/opac/controllers/RechercheControllerSimpleSerieTest.php b/tests/application/modules/opac/controllers/RechercheControllerSimpleSerieTest.php index 540c2807791b20718cb5ee5d8e36b1d0a9fe1ea7..ed91d803eedbcaebcf4e608cb2c9bfd1f4c424d1 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerSimpleSerieTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerSimpleSerieTest.php @@ -35,7 +35,7 @@ class RechercheControllerRechercheSimpleSerieTest /** @test */ public function withoutTypeDocshouldQueryWithoutTypeDoc() { $this->dispatch('recherche/simple/serie/PAPIERS/tri/date_creation+desc', true); - $this->assertEquals(' Where clef_chapeau="PAPIERS" ', + $this->assertEquals(' Where (clef_chapeau="PAPIERS" ) and type=1', $this->_search->buildWherePartQuery()); } @@ -43,7 +43,7 @@ class RechercheControllerRechercheSimpleSerieTest /** @test */ public function withTypeDocshouldQueryWithTypeDoc() { $this->dispatch('recherche/simple/serie/PAPIERS-2/tri/date_creation+desc', true); - $this->assertEquals(' Where clef_chapeau="PAPIERS" and type_doc="2"', + $this->assertEquals(' Where (clef_chapeau="PAPIERS" and type_doc="2") and type=1', $this->_search->buildWherePartQuery()); } } diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 2eb4e40c5c9a66b066838ce9a5218ac9e04b9d72..784e2d77efd3e23aafef3e422da335a4ac1c4cd3 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -177,7 +177,7 @@ class RechercheControllerPagerTest extends RechercheControllerNoticeTestCase { $records = array_map(function($i) { return [$i, ''];}, range(1, 45) ); $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' POMME') * 1.5) + (MATCH(auteurs) AGAINST(' POMME')) desc", + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' POMME') * 1.5) + (MATCH(auteurs) AGAINST(' POMME')) desc", true, false) ->answers($records) @@ -699,7 +699,7 @@ class RechercheControllerViewNoticeClefAlphaTest extends RechercheControllerNoti $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(MILLENIUM MILLENIUMS MILENIUM)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' MILLENIUM') * 1.5) + (MATCH(auteurs) AGAINST(' MILLENIUM')) desc", true, null) + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(MILLENIUM MILLENIUMS MILENIUM)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' MILLENIUM') * 1.5) + (MATCH(auteurs) AGAINST(' MILLENIUM')) desc", true, null) ->answers([ [10, ''], [99, ''], @@ -2207,7 +2207,7 @@ class RechercheControllerWithPanierTest extends RechercheControllerNoticeTestCas $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where notices.clef_alpha in('COMBAT ORDINAIRE', 'BLACKSAD') order by FIELD(notices.clef_alpha, 'COMBAT ORDINAIRE', 'BLACKSAD')", true, false) + ->with("select id_notice, facettes from notices Where (notices.clef_alpha in('COMBAT ORDINAIRE', 'BLACKSAD')) and type=1 order by FIELD(notices.clef_alpha, 'COMBAT ORDINAIRE', 'BLACKSAD')", true, false) ->answers([ [1, ''], @@ -2585,7 +2585,7 @@ class RechercheControllerNavigationTest extends RechercheControllerNoticeTestCas $this->mock_sql = $this->mock() ->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices order by alpha_titre', true, false) + ->with('select id_notice, facettes from notices Where type=1 order by alpha_titre', true, false) ->answers([ [28, ''], [12, ''], @@ -2649,7 +2649,7 @@ class RechercheControllerNavigationTest extends RechercheControllerNoticeTestCas public function navigationSuivantOnNoticeLesarbresWhenResultatRechercheIsEmptyShouldRedirectToCurrentNoticeLsearbres() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices order by alpha_titre', true, false) + ->with('select id_notice, facettes from notices Where type=1 order by alpha_titre', true, false) ->answers([]); @@ -2662,7 +2662,7 @@ class RechercheControllerNavigationTest extends RechercheControllerNoticeTestCas public function navigationSuivantOnNoticeLesarbresWhenResultatRechercheAsMussoResultShouldRedirectToCurrentNoticeMusso() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices order by alpha_titre', true, false) + ->with('select id_notice, facettes from notices Where type=1 order by alpha_titre', true, false) ->answers([ [28, '' ] ]); $this->dispatch('/recherche/viewnotice/id/28/tri/alpha_titre/navigation/suivant',true); @@ -3081,7 +3081,7 @@ class RechercheControllerSimpleActionWithEmptyDomainSettingsAndSiteLinkedTest ex $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE) order by annee desc", true, false) + ->with("select id_notice, facettes from notices Where ((MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE)) and type=1) and type=1 order by annee desc", true, false) ->answers([ [1, ''] ]) ->whenCalled('fetchOne') ->answers(1) @@ -3185,7 +3185,7 @@ class RechercheControlleSimpleActionWithMultifacetsThesauriTest extends Recherch $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(facettes) AGAINST('+(HDOCU0001 HDOCU0002 HDOCU00020001) +(HMUSI0001)' IN BOOLEAN MODE)", true, false) + ->with("select id_notice, facettes from notices Where (MATCH(facettes) AGAINST('+(HDOCU0001 HDOCU0002 HDOCU00020001) +(HMUSI0001)' IN BOOLEAN MODE)) and type=1", true, false) ->answers([ [1, ''] ]) ->whenCalled('fetchOne') @@ -3231,7 +3231,7 @@ class RechercheControlleSimpleActionWithEmptyDomainSettingsAndArticlesLinkedTest $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE) order by annee desc", true, false) + ->with("select id_notice, facettes from notices Where ((MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE)) and type=1) and type=1 order by annee desc", true, false) ->answers([ [1, ''] ]) ->whenCalled('fetchOne') @@ -3315,7 +3315,7 @@ class RechercheControlleSiteInResultAndModeThumbnailTest extends RechercheContro $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE) order by annee desc", true, false) + ->with("select id_notice, facettes from notices Where ((MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE)) and type=1) and type=1 order by annee desc", true, false) ->answers([ [1, ''] ]) ->whenCalled('fetchOne') ->answers(1) @@ -3421,7 +3421,7 @@ class RechercheControllerSimpleSearchTest extends AbstractControllerTestCase { ->whenCalled('fetchOne') ->answers(null) ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices limit 2", true, false) + ->with("select id_notice, facettes from notices Where type=1 limit 2", true, false) ->answers([ [1, ''], [2, ''] @@ -3461,7 +3461,7 @@ class RechercheControllerNoExtensionTest extends AbstractControllerTestCase { $this->mock_sql = $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(VIE VIES) +(GEEK GEEKS JEK)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc", true, false) + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(VIE VIES) +(GEEK GEEKS JEK)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc", true, false) ->answers([[1, '']]) ->beStrict(); diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 93b2c114d4b85ff11d62f3e1ef0113a6642c4979..b16529eb9ed7edc2f1a60440e9079a6806b0e71e 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -2132,7 +2132,6 @@ class UpgradeDB_349_Test extends UpgradeDBTestCase { - class UpgradeDB_350_Test extends UpgradeDBTestCase { public function prepare() { try { @@ -2329,3 +2328,47 @@ class UpgradeDB_357_Test extends UpgradeDBTestCase { $other_index_fields); } } + + + +class UpgradeDB_358_Test extends UpgradeDBTestCase { + public function prepare() { + $this->silentQuery("UPDATE `variables` SET liste='0:notices\r\n1:abonnés\r\n2:prêts\r\n3:reservations\r\n4:paniers' WHERE clef='type_fichier'") + ->silentQuery('ALTER TABLE notices drop KEY type') + ->silentQuery('ALTER TABLE notices drop column type') + ->silentQuery('ALTER TABLE exemplaires drop KEY type') + ->silentQuery('ALTER TABLE exemplaires drop column type') + ; + } + + + /** @test */ + public function typeFichierVarShouldContainsAutorites() { + $type_fichier = $this->query('select liste from variables where clef="type_fichier"')->fetch(); + $this->assertContains('5:autorités', $type_fichier['liste']); + } + + + /** @test */ + public function recordShouldHaveType() { + $this->assertFieldType('notices', 'type', 'int(11)'); + } + + + /** @test */ + public function recordTypeShouldBeIndexed() { + $this->assertIndex('notices', 'type'); + } + + + /** @test */ + public function itemShouldHaveType() { + $this->assertFieldType('exemplaires', 'type', 'int(11)'); + } + + + /** @test */ + public function itemTypeShouldBeIndexed() { + $this->assertIndex('exemplaires', 'type'); + } +} \ No newline at end of file diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index f170b7b29e7c47cfb26d144242f68c9b27ca0be5..d0b8cfb3674f8f5620e3b2b9697f8d6324b1ccfc 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -54,26 +54,26 @@ class CatalogueTestGetRequetesPanierWithIdUserAndIdPanier extends ModelTestCase public function testRequeteListe() { - $this->assertEquals("select * from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' order by alpha_titre LIMIT 0,3", + $this->assertEquals("select * from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' and type=1 order by alpha_titre LIMIT 0,3", $this->requetes['req_liste']); } public function testRequeteComptage() { - $this->assertEquals("select count(*) from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' ", + $this->assertEquals("select count(*) from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' and type=1 ", $this->requetes['req_comptage']); } public function testRequeteFacettes() { - $this->assertEquals("select id_notice, notices.type_doc, facettes from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' LIMIT 0,3", + $this->assertEquals("select id_notice, notices.type_doc, facettes from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' and type=1 LIMIT 0,3", $this->requetes['req_facettes']); } /** @test */ public function requestWithBasketOrderShouldOrderByField() { - $this->assertEquals('select * from notices where notices.clef_alpha in(\'STARWARS\',\'JAMESBOND\') and url_vignette > \'\' and url_vignette != \'NO\' order by FIELD(notices.clef_alpha, \'STARWARS\',\'JAMESBOND\') LIMIT 0,3', + $this->assertEquals('select * from notices where notices.clef_alpha in(\'STARWARS\',\'JAMESBOND\') and url_vignette > \'\' and url_vignette != \'NO\' and type=1 order by FIELD(notices.clef_alpha, \'STARWARS\',\'JAMESBOND\') LIMIT 0,3', $this->requests_with_basket_order['req_liste']); } @@ -104,7 +104,7 @@ class CatalogueTestGetRequetesPanierWithIdUserAndIdPanierUsedForId extends Model public function testRequeteListe() { - $this->assertEquals("select * from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' order by alpha_titre LIMIT 0,3", + $this->assertEquals("select * from notices where notices.clef_alpha in('STARWARS','JAMESBOND') and url_vignette > '' and url_vignette != 'NO' and type=1 order by alpha_titre LIMIT 0,3", $this->requetes['req_liste']); } } @@ -481,19 +481,19 @@ class CatalogueTestGetRequetesWithFacettesAndNoCatalogue extends ModelTestCase { /** @test */ public function requeteListeShouldEqualsSelectStarWhereFacettesFromNotices() { - $this->assertEquals('select * from notices Where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE) order by alpha_titre LIMIT 5000', $this->_requetes['req_liste']); + $this->assertEquals('select * from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre LIMIT 5000', $this->_requetes['req_liste']); } /** @test */ public function requeteComptageShouldBeSelectCount() { - $this->assertEquals('select count(*) from notices Where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)', $this->_requetes['req_comptage']); + $this->assertEquals('select count(*) from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1', $this->_requetes['req_comptage']); } /** @test */ public function requeteFacettesShouldBeSelectIdNoticeTypeDocFacet() { - $this->assertEquals('select notices.id_notice, notices.type_doc, facettes from notices Where MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE) LIMIT 5000', $this->_requetes['req_facettes']); + $this->assertEquals('select notices.id_notice, notices.type_doc, facettes from notices Where (MATCH(facettes) AGAINST(\' +(T1, Y1)\' IN BOOLEAN MODE)) and type=1 LIMIT 5000', $this->_requetes['req_facettes']); } } @@ -572,7 +572,7 @@ class CatalogueGetNoticesByPreferencesNotRandomTest extends ModelTestCase { Zend_Registry::set('sql', $this->mock() ->whenCalled('fetchAllByColumn') - ->with("select notices.id_notice from notices Where notices.type_doc='1' order by alpha_titre LIMIT 0,40") + ->with("select notices.id_notice from notices Where (notices.type_doc='1') and type=1 order by alpha_titre LIMIT 0,40") ->answers([23]) ->beStrict()); @@ -1051,7 +1051,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends ModelTestCase { public function queryWithNb5Page10() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice from notices Where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre limit 50,5') + ->with('select id_notice from notices Where (MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre limit 50,5') ->answers([ ['id_notice' => 23, 'titre' => 'POTTER'], ['id_notice' => 45, 'titre' => 'POTTER2'], ]) @@ -1065,7 +1065,7 @@ class CatalogueGetAllNoticesIdsForDomaineTest extends ModelTestCase { public function queryWithNb1Page2() { $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice from notices Where MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE) order by alpha_titre limit 2,1') + ->with('select id_notice from notices Where (MATCH(facettes) AGAINST(\' +(T1)\' IN BOOLEAN MODE)) and type=1 order by alpha_titre limit 2,1') ->answers([]) ->beStrict(); @@ -1172,7 +1172,7 @@ class CatalogueWithNoveltyTest extends ModelTestCase { /** @test */ public function recordFacetsShouldContainsNoveltyForRoubaixAndNoveltyForLille() { - $this->assertSame('select * from notices Where MATCH(facettes) AGAINST(\' +(B10 B11) +(YROUB YISTR) +(HNNNN0001 HNNNN0002 HNANA0001 HNANA0002)\' IN BOOLEAN MODE) and date_creation >= \'2016-05-11\' order by alpha_titre LIMIT 5000', + $this->assertSame('select * from notices Where (MATCH(facettes) AGAINST(\' +(B10 B11) +(YROUB YISTR) +(HNNNN0001 HNNNN0002 HNANA0001 HNANA0002)\' IN BOOLEAN MODE) and date_creation >= \'2016-05-11\') and type=1 order by alpha_titre LIMIT 5000', $this->_domain_request['req_liste']); } } @@ -1192,7 +1192,7 @@ class CatalogueFetchAllNoticeByPrefWithRandomTest extends ModelTestCase { $this->onLoaderOfModel('Class_Notice') ->whenCalled('findAllByRequeteRecherche') - ->with("select notices.id_notice from notices Where MATCH(facettes) AGAINST(' +( A344)' IN BOOLEAN MODE) order by alpha_titre LIMIT 0,1000", + ->with("select notices.id_notice from notices Where (MATCH(facettes) AGAINST(' +( A344)' IN BOOLEAN MODE)) and type=1 order by alpha_titre LIMIT 0,1000", 1000, 1) ->beStrict(); diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseAuthorityTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseAuthorityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e9af0c2775e30eeeda01581f13feaad8f63994c9 --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/PhaseAuthorityTest.php @@ -0,0 +1,168 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 + */ + +require_once __DIR__ . '/PhaseTestCase.php'; + + +class PhaseAuthorityTest extends Class_Cosmogramme_Integration_PhaseTestCase { + public function setUp() { + parent::setUp(); + + $time_source = (new TimeSourceForTest('2018-07-17'))->atCoffeeTime(); + Class_Cosmogramme_Integration_PhaseAuthority::setTimeSource($time_source); + + $this->_phase = $this->_buildPhase('Authority') + ->setMemoryCleaner(function() {}) + ->run(); + + Class_Notice::clearCache(); + } + + + protected function _prepareFixtures() { + $this->fixture('Class_IntProfilDonnees', + ['id' => 102, + 'libelle' => 'Autorités Pergame', + 'accents' => Class_IntProfilDonnees::ENCODING_UTF8, + 'type_fichier' => Class_IntProfilDonnees::FT_AUTHORITY, + 'format' => Class_IntProfilDonnees::FORMAT_UNIMARC, + ]); + + $this->fixture('Class_IntBib', + ['id' => 2, + 'nom_court' => 'UPEC', + 'sigb' => 1]); + + $this->fixture('Class_Cosmogramme_Integration', + ['id' => 999, + 'bib' => Class_IntBib::find(2), + 'profil_donnees' => Class_IntProfilDonnees::find(102), + 'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL, + 'traite' => 'non', + 'fichier' => 'authorities_tess_mini.mrc', + 'pointeur_reprise' => 0]); + } + + + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(-1)) + ->beCron(); + } + + + protected function _recordWithIdOrigine($id) { + return ($item = Class_Exemplaire::findFirstBy(['type' => Class_Notice::TYPE_AUTHORITY, + 'id_origine' => $id])) + ? $item->getNotice() + : null; + } + + + /** @test */ + public function newPhaseShouldBe0() { + $this->assertTrue($this->_phase->isId(0)); + } + + + /** @test */ + public function shouldHave28Records() { + $this->assertEquals(28, Class_Notice::countBy(['type' => Class_Notice::TYPE_AUTHORITY])); + } + + + /** @test */ + public function repeated250DollarAShouldNotBeImported() { + $this->assertNull($this->_recordWithIdOrigine('191145')); + } + + + /** @test */ + public function repeated250DollarAShouldBeLoggedAsError() { + $this->assertLogContains('Autorité avec vedette répétée (191145)'); + } + + + /** @test */ + public function amenagementDuTerritoireShouldExists() { + $this->assertNotNull($record = $this->_recordWithIdOrigine('185349')); + return $record; + } + + + /** @test */ + public function codifMatiereAmenagementDuTerritoireShouldExists() { + $this->assertNotNull(Class_CodifMatiere::findFirstBy(['libelle' => 'Aménagement du territoire'])); + } + + + /** + * @test + * @depends amenagementDuTerritoireShouldExists + */ + public function amenagementDuTerritoireShouldHaveLinksFacets($record) { + $this->assertContains('g192156 ', $record->getFacettes()); + } + + + /** + * @test + * @depends amenagementDuTerritoireShouldExists + */ + public function amenagementDuTerritoireShouldBeMater($record) { + $this->assertEquals('j', $record->getTypeDoc()); + } + + + /** @test */ + public function cadreEtMilieuDeVieShouldExists() { + $this->assertNotNull($record = $this->_recordWithIdOrigine('192156')); + return $record; + } + + + /** + * @test + * @depends cadreEtMilieuDeVieShouldExists + */ + public function cadreEtMilieuDeVieShouldBeMater($record) { + $this->assertEquals('j', $record->getTypeDoc()); + } + + + /** @test */ + public function plieShouldIndexRejects() { + $record = $this->_recordWithIdOrigine('192516'); + $this->assertContains('PLAN LOCAL', $record->getTitres()); + } + + + /** @test */ + public function assuranceMaladieShouldHaveUnimarc() { + $record = $this->_recordWithIdOrigine('185351'); + $this->assertContains('CMU', $record->get_subfield('550', 'a')); + } + + + /** @test */ + public function rejectWithIdShouldExists() { + $this->assertNotNull($this->_recordWithIdOrigine('778899')); + } +} diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseNoticeTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseNoticeTest.php index aea07942190ce17bce297d27556e71a6088fb43d..21215f0a43d249dd9278e8399a1b5fa7efe0e23d 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseNoticeTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseNoticeTest.php @@ -47,6 +47,9 @@ abstract class PhaseNoticeImportTestCase extends PhaseNoticeTestCase { $this->fixture('Class_Exemplaire', ['id' => 889039, 'id_int_bib' => 2]); + $this->fixture('Class_Exemplaire', + ['type' => Class_Notice::TYPE_AUTHORITY, 'id' => 889040, 'id_int_bib' => 2]); + $oscar = $this->fixture('Class_CodifAuteur', ['id' => 42, 'libelle' => 'WILDE oscar', @@ -103,7 +106,7 @@ class PhaseNoticeImportFullTest extends PhaseNoticeImportTestCase { /** @test */ public function totalNumberOfItemsShouldBe109() { - $this->assertEquals(109, Class_Exemplaire::countBy([])); + $this->assertEquals(109, Class_Exemplaire::countBy(['type' => Class_Notice::TYPE_BIBLIOGRAPHIC])); } @@ -128,6 +131,12 @@ class PhaseNoticeImportFullTest extends PhaseNoticeImportTestCase { } + /** @test */ + public function previousAuthorityItemShouldNotBeDeleted() { + $this->assertNotNull(Class_Exemplaire::find(889040)); + } + + /** @test */ public function logShouldContainsDeletedOneItemMessage() { $this->assertLogContains('1 exemplaire(s) supprimé(s)'); diff --git a/tests/library/Class/Cosmogramme/Integration/authorities_tess_mini.mrc b/tests/library/Class/Cosmogramme/Integration/authorities_tess_mini.mrc new file mode 100644 index 0000000000000000000000000000000000000000..b3bd1cfd8378818592d76fbd9861a7fe3bd47ac2 --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/authorities_tess_mini.mrc @@ -0,0 +1 @@ +00978 a2200277 450000500170000010000290001715200090004625000310005555000420008655000360012855000360016455000280020055000360022855000400026455000410030455000320034555000490037755000400042655000340046655000290050055000260052955000540055555000460060999900380065500100070069320171128140014.0 a20170831afrey50 ba0 bTESS aAménagement du territoire 31921565ga1 - CADRE ET MILIEU DE VIE 31856115haDéveloppement local 31861065haEquipement collectif 31861135haMilieu rural 31906215haAménagement foncier 31887235haDéveloppement régional 31911715haCoopération territoriale 31885705haZone touristique 31872935haZone d'aménagement du territoire 31909415haPôle de compétitivité 31854275haZone d'entreprises 31905315haOuvrage d'art 31889315haTerritoire 31853835haPolitique d'aménagement du territoire 31900005haCoopération transfrontalière 9tess:TESS/AMENAGEMENTDUTERRITOIRE18534900339 a2200133 450000500170000010000290001715200090004625000230005555000310007855000300010955000300013999900290016900100070019820171128140013.0 a20170831afrey50 ba0 bTESS aSystème de santé 31853865gaSanté publique 3185351aAssurance maladie 3185351aAssurance maladie 9tess:TESS/SYSTEMEDESANTE18535000408 a2200157 450000500170000010000290001715200090004625000220005555000330007755000190011055000210012955000310015055000310018199900310021200100070024320171128140004.0 a20170831afrey50 ba0 bTESS aAssurance maladie 31877265gaAssurance sociale 31885535haCMU 31888975haCMU-C 3185350aSystème de santé 3185350aSystème de santé 9tess:TESS/ASSURANCEMALADIE18535100229 a2200109 450000500170000010000290001715200090004625000100005555000270006599900200009200100070011220171128140024.0 a20170831afrey50 ba0 bTESS aBilan 31922585gaMots-outils 9tess:TESS/BILAN18535200234 a2200109 450000500170000010000290001715200090004625000130005555000270006899900220009500100070011720171128140027.0 a20170831afrey50 ba0 bTESS aRéforme 31922585gaMots-outils 9tess:TESS/REFORME18535300462 a2200157 450000500170000010000290001715200090004625000090005545000390006445000560010345000560015945000270021555000360024299900190027800100070029720171128140039.0 a20170831afrey50 ba0 bTESS aPLIE aPlan local d'insertion économique aPlan local pluriannuel pour l'insertion et l'emploi aPlan local pluriannuel pour l'insertion et l'emploi 3778899aReject with id 31868085gaMesure pour l'emploi 9tess:TESS/PLIE19251600177 a2200085 450000100070000000500170000725000290002410000290005315200090008219114520171123192627.0 aCodeaSécurité sociale a20171123afrey50 ba0 bTESS \ No newline at end of file diff --git a/tests/library/Class/ModelTestCase.php b/tests/library/Class/ModelTestCase.php index 6f996ab370f2f9940d46132dda769c6b70160792..e95f85b7703f0a2ab3b7cdc576ac10071dec57aa 100644 --- a/tests/library/Class/ModelTestCase.php +++ b/tests/library/Class/ModelTestCase.php @@ -63,6 +63,7 @@ abstract class ModelTestCase extends Storm_Test_ModelTestCase { Storm_Model_Loader::defaultToVolatile(); Class_Versions::defaultToVolatile(); } + Storm_Cache::setDefaultZendCache(null); $this->_registry_sql = Zend_Registry::get('sql'); Class_Url::setBaseUrl('/bokeh'); diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php index 5067b0bfd40c70d2d6be3cd96ebe92c9a06a46a2..c210f1fec9325f48493c6412377a3c1e479f4a5a 100644 --- a/tests/library/Class/MoteurRechercheTest.php +++ b/tests/library/Class/MoteurRechercheTest.php @@ -77,7 +77,7 @@ abstract class MoteurRechercheTestCase extends ModelTestCase { protected function listSqlWith($where, $order=null) { - return sprintf('select id_notice, facettes from notices Where %s%s', + return sprintf('select id_notice, facettes from notices Where (%s) and type=1%s', $where, $order ? ' order by ' . $order : ''); } } @@ -249,40 +249,45 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { return [ [['expressionRecherche' => 'Bakounine'], 'nb_mots' => 1, - 'req_liste' => "select id_notice, facettes from notices Where ". $match_axes ." AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' BAKOUNINE') * 1.5) + (MATCH(auteurs) AGAINST(' BAKOUNINE')) desc"], + 'req_liste' => $this->listSqlWith($match_axes ." AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' BAKOUNINE') * 1.5) + (MATCH(auteurs) AGAINST(' BAKOUNINE')) desc")], [['expressionRecherche' => 'Slavoj Zizek', 'tri' => 'alpha_titre'] , 'nb_mots' => 2, - 'req_liste' => "select id_notice, facettes from notices Where " . $match_axes . " AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE) order by alpha_titre"], + 'req_liste' => $this->listSqlWith($match_axes . " AGAINST('+(SLAVOJ SLAVOJS SLAVOJ) +(ZIZEK ZIZEKS ZIZEK)' IN BOOLEAN MODE)", + 'alpha_titre')], [['expressionRecherche' => 'La commune de Paris', 'annexe' => 'MED1', 'selection_annexe' => 'TUN;TAP', 'tri' => 'alpha_titre'] , 'nb_mots' => 2, - 'req_liste' => "select id_notice, facettes from notices Where " . $match_axes . " AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE) order by alpha_titre"], + 'req_liste' => $this->listSqlWith($match_axes . " AGAINST('+(COMMUNE COMMUNES KOMUN) +(PARI PARIS PARI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +(YTUN YTAP)' IN BOOLEAN MODE)", + 'alpha_titre')], [['expressionRecherche' => '2-7427-3315-9', 'geo_zone' => 2, 'tri' => 'alpha_auteur'] , 'nb_mots'=> null, - 'req_liste' => "select id_notice, facettes from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE) order by alpha_auteur"], + 'req_liste' => $this->listSqlWith("(isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3 B4)' IN BOOLEAN MODE)", + "alpha_auteur")], [['expressionRecherche' => '2-7427-3315-9', 'geo_bib' => 3, 'tri' => 'alpha_auteur'] , 'nb_mots'=> null, - 'req_liste' => "select id_notice, facettes from notices Where (isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE) order by alpha_auteur"] , + 'req_liste' => $this->listSqlWith("(isbn='2-7427-3315-9' or isbn='978-2-7427-3315-6') and MATCH(facettes) AGAINST('+(B3)' IN BOOLEAN MODE)", + "alpha_auteur")], [['expressionRecherche' => '9782742761579'], 'nb_mots'=> null, - 'req_liste' => "select id_notice, facettes from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9')"], + 'req_liste' => $this->listSqlWith("(isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9')")], [['expressionRecherche' => '9782742761579', 'selection_bib'=> 1], 'nb_mots'=> null, - 'req_liste' => "select id_notice, facettes from notices Where (isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+(B1)' IN BOOLEAN MODE)"], + 'req_liste' => $this->listSqlWith("(isbn='2-7427-6157-8' or isbn='978-2-7427-6157-9') and MATCH(facettes) AGAINST('+(B1)' IN BOOLEAN MODE)")], [['expressionRecherche' => 'logo', 'annexe' => 'MED1', @@ -290,7 +295,8 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'selection_annexe' => 'TUN;TAP', 'selection_sections' => '1;12;9'], 'nb_mots'=> 1, - 'req_liste' => "select id_notice, facettes from notices Where " . $match_axes . " AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' LOGO') * 1.5) + (MATCH(auteurs) AGAINST(' LOGO')) desc"], + 'req_liste' => $this->listSqlWith($match_axes . " AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+YMED1 +M52291 +A15067 +(YTUN YTAP) +(S1 S12 S9)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' LOGO') * 1.5) + (MATCH(auteurs) AGAINST(' LOGO')) desc")], [['expressionRecherche' => 'security', 'annexe' => 'MED(")', @@ -301,35 +307,39 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { 'type_doc' => 'delete("*"),1,uraiets,2', 'selection_sections' => '1;goup<ip;9'], 'nb_mots'=> 1, - 'req_liste' => "select id_notice, facettes from notices Where " . $match_axes . " AGAINST('+(SECURITY SECURITYS SEKURITI)' IN BOOLEAN MODE) and type_doc in('1','2') and MATCH(facettes) AGAINST('+(Y8) +(S1 S9) +(E34) +(B12)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' SECURITY') * 1.5) + (MATCH(auteurs) AGAINST(' SECURITY')) desc"], + 'req_liste' => $this->listSqlWith($match_axes . " AGAINST('+(SECURITY SECURITYS SEKURITI)' IN BOOLEAN MODE) and type_doc in('1','2') and MATCH(facettes) AGAINST('+(Y8) +(S1 S9) +(E34) +(B12)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' SECURITY') * 1.5) + (MATCH(auteurs) AGAINST(' SECURITY')) desc")], [['expressionRecherche' => '', 'digital_lib' => '1'], 'nb_mots'=> 0, - 'req_liste' => "select id_notice, facettes from notices Where (type_doc in ('100','101','102','103','104','105','106','109','110','111','112','113','115','116','117','119','Assimil','Cvs','DiMusic','LaSourisQuiRaconte','Lekiosk','LesYeuxDoc','Musicme','Numel','Omeka','Skilleos','StoryPlayR','ToutApprendre'))"], + 'req_liste' => $this->listSqlWith("(type_doc in ('100','101','102','103','104','105','106','109','110','111','112','113','115','116','117','119','Assimil','Cvs','DiMusic','LaSourisQuiRaconte','Lekiosk','LesYeuxDoc','Musicme','Numel','Omeka','Skilleos','StoryPlayR','ToutApprendre'))")], [['expressionRecherche' => 'logo', 'digital_lib' => '1'], 'nb_mots'=> 1, - 'req_liste' => "select id_notice, facettes from notices Where " . $match_axes . " AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and (type_doc in ('100','101','102','103','104','105','106','109','110','111','112','113','115','116','117','119','Assimil','Cvs','DiMusic','LaSourisQuiRaconte','Lekiosk','LesYeuxDoc','Musicme','Numel','Omeka','Skilleos','StoryPlayR','ToutApprendre')) order by (MATCH(titres) AGAINST(' LOGO') * 1.5) + (MATCH(auteurs) AGAINST(' LOGO')) desc"], + 'req_liste' => $this->listSqlWith($match_axes . " AGAINST('+(LOGO LOGOS LOGO)' IN BOOLEAN MODE) and (type_doc in ('100','101','102','103','104','105','106','109','110','111','112','113','115','116','117','119','Assimil','Cvs','DiMusic','LaSourisQuiRaconte','Lekiosk','LesYeuxDoc','Musicme','Numel','Omeka','Skilleos','StoryPlayR','ToutApprendre'))", + "(MATCH(titres) AGAINST(' LOGO') * 1.5) + (MATCH(auteurs) AGAINST(' LOGO')) desc")], [['expressionRecherche' => '', 'id_panier' => 4], 'nb_mots'=> 0, - 'req_liste' => "select id_notice, facettes from notices Where notices.clef_alpha in('BATMAN', 'STARWARS', 'INDIANAJONES', 'SPIDERMAN') order by FIELD(notices.clef_alpha, 'BATMAN', 'STARWARS', 'INDIANAJONES', 'SPIDERMAN')"], + 'req_liste' => $this->listSqlWith("notices.clef_alpha in('BATMAN', 'STARWARS', 'INDIANAJONES', 'SPIDERMAN')", + "FIELD(notices.clef_alpha, 'BATMAN', 'STARWARS', 'INDIANAJONES', 'SPIDERMAN')")], [['expressionRecherche' => '', 'tri' => 'alpha_auteur', 'id_panier' => 4], 'nb_mots'=> 0, - 'req_liste' => "select id_notice, facettes from notices Where notices.clef_alpha in('BATMAN', 'STARWARS', 'INDIANAJONES', 'SPIDERMAN') order by alpha_auteur"], + 'req_liste' => $this->listSqlWith("notices.clef_alpha in('BATMAN', 'STARWARS', 'INDIANAJONES', 'SPIDERMAN')", + "alpha_auteur")], // see http://forge.afi-sa.fr/issues/46007 [['filtres' => 'T1;-HFOND0003*;'], 'nb_mots'=> 0, - 'req_liste' => 'select id_notice, facettes from notices Where MATCH(facettes) AGAINST(\'+(T1) +(HFOND0003*)\' IN BOOLEAN MODE)'] + 'req_liste' => $this->listSqlWith('MATCH(facettes) AGAINST(\'+(T1) +(HFOND0003*)\' IN BOOLEAN MODE)')] ]; } @@ -377,7 +387,8 @@ class MoteurRechercheSimpleWithOtherIndexFieldsTest extends MoteurRechercheSimpl return [ [['expressionRecherche' => 'Bakounine'], 'nb_mots' => 1, - 'req_liste' => "select id_notice, facettes from notices Where ". $match_axes ." AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' BAKOUNINE') * 1.5) + (MATCH(auteurs) AGAINST(' BAKOUNINE')) desc"], + 'req_liste' => $this->listSqlWith($match_axes ." AGAINST('+(BAKOUNINE BAKOUNINES BAKOUNIN)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' BAKOUNINE') * 1.5) + (MATCH(auteurs) AGAINST(' BAKOUNINE')) desc")], ]; } } @@ -391,7 +402,8 @@ class MoteurRechercheSerieTest extends MoteurRechercheTestCase { [['expressionRecherche' => 'Geo', 'serie'=> 'GEO', 'tri' => 'date_creation desc'], - 'req_liste' => 'select id_notice, facettes from notices Where clef_chapeau="GEO" order by cast(tome_alpha as SIGNED INTEGER) desc']]; + 'req_liste' => $this->listSqlWith('clef_chapeau="GEO" ', + 'cast(tome_alpha as SIGNED INTEGER) desc')]]; } @@ -750,19 +762,23 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheTestCase { [ [['id_catalogue' => 89], "select libelle from codif_dewey where id_dewey='3'", - "select id_notice, facettes from notices Where date_creation >'2012-05-03' and MATCH(facettes) AGAINST('+(YANNECY YSEYNOD) +(HNANA0001 HNANA0002)' IN BOOLEAN MODE) order by annee desc"], + $this->listSqlWith("(date_creation >'2012-05-03' and MATCH(facettes) AGAINST('+(YANNECY YSEYNOD) +(HNANA0001 HNANA0002)' IN BOOLEAN MODE)) and type=1", + "annee desc")], [['id_catalogue' => 88], "select libelle from codif_dewey where id_dewey='3'", - "select id_notice, facettes from notices Where date_creation >'2012-05-03' and MATCH(facettes) AGAINST('+(T1 T4)' IN BOOLEAN MODE) order by annee desc"], + $this->listSqlWith("(date_creation >'2012-05-03' and MATCH(facettes) AGAINST('+(T1 T4)' IN BOOLEAN MODE)) and type=1", + "annee desc")], [['id_catalogue' => 99], "select libelle from codif_dewey where id_dewey='3'", - "select id_notice, facettes from notices Where cote >='N222.77' and cote <= 'V222.77' and annee >='1997' order by annee desc"], + $this->listSqlWith("( cote >='N222.77' and cote <= 'V222.77' and annee >='1997') and type=1", + "annee desc")], [['id_catalogue' => 101], '', - "select id_notice, facettes from notices Where MATCH(facettes) AGAINST('+(T1) +(HFOND0003*)' IN BOOLEAN MODE) order by annee desc"] + $this->listSqlWith("(MATCH(facettes) AGAINST('+(T1) +(HFOND0003*)' IN BOOLEAN MODE)) and type=1", + "annee desc")] ]; } @@ -795,7 +811,10 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheTestCase { $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where (date_creation >'2012-05-03' and MATCH(facettes) AGAINST('+(YANNECY YSEYNOD) +(HNANA0001 HNANA0002)' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST('+(HNANA0001 HNANA0002) +(F565)' IN BOOLEAN MODE) order by annee desc", true, false) + ->with($this->listSqlWith("(date_creation >'2012-05-03' and MATCH(facettes) AGAINST('+(YANNECY YSEYNOD) +(HNANA0001 HNANA0002)' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST('+(HNANA0001 HNANA0002) +(F565)' IN BOOLEAN MODE)) and type=1", + "annee desc"), + true, + false) ->answers([ [1, ''] ]) @@ -821,7 +840,10 @@ class MoteurRecherchePhonetixCollisionTest extends MoteurRechercheTestCase { public function shouldNotUsePhonetix() { $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(JEAN JEANS) +(GENET GENETS) +(PARCOUR PARCOURS PARKOUR)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' JEAN GENET PARCOURS') * 1.5) + (MATCH(auteurs) AGAINST(' JEAN GENET PARCOURS')) desc", true, false) + ->with($this->listSqlWith("MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(JEAN JEANS) +(GENET GENETS) +(PARCOUR PARCOURS PARKOUR)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' JEAN GENET PARCOURS') * 1.5) + (MATCH(auteurs) AGAINST(' JEAN GENET PARCOURS')) desc"), + true, + false) ->answers( [ [1, ''] ] ) @@ -872,7 +894,10 @@ class MoteurRechercheWithCatalogueTest extends MoteurRechercheWithCatalogueTestC $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where (MATCH(facettes) AGAINST('Q5' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST('+(Y2 Y4 Y1)' IN BOOLEAN MODE) order by annee desc", true, false) + ->with($this->listSqlWith("(MATCH(facettes) AGAINST('Q5' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST('+(Y2 Y4 Y1)' IN BOOLEAN MODE)) and type=1", + "annee desc"), + true, + false) ->answers( [ [1, ''] ] ) @@ -882,7 +907,7 @@ class MoteurRechercheWithCatalogueTest extends MoteurRechercheWithCatalogueTestC $this->request = (new Class_MoteurRecherche())->lancerRecherche($criteres_recherche); - $this->assertEquals('select id_notice, facettes from notices Where (MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+(Y2 Y4 Y1)\' IN BOOLEAN MODE) order by annee desc', + $this->assertEquals('select id_notice, facettes from notices Where ((MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST(\'+(Y2 Y4 Y1)\' IN BOOLEAN MODE)) and type=1) and type=1 order by annee desc', $this->request->getRecordsQuery()); } } @@ -911,7 +936,8 @@ class MoteurRechercheWithCatalogueAndParamsTest extends MoteurRechercheWithCatal /** @test */ public function requestShouldUseProfilSettings() { - $query = 'select id_notice, facettes from notices Where ((date_creation >\'2014-12-23\' and MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+P4* +(Y2 Y4 Y1)\' IN BOOLEAN MODE) order by date_creation desc'; + $query = $this->listSqlWith('((date_creation >\'2014-12-23\' and MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST(\'+P4* +(Y2 Y4 Y1)\' IN BOOLEAN MODE)) and type=1', + 'date_creation desc'); $this->mock_sql ->whenCalled('fetchAll') @@ -959,7 +985,8 @@ class MoteurRechercheWithCatalogueAndUrlParamsTest extends MoteurRechercheWithCa 'facettes' =>'T1-T10', 'facette' => 'T5']); - $query = 'select id_notice, facettes from notices Where ((MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+T1 +T10 +T5\' IN BOOLEAN MODE) order by annee desc'; + $query = $this->listSqlWith('((MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST(\'+T1 +T10 +T5\' IN BOOLEAN MODE)) and type=1', + 'annee desc'); $this->mock_sql ->whenCalled('fetchAll') @@ -1005,7 +1032,8 @@ class MoteurRechercheWithCatalogueWithNoSettingsAndUrlParamsTest extends MoteurR (new Class_CriteresRecherche())->setParams(['id_catalogue' => 5, 'facettes' =>'T4-T8']); - $query = 'select id_notice, facettes from notices Where (MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+T4 +T8\' IN BOOLEAN MODE) order by annee desc'; + $query = $this->listSqlWith('(MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST(\'+T4 +T8\' IN BOOLEAN MODE)) and type=1', + 'annee desc'); $this->mock_sql ->whenCalled('fetchAll') @@ -1043,11 +1071,17 @@ class MoteurRechercheExtendingTest extends MoteurRechercheTestCase { public function withoutResultShouldExtend() { $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(VIE VIES) +(GEEK GEEKS JEK)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc", true, false) + ->with($this->listSqlWith("MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(VIE VIES) +(GEEK GEEKS JEK)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc"), + true, + false) ->answers([]) ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST(' (VIE VIES) (GEEK GEEKS JEK)') order by (MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc", true, false) + ->with($this->listSqlWith("MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST(' (VIE VIES) (GEEK GEEKS JEK)')", + "(MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc"), + true, + false) ->answers([ [ 1, '' @@ -1069,10 +1103,11 @@ class MoteurRechercheExtendingTest extends MoteurRechercheTestCase { public function withoutResultWithNoExtensionParamShouldNotExtend() { $this->mock_sql ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(VIE VIES) +(GEEK GEEKS JEK)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc", true, false) - ->answers([ - [1, ''] - ]) + ->with($this->listSqlWith("MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(VIE VIES) +(GEEK GEEKS JEK)' IN BOOLEAN MODE)", + "(MATCH(titres) AGAINST(' VIE GEEKS') * 1.5) + (MATCH(auteurs) AGAINST(' VIE GEEKS')) desc"), + true, + false) + ->answers([]) ->beStrict(); $criteria = (new Class_CriteresRecherche()) @@ -1080,7 +1115,6 @@ class MoteurRechercheExtendingTest extends MoteurRechercheTestCase { 'no_extension' => '1']); $result = $this->_engine->lancerRecherche($criteria); - - $this->assertEquals(1, $result->getRecordsCount()); + $this->assertEquals(0, $result->getRecordsCount()); } } \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php index 27a7021350a6b2e76df6e0f16c6a010b22f504ed..bd54aabe197f1df2f53ffb2ed171ada7593669ed 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php @@ -298,11 +298,11 @@ abstract class ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase extends ZendA $this->mock_sql ->whenCalled('fetchOne') - ->with("select count(*) from notices where notices.clef_alpha in('BB') and url_vignette > '' and url_vignette != 'NO' ") + ->with("select count(*) from notices where notices.clef_alpha in('BB') and url_vignette > '' and url_vignette != 'NO' and type=1 ") ->answers(10) ->whenCalled('fetchAllByColumn') - ->with("select notices.id_notice from notices where notices.clef_alpha in('BB') and url_vignette > '' and url_vignette != 'NO' order by date_creation DESC LIMIT 0,50") + ->with("select notices.id_notice from notices where notices.clef_alpha in('BB') and url_vignette > '' and url_vignette != 'NO' and type=1 order by date_creation DESC LIMIT 0,50") ->answers([2, 45]) ->beStrict(); @@ -637,7 +637,7 @@ class ZendAfi_View_Helper_Accueil_KiosqueWithLinkedRecordsInDomainSetTest extend /** @test */ public function requestShouldBeAsExpected() { - $this->assertEquals('select id_notice from notices Where MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE) order by date_creation DESC LIMIT 0,50', $this->_request['req_liste']); + $this->assertEquals('select id_notice from notices Where (MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and type=1 order by date_creation DESC LIMIT 0,50', $this->_request['req_liste']); } } diff --git a/tests/scenarios/SearchResult/SearchResultTest.php b/tests/scenarios/SearchResult/SearchResultTest.php index dfd368961f7db30b003e4a4afcfa708a1ade5fac..007fe253fc6cf59b965e5fe8a1ffdfbe5665d41d 100644 --- a/tests/scenarios/SearchResult/SearchResultTest.php +++ b/tests/scenarios/SearchResult/SearchResultTest.php @@ -125,7 +125,7 @@ class SearhResultFilterDomainsFromProfilTest extends AbstractControllerTestCase $sql = $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(TROLL TROLLS TROL) +(TROY TROYS TROI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+(T2) +(HCCCC0001 HCCCC0002)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' TROLLS TROY') * 1.5) + (MATCH(auteurs) AGAINST(' TROLLS TROY')) desc", true, false) + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(TROLL TROLLS TROL) +(TROY TROYS TROI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+(T2) +(HCCCC0001 HCCCC0002)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' TROLLS TROY') * 1.5) + (MATCH(auteurs) AGAINST(' TROLLS TROY')) desc", true, false) ->answers([ ['1' , 'T1 T2']]) ->beStrict(); @@ -156,7 +156,7 @@ class SearchResultFilterFromProfilTest extends AbstractControllerTestCase { $sql = $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(TROLL TROLLS TROL) +(TROY TROYS TROI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+(T2)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' TROLLS TROY') * 1.5) + (MATCH(auteurs) AGAINST(' TROLLS TROY')) desc", true, false) + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(TROLL TROLLS TROL) +(TROY TROYS TROI)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+(T2)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' TROLLS TROY') * 1.5) + (MATCH(auteurs) AGAINST(' TROLLS TROY')) desc", true, false) ->answers([ ['1' , 'T1 T2']]); Zend_Registry::set('sql', $sql); @@ -213,7 +213,7 @@ class SearchResultFilterFromProfilOnDomainTest extends AbstractControllerTestCas $sql = $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where (date_creation >'2017-04-13' and MATCH(facettes) AGAINST('+(B1) +(E36 E112) +(HNNNN0001)' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST('+(T2) +(B1)' IN BOOLEAN MODE) order by annee desc", true, false) + ->with("select id_notice, facettes from notices Where ((date_creation >'2017-04-13' and MATCH(facettes) AGAINST('+(B1) +(E36 E112) +(HNNNN0001)' IN BOOLEAN MODE)) and (MATCH(facettes) AGAINST('+(T2) +(B1)' IN BOOLEAN MODE)) and type=1) and type=1 order by annee desc", true, false) ->answers([ [1, 'T1 T2 B1 HNNNN0001 E36 A332'] ]) ->beStrict(); diff --git a/tests/scenarios/SearchSelection/SearchSelectionTest.php b/tests/scenarios/SearchSelection/SearchSelectionTest.php index d6300bea092a3ec04989d05366a5f56521fdda3f..b3e8038cb0c1ee5363d25371066e4567fe81af5b 100644 --- a/tests/scenarios/SearchSelection/SearchSelectionTest.php +++ b/tests/scenarios/SearchSelection/SearchSelectionTest.php @@ -308,7 +308,7 @@ class SearchSelectionSelectPageTest extends SearchSelectionTestCase { 'recherche', 'resultat', 'simple'); - + $this->dispatch('/records/select-page/expressionRecherche/pomme/facettes/T3/page/1', true); sort(Zend_Registry::get('session')->search_record_selection); @@ -341,7 +341,7 @@ class SearchSelectionSelectViewWithSelectionTest extends SearchSelectionTestCase Zend_Registry::get('session')->search_record_selection = [8, 10]; $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices Where id_notice in (8,10)', + ->with('select id_notice, facettes from notices Where (id_notice in (8,10)) and type=1', true, false) ->answers([ [8, ''], [10, '']]) ->beStrict(); @@ -599,7 +599,7 @@ class SearchSelectionPrintWithSelectionTest extends SearchSelectionTestCase { Zend_Registry::get('session')->search_record_selection = [8, 10]; $this->mock_sql ->whenCalled('fetchAll') - ->with('select id_notice, facettes from notices Where id_notice in (8,10)', + ->with('select id_notice, facettes from notices Where (id_notice in (8,10)) and type=1', true, false) ->answers([ [8, ''], [10, '']]) ->beStrict(); diff --git a/tests/scenarios/bookmarks/SearchTest.php b/tests/scenarios/bookmarks/SearchTest.php index 9eecbab0c65689113a9340a5479c08cef90f125a..f35445656f4fec090513f5b8c4acb7245bd96a6c 100644 --- a/tests/scenarios/bookmarks/SearchTest.php +++ b/tests/scenarios/bookmarks/SearchTest.php @@ -497,7 +497,7 @@ class Bookmarks_SearchCosmogrammePhaseTest Zend_Registry::set('sql', $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE) order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) ->answers($result) ->beStrict()); @@ -657,7 +657,7 @@ class Bookmarks_SearchDiffLoggedTest extends AbstractControllerTestCase { Zend_Registry::set('sql', $this->mock() ->whenCalled('fetchAll') - ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE) and clef_alpha in ('DROITDEVANT--ODAEIICHIRO-15-GLENAT-2013-1') order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) + ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(HARRY HARRYS ARI) +(POTTER POTTERS POT)' IN BOOLEAN MODE) and clef_alpha in ('DROITDEVANT--ODAEIICHIRO-15-GLENAT-2013-1')) and type=1 order by (MATCH(titres) AGAINST(' HARRY POTTER') * 1.5) + (MATCH(auteurs) AGAINST(' HARRY POTTER')) desc", true, false) ->answers([[1888, '']]) ->beStrict());