Newer
Older
<?php
/**
* Copyright (c) 2012-2022, 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__ . '/DynamicFacetOnDomainsFixture.php');
abstract class DynamicFacetOnDomainsPhaseTestCase
extends Class_Cosmogramme_Integration_PhaseTestCase {
protected function _getPreviousPhase() {
return (new Class_Cosmogramme_Integration_Phase(7.1))->beCron();
}

Patrick Barroca
committed
public function setUp() {
parent::setUp();
Class_Cosmogramme_Integration_Around_Before::reset();
$this->onLoaderOfModel(Class_Notice::class)
->whenCalled('dropIndexMotsNotice')
->willDo(function() {});

Patrick Barroca
committed
$this->_phase = $this->_buildPhase('DynamicFacetsOnDomainIndex')
->setMemoryCleaner(function() {})
->setPrinter($this->_printer)
->run();
}
/** @test */
public function logShouldNotContainsError() {
$this->assertNotError();
}
}
class DynamicFacetOnDomainsPhaseEnabledTest extends DynamicFacetOnDomainsPhaseTestCase {
protected array $_storm_scopes = ['Class_Cosmogramme_Integration_PhaseDynamicFacetsOnDomainIndex'];
protected function _prepareFixtures() {
parent::_prepareFixtures();
Class_AdminVar::set('ENABLE_FACETS_ON_DOMAINS', true);

Patrick Barroca
committed
(new DynamicFacetOnDomainsFixture)
->buildCodifications()
->buildDomains()
->buildThesaurus()
->buildRecords();
}
/** @test */
public function logShouldContainsIndexationDesFacettesSurDomaines() {

Patrick Barroca
committed
$this->assertLogContains('Indexation des facettes sur les domaines');
}
/** @test */
public function logShouldContainsTraitementThesaurusAnimaux() {

Patrick Barroca
committed
$this->assertLogContains('Traitement du thesaurus : Animaux');
}
/** @test */
public function logShouldContainsIndexationDomaineAnimaux() {

Patrick Barroca
committed
$this->assertLogContains('Indexation des notices du domaine : De la ferme');
}
/** @test */
public function logShouldContainsUneNoticeIndexée() {

Patrick Barroca
committed
$this->assertLogContains('1 notice(s) indexée(s)');
}
/** @test */
public function logShouldContainsTraitementDeleteFacetANIMinNotice() {

Patrick Barroca
committed
$this->assertLogContains('Suppression de la facette ANIM dans 1 notice(s)');
public function logShouldContainsTraitementDeleteFacetAllIdANIM() {
$this->assertLogContains('Suppression de toutes les facettes enfants sous : ANIM-Animaux');
}
/** @test */
public function recordOneFacetsShouldBeT1_A1_M1_HANIM0001() {
Class_Notice::clearCache();
$this->assertEquals('F_T1 F_A1 F_M1 F_HANIM0001', Class_Notice::find(1)->getFacets());
$this->assertEquals('T1 A1 M1 HANIM0001', Class_Notice::find(1)->getFacettes());
}
/** @test */
public function recordTwoFacetsShouldBeT1_A2_M2_HANIM0002() {
Class_Notice::clearCache();
$this->assertEquals('F_T1 F_A2 F_M2 F_HANIM0002', Class_Notice::find(2)->getFacets());
$this->assertEquals('T1 A2 M2 HANIM0002', Class_Notice::find(2)->getFacettes());
}
/** @test */
public function recordOiseauxShouldLostDynamicFacetHANIM0001() {
Class_Notice::clearCache();
$this->assertEquals('F_T1 F_A3', Class_Notice::find(3)->getFacets());
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
$this->assertEquals('T1 A3', Class_Notice::find(3)->getFacettes());
}
/** @test */
public function thesaurusANIM0002ShouldHaveIdOrigine22() {
$this->assertEquals('22', Class_CodifThesaurus::findFirstBy(['id_thesaurus' => 'ANIM0002'])->getIdOrigine());
}
/** @test */
public function thesaurusANIM0002ShouldHaveCodeDomain() {
$this->assertEquals(Class_CodifThesaurusFixed::CODE_DOMAIN_FACET,
Class_CodifThesaurus::findFirstBy(['id_thesaurus' => 'ANIM0002'])->getCode());
}
/** @test */
public function thesaurusANIM0002ShouldHaveLibelleDeCompagnie() {
$this->assertEquals('De compagnie',
Class_CodifThesaurus::findFirstBy(['id_thesaurus' => 'ANIM0002'])->getLibelle());
}
/** @test */
public function thesaurusANIM0002ShouldHaveLibelleFacetteDeCompagnie() {
$this->assertEquals('De compagnie',
Class_CodifThesaurus::findFirstBy(['id_thesaurus' => 'ANIM0002'])->getLibelleFacette());
}
/** @test */
public function thesaurusANIM00003ShouldBeDeleted() {
$this->assertNull(Class_CodifThesaurus::find(3));
}
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/** @test */
public function allSqlUpdatesShouldBePresent() {
$this->assertSqlEquals(["SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'DOMAIN' AND `codif_thesaurus`.`rules` > '')",
"UPDATE `notices` SET `facettes` = CLEAN_SPACES(REGEXP_REPLACE(`facettes`, '\\\\bHANIM[a-zA-Z0-9]*\\\\b', '')), `facets` = CLEAN_SPACES(REGEXP_REPLACE(`facets`, '\\\\bF_HANIM[a-zA-Z0-9]*\\\\b', '')) WHERE (MATCH(`notices`.`facets`) AGAINST('F_HANIM*' IN BOOLEAN MODE))",
"DELETE FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`id_thesaurus` LIKE 'ANIM%' AND `codif_thesaurus`.`rules` IS null AND `codif_thesaurus`.`id_origine` NOT IN ('21', '22'))",
"SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'DOMAIN' AND `codif_thesaurus`.`id_thesaurus` LIKE 'ANIM%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1",
"SELECT `codif_matiere`.* FROM `codif_matiere` WHERE (`codif_matiere`.`libelle` LIKE 'Animaux de la ferme : %')",
"UPDATE `notices` SET `facettes` = CONCAT(`facettes`, ' HANIM0001'), `facets` = CONCAT(`facets`, ' F_HANIM0001') WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_M1' IN BOOLEAN MODE) AND `notices`.`type` = 1)",
"SELECT `codif_matiere`.* FROM `codif_matiere` WHERE (`codif_matiere`.`libelle` LIKE 'Animaux de compagnie : %')",
"UPDATE `notices` SET `facettes` = CONCAT(`facettes`, ' HANIM0002'), `facets` = CONCAT(`facets`, ' F_HANIM0002') WHERE (MATCH(`notices`.`titres`, `notices`.`auteurs`, `notices`.`editeur`, `notices`.`collection`, `notices`.`matieres`, `notices`.`dewey`, `notices`.`other_terms`, `notices`.`facets`) AGAINST('+F_M2' IN BOOLEAN MODE) AND `notices`.`type` = 1)",
"UPDATE `notices` SET `facettes` = CLEAN_SPACES(REGEXP_REPLACE(`facettes`, '\\\\bHSUPP[a-zA-Z0-9]*\\\\b', '')), `facets` = CLEAN_SPACES(REGEXP_REPLACE(`facets`, '\\\\bF_HSUPP[a-zA-Z0-9]*\\\\b', '')) WHERE (MATCH(`notices`.`facets`) AGAINST('F_HSUPP*' IN BOOLEAN MODE))",
"DELETE FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`id_thesaurus` LIKE 'SUPP%' AND `codif_thesaurus`.`rules` IS null AND `codif_thesaurus`.`id_origine` NOT IN (3, 2, 4))",
"SELECT `codif_thesaurus`.* FROM `codif_thesaurus` WHERE (`codif_thesaurus`.`code` = 'DOMAIN' AND `codif_thesaurus`.`id_thesaurus` LIKE 'SUPP%') ORDER BY `codif_thesaurus`.`id_thesaurus` DESC LIMIT 1"]);
}
class DynamicFacetOnDomainsPhaseDisabledTest extends DynamicFacetOnDomainsPhaseTestCase {
public function prepareFixtures() {
parent::_prepareFixtures();
Class_AdminVar::set('ENABLE_FACETS_ON_DOMAINS', false);
}
/** @test */

Patrick Barroca
committed
public function logShouldContainsIndexationDesFacettesSurDomaines() {
$this->assertLogContains('Indexation des facettes sur les domaines');
}
/** @test */
public function logShouldContainsDynamicFacetOnDomainsDisabled() {
$this->assertLogContains('Les facettes dynamiques sur les domaines ne sont pas activées');
class DynamicFacetOnDomainsPhaseWithCustomFormTest extends DynamicFacetOnDomainsPhaseTestCase {
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
protected function _prepareFixtures() {
parent::_prepareFixtures();
Class_AdminVar::set('ENABLE_FACETS_ON_DOMAINS', 1);
Class_AdminVar::set('CUSTOM_DOMAIN_FORM', 1);
Class_AdminVar::set('CUSTOM_SEARCH_FORM', 1);
$this->fixture(Class_SearchForm::class,
['id' => 2,
'label' => 'My super form',
'filename' => __DIR__ . '/my_super.php']);
$custom_values = ['type_doc' => 'testing'];
$this->fixture(Class_Catalogue::class,
['id' => 6,
'libelle' => 'Adultes',
'description' => 'Mon catalogue',
'oai_spec' => 'adultes',
'type_doc' => '1;3;4;5',
'annee_debut' => 2012,
'annee_fin' => 2012,
'annexe' => 0,
'dewey' => 78308,
'sous_domaines' => [],
'bibliotheque' => 1,
'paniers' => [],
'custom_form_id' => 2,
'custom_form_values' => json_encode($custom_values)]);
$this->fixture(Class_CodifThesaurus::class,
['id' => 1,
'code' => Class_CodifThesaurusFixed::CODE_DOMAIN_FACET,
'id_thesaurus' => 'ANIM',
'libelle' => 'Animaux',
'libelle_facette' => 'Les animaux',
'rule_list_domain_id' => ['6']
]);
}
/** @test */
public function logShouldContainsIndexationDomaineAdultes() {
$this->assertLogContains('Indexation des notices du domaine : Adultes');
}
}