CodifThesaurusTest.php 7.48 KB
Newer Older
Patrick Barroca's avatar
Patrick Barroca committed
1
<?php
efalcy's avatar
efalcy committed
2 3 4
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
5
 * BOKEH is free software; you can redistribute it and/or modify
efalcy's avatar
efalcy committed
6 7 8 9 10 11
 * 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).
 *
Laurent's avatar
Laurent committed
12
 * BOKEH is distributed in the hope that it will be useful,
efalcy's avatar
efalcy committed
13 14 15 16 17
 * 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
Laurent's avatar
Laurent committed
18
 * along with BOKEH; if not, write to the Free Software
Laurent's avatar
Laurent committed
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
efalcy's avatar
efalcy committed
20 21
 */

22 23 24
class CodifThesaurusCommonTest extends ModelTestCase {
  protected $_storm_default_to_volatile = true;

Patrick Barroca's avatar
Patrick Barroca committed
25 26
  public function setUp() {
    parent::setUp();
27

28 29 30 31 32 33
    $this->onLoaderOfModel('Class_CodifThesaurus')
         ->whenCalled('findFirstBy')
         ->with(['code' => 'catalogue',
                 'where' => 'id_thesaurus like "CCCC0001%"',
                 'order' => 'id_thesaurus desc'])
         ->answers(Class_CodifThesaurus::newInstanceWithId(60,['id_thesaurus'=>'CCCC00010022']))
Patrick Barroca's avatar
Patrick Barroca committed
34
      ;
35

Patrick Barroca's avatar
Patrick Barroca committed
36
  }
37 38


Patrick Barroca's avatar
Patrick Barroca committed
39 40
  /** @test */
  public function findNextThesaurusChildIdShouldReturnCCCC00010001() {
41 42
    $this->assertEquals('CCCC00010023',
                        Class_CodifThesaurus::findNextThesaurusChildId('catalogue','CCCC0001'));
Patrick Barroca's avatar
Patrick Barroca committed
43
  }
44 45


Patrick Barroca's avatar
Patrick Barroca committed
46 47
  /** @test */
  public function code01Sur4ChiffresShouldReturn0100() {
48
    $this->assertEquals('0100', Class_CodifThesaurus::getCodeSur4Chiffres('01'));
Laurent's avatar
Laurent committed
49

Patrick Barroca's avatar
Patrick Barroca committed
50
  }
efalcy's avatar
efalcy committed
51 52


Patrick Barroca's avatar
Patrick Barroca committed
53 54
  /** @test */
  public function codeASur4ChiffresShouldReturn0100() {
55
    $this->assertEquals('A000', Class_CodifThesaurus::getCodeSur4Chiffres('A'));
Laurent's avatar
Laurent committed
56

Patrick Barroca's avatar
Patrick Barroca committed
57
  }
efalcy's avatar
efalcy committed
58

59

Patrick Barroca's avatar
Patrick Barroca committed
60
  /** @test */
61 62
  public function incrementYYYY0999ShouldReturnYYYY099A() {
    $this->assertEquals('YYYY099A', Class_CodifThesaurus::incrementId('YYYY0999'));
Patrick Barroca's avatar
Patrick Barroca committed
63
  }
64 65


Patrick Barroca's avatar
Patrick Barroca committed
66 67
  /** @test */
  public function incrementYYYY00ZZShouldReturnYYYY0100() {
68 69 70 71 72 73 74
    $this->assertEquals('YYYY0100', Class_CodifThesaurus::incrementId('YYYY00ZZ'));
  }


  /** @test */
  public function incrementYYYY0009ShouldReturnYYYY000A() {
    $this->assertEquals('YYYY000A', Class_CodifThesaurus::incrementId('YYYY0009'));
Patrick Barroca's avatar
Patrick Barroca committed
75
  }
76

77

Patrick Barroca's avatar
Patrick Barroca committed
78 79
  /** @test */
  public function libelleHierarchiqueForCultureShouldBeConfGesticulee() {
80 81 82 83 84 85 86 87
    $this->onLoaderOfModel('Class_CodifThesaurus')
         ->whenCalled('findParent')
         ->with('THEM000100503000')
         ->answers(Class_CodifThesaurus::newInstanceWithId(70,['id_thesaurus'=>'THEM00010050'])->setLibelle('Spectacles'))

         ->whenCalled('findParent')
         ->with('THEM00010050')
         ->answers(Class_CodifThesaurus::newInstanceWithId(20,['id_thesaurus'=>'THEM0001'])->setLibelle('Culture'));
88

Laurent's avatar
Laurent committed
89 90


91 92
    $this->assertEquals('Culture : Spectacles : Conférences Gesticulées',
                        Class_CodifThesaurus::getLibelleHierarchique(Class_CodifThesaurus::newInstanceWithId(10,['id_thesaurus'=>'THEM000100503000'])->setLibelle('Conférences Gesticulées')));
Patrick Barroca's avatar
Patrick Barroca committed
93
  }
94

95

Patrick Barroca's avatar
Patrick Barroca committed
96 97 98 99 100 101
  /** @test */
  public function facetPublicShouldBeCreatedForNanook() {
    $this->fixture('Class_IntBib',
                   ['id' => 1,
                    'comm_sigb' => Class_IntBib::COM_NANOOK,
                    'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]);
102

Patrick Barroca's avatar
Patrick Barroca committed
103
    Class_CodifThesaurus::addFacetForSigb('Public' , '993$a',Class_IntBib::COM_NANOOK);
104

Patrick Barroca's avatar
Patrick Barroca committed
105 106
    $this->assertNotNull(Class_CodifThesaurus::findFirstBy(['libelle_facette' => 'Public']));
  }
107 108


Patrick Barroca's avatar
Patrick Barroca committed
109 110 111 112 113 114
  /** @test */
  public function facetPublicShouldNotBeCreatedForNanook() {
    $this->fixture('Class_IntBib',
                   ['id' => 1,
                    'comm_sigb' => Class_IntBib::COM_NANOOK,
                    'comm_params' => ['url_serveur' => 'http://bib.valensol.net']]);
115

Patrick Barroca's avatar
Patrick Barroca committed
116 117
    Class_CodifThesaurus::addFacetForSigb('Publique' , '993$a',Class_IntBib::COM_NANOOK);
    Class_CodifThesaurus::addFacetForSigb('Public' , '993$a',Class_IntBib::COM_NANOOK);
118

Patrick Barroca's avatar
Patrick Barroca committed
119 120
    $this->assertNull(Class_CodifThesaurus::findFirstBy(['libelle_facette' => 'Public']));
  }
efalcy's avatar
efalcy committed
121
}
122 123 124 125 126 127 128 129 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




class CodifThesaurusDeleteTest extends ModelTestCase {
  protected
    $_storm_default_to_volatile = true,
    $_record;

  public function setUp() {
    parent::setUp();

    $parent = $this->fixture('Class_CodifThesaurus',
                             ['id' => 1,
                              'id_thesaurus' => 'CFCF0001',
                              'libelle' => 'Parent']);

    $this->fixture('Class_CodifThesaurus',
                   ['id' => 2,
                    'id_thesaurus' => 'CFCF00010001',
                    'libelle' => 'Child']);

    $this->_record = $this->fixture('Class_Notice',
                                    ['id' => 12,
                                     'facettes' => 'T8 HCFCF00010001 A3452']);

    $parent->cleanRecords();
  }


  /** @test */
  public function recordShouldNotHaveFacetHCFCF() {
    $this->assertEquals('T8 A3452', $this->_record->getFacettes());
  }
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
}



class CodifThesaurusGetIndicesRootTest extends ModelTestCase {
  protected $_storm_default_to_volatile = true;


  public function setUp() {
    parent::setUp();
    $this->onLoaderOfModel('Class_CodifThesaurus')
         ->whenCalled('findAllBy')
         ->answers([]);
  }


  /** @test */
173 174
  public function shouldExcludeNoveltyAndDomains() {
    Class_CodifThesaurus::getIndices('root', false);
175
    $expected_params = ['where' => 'code not in ("Nouveauté par bibliothèque", "Nouveauté par annexe", "Catalogue") and LENGTH(id_thesaurus) in (1,4)',
176
                        'order' => 'id_thesaurus'];
177 178 179

    $this->assertEquals($expected_params,
                        Class_CodifThesaurus::getFirstAttributeForLastCallOn('findAllBy'));
180
  }
181 182 183


  /** @test */
184
  public function shouldExcludeNoveltyButNotDomain() {
185
    Class_CodifThesaurus::getIndices('root', true);
186
    $expected_params = ['where' => 'code not in ("Nouveauté par bibliothèque", "Nouveauté par annexe") and LENGTH(id_thesaurus) in (1,4)',
187 188 189
                        'order' => 'id_thesaurus'];
    $this->assertEquals($expected_params, Class_CodifThesaurus::getFirstAttributeForLastCallOn('findAllBy'));
  }
Patrick Barroca's avatar
Patrick Barroca committed
190 191 192 193 194
}




195 196 197 198 199 200 201 202 203 204 205 206 207 208
/** @see http://forge.afi-sa.fr/issues/50500 */
class CodifThesaurusTooManyValuesTest extends ModelTestCase {
  protected $_storm_default_to_volatile = true;

  public function setUp() {
    parent::setUp();

    $this->fixture('Class_CodifThesaurus',
                   ['id_thesaurus' => 'TEST',
                    'id_origine' => null,
                    'libelle' => 'test',
                    'code' => 'TEST',
                    'id' => 723,
                    'libelle_facette' => 'test',
209
                    'rules' => null]);
210 211

    $this->fixture('Class_CodifThesaurus',
212
                   ['id_thesaurus' => 'TESTZZZZ',
213 214 215 216 217 218 219 220 221
                    'id_origine' => 'RIME',
                    'libelle' => 'rime',
                    'code' => 'TEST',
                    'id' => 10722,
                    'libelle_facette' => 'rime',
                    'rules' => null]);
  }


222

223
  /** @test */
224
  public function shouldNotInsertMoreThanZZZZChild() {
Patrick Barroca's avatar
Patrick Barroca committed
225 226 227
    Class_CodifThesaurus::find(723)
      ->getOrCreateChild(strtoupper('métiers de la recherche'),
                         'métiers de la recherche');
228

Patrick Barroca's avatar
Patrick Barroca committed
229 230 231
    $this->assertEquals(2, Class_CodifThesaurus::count(),
                        Class_CodifThesaurus::findFirstBy(['order' => 'id desc'])
                        ->getIdThesaurus());
232
  }
Patrick Barroca's avatar
Patrick Barroca committed
233
}