Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software

Ghislain Loas
committed
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'AbstractControllerTestCase.php';
abstract class BibControllerWithZoneTestCase extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
unset($_REQUEST['geo_zone']);
$_SESSION['selection_bib'] = ['nb_notices' => 12345,
'id_bibs' => null];
$this->bib_annecy = Class_Bib::getLoader()
->newInstanceWithId(4)
->setIdZone(1)
->setLibelle('Annecy')
->setAffZone('')
->setVille('Annecy')
->setUrlWeb('http://www.annecy.fr')
->setMail('jp@annecy.com')
->setTelephone('04 50 51 32 12')
->setAdresse('1 rue Jean Jaures')
->setVisibilite(Class_Bib::V_DATA);
$this->haute_savoie = Class_Zone::getLoader()
->newInstanceWithId(1)
->setCouleurTexte('#059')
->setCouleurOmbre('#234')
->setTailleFonte('14')
->setImage('carte_moulins.jpg')
->setBibs(array($this->bib_annecy));
$ecrivez_des_tests = Class_Article::getLoader()
->newInstanceWithId(2)
->setIdSite(0)
->setTitre('Ecrivez des tests !')
->setContenu('Ça fera le plus grand bien')
->setCategorie(Class_ArticleCategorie::getLoader()
->newInstanceWithId(5)
->setLibelle('Bonnes pratiques'));

Ghislain Loas
committed
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
->whenCalled('getArticlesByPreferences')
->with(array('id_bib' => '4'))
->answers(array($ecrivez_des_tests))
->whenCalled('filterByLocaleAndWorkflow')
->with(array($ecrivez_des_tests))
->answers(array($ecrivez_des_tests));
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Zone')
->whenCalled('findAll')
->answers(array($this->haute_savoie));
}
}
class BibControllerZoneViewOneTest extends BibControllerWithZoneTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('bib/zoneview/id/1');
}
/** @test */
public function bibListShouldBeVisible() {

Ghislain Loas
committed
$this->assertXPathContentContains("//table//td[@class='listeTitre']",
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
156
157
158
159
160
161
162
163
164
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
"Bibliothèque");
}
/** @test */
public function actualitesShouldBeVisible() {
$this->assertXPathContentContains("//h2", "Actualités :");
}
/** @test */
public function bibAnnecyShouldBeVisible() {
$this->assertXPathContentContains("//table//td//a",
"Annecy");
}
/** @test */
public function bibAnnecyShouldBeVisibleOnMap() {
$this->assertXPathContentContains("//span[contains(@onclick, '/bib/bibview/id/4')]", "Annecy");
}
/** @test */
public function mapShouldBeVisible() {
$this->assertXPath("//div[@id='image_container']");
}
/** @test */
public function imageZoneShouldBeVisible() {
$this->assertXPath("//div[@id='image_container'][contains(@style, 'images/blank.gif')]");
}
/** @test */
public function articleEcrivezDesTestsShouldBeVisible() {
$this->assertXPathContentContains("//li//a", "Ecrivez des tests !");
}
}
class BibControllerZoneViewOneWithHideNewsTest extends BibControllerWithZoneTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()->setCfgModules(array("bib" => array("zoneview" => array("hide_news" => 1))));
$this->dispatch('bib/zoneview/id/1');
}
/** @test */
public function actualitesShouldNotBeVisible() {
$this->assertNotXPathContentContains("//h2", "Actualités :");
}
/** @test */
public function articleEcrivezDesTestsShouldNotBeVisible() {
$this->assertNotXPathContentContains("//li//a", "Ecrivez des tests !");
}
}
class BibControllerIndexWithHideNewsTest extends BibControllerWithZoneTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()->setCfgModules(array("bib" => array("index" => array("hide_news" => 1))));
$this->dispatch('bib/index');
}
/** @test */
public function actualitesShouldNotBeVisible() {
$this->assertNotXPathContentContains("//h2", "Actualités :");
}
/** @test */
public function articleEcrivezDesTestsShouldNotBeVisible() {
$this->assertNotXPathContentContains("//li//a", "Ecrivez des tests !");
}
}
class BibControllerIndexWithShowNewsTest extends BibControllerWithZoneTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()->setCfgModules(array("bib" => array("index" => array("hide_news" => 0))));
$this->dispatch('bib/index');
}
/** @test */
public function actualitesShouldBeVisible() {
$this->assertXPathContentContains("//h2", "Actualités :");
}
/** @test */
public function articleEcrivezDesTestsShouldBeVisible() {
$this->assertXPathContentContains("//li//a", "Ecrivez des tests !");
}
/** @test */
function hrefForArticleEcrivezDesTestsShouldLinkToArticleView() {
$this->assertXPath('//li//a[contains(@href, "cms/articleview/id/2")]',
$this->_response->getBody());
}
}
class BibControllerMapViewTest extends BibControllerWithZoneTestCase {
public function setUp() {
parent::setUp();
$aff_zone = array('profilID' => '3',
'libelle' => 'Annecy',
'posX' => 2,
'posY' => 5,
'posPoint' => 'droite');
$this->bib_annecy->setAffZone(ZendAfi_Filters_Serialize::serialize($aff_zone));
$this->dispatch('bib/mapzoneview/id/1');
}
/** @test */
public function actionShouldBeMapZoneView() {
$this->assertAction('mapzoneview');
}
/** @test */
public function mapShouldBeVisible() {
$this->assertXPath("//div[@id='image_container']");
}
/** @test */
public function imageZoneShouldBeVisible() {
$this->assertXPath("//div[@id='image_container'][contains(@style, 'images/blank.gif')]");
}
/** @test */
public function bibAnnecyShouldBeVisibleOnMap() {
$this->assertXPathContentContains("//span[contains(@onclick, '?id_profil')]", "Annecy");
}
}
class BibControllerBibViewAnnecyTest extends BibControllerWithZoneTestCase {
protected $_mock_sql;
public function setUp() {
parent::setUp();
$this->_mock_sql = Storm_Test_ObjectWrapper::mock();
Zend_Registry::set('sql', $this->_mock_sql);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Exemplaire')
->whenCalled('countBy')
->with(['model' => $this->bib_annecy, 'role' => 'bib'])
->answers(20)
->beStrict();
->whenCalled('fetchOne')
$this->dispatch('bib/bibview/id/4', true);
}
/** @test */
public function formRechercheShouldLinkToCurrentBib() {
$this->assertXPath('//form[contains(@action, "/recherche/simple/id/4/geo_bib/4")]', $this->_response->getBody());
}
/** @test */
function AdresseShouldBe1RueJeanJaures() {
$this->assertXPathContentContains('//tr', '1 rue Jean Jaures');
}
/** @test */
function articleEcrivezDesTestsShouldBeVisible() {
$this->assertXPathContentContains('//h2', 'Ecrivez des tests !');
}
/** @test */
function libelleCatBonnesPratiquesShouldBeVisible() {
$this->assertXPathContentContains('//h1', 'Bonnes pratiques');
}
/** @test */
public function urlRetourShouldBeZoneViewIdOne() {

Ghislain Loas
committed
$this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]',
'Retour');
}
}
class BibControllerBibViewAnnecyWithParamRetourHistoriqueTest extends BibControllerWithZoneTestCase {
/** @test */
public function withUrlRetourCmsArticleViewFiveShouldBeAccepted() {
$this->dispatch('bib/bibview/id/4?retour=cms+articleview+5');

Ghislain Loas
committed
$this->assertXPathContentContains('//a[contains(@href, "/cms/articleview/id/5")]',
'Retour');
}
/** @test */
public function withUrlRetourCmsOnlyShouldNotBeAccepted() {
$this->dispatch('bib/bibview/id/4?retour=cms');

Ghislain Loas
committed
$this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]',
'Retour');
}
}
class BibControllerBibViewInexistantTest extends BibControllerWithZoneTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('bib/bibview/');
}
/** @test */
public function responseShouldRedirectToIndex() {
$this->assertRedirectTo('/opac/bib/index');
}
}

Ghislain Loas
committed
abstract class BibControllerBibSelectionAbstractTestCase extends AbstractControllerTestCase {
public function setUp() {

Ghislain Loas
committed
parent::setUp();
$_SESSION['selection_bib'] = ['id_bibs' => []];
$this->fixture('Class_Zone',
['id' => 1,
'libelle' => 'Africa']);
$this->fixture('Class_Zone',
['id' => 2,
'libelle' => 'Europe']);

Ghislain Loas
committed
$cairo = $this->fixture('Class_Bib',
['id' => 1,
'id_site' => 1,
'libelle' => 'Cairo',
'id_zone' => 1,
'visibilite' => 2]);
$casablanca = $this->fixture('Class_Bib',
['id' => 2,
'id_site' => '2',
'libelle' => 'Casablanca',
'visibilite' => 2,
'id_zone' => 1]);
$paris = $this->fixture('Class_Bib',
['id' => 3,
'id_site' => '2',
'libelle' => 'Paris',
'visibilite' => 2,
'id_zone' => 2]);
}
}

Ghislain Loas
committed
class BibControllerBibSelectionWithEmptySessionTest extends BibControllerBibSelectionAbstractTestCase {
public function setUp() {
parent::setUp();

Ghislain Loas
committed
$this->dispatch('bib/selection', true);
}
/** @test */
public function pageShouldBeHtml5Valid() {
$this->assertHTML5($this->_response->getBody());
}
/** @test */
public function cairoShouldBeInBibList() {
$this->assertXPathContentContains('//li/span', 'Cairo');
}
/** @test */
public function casablancaShouldBeInBibList() {
$this->assertXPathContentContains('//li/span', 'Casablanca');
}
/** @test */
public function inputTypeSubmitShouldBePresent() {
$this->assertXPath('//form//input[@type="submit"]');
}

Ghislain Loas
committed
}

Ghislain Loas
committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
class BibControllerBibSelectionWithBibsIdsInSessionTest extends BibControllerBibSelectionAbstractTestCase {
public function setUp() {
parent::setUp();
$_SESSION['selection_bib'] = ['id_bibs' => [1, 2]];
$this->dispatch('bib/selection', true);
}
/** @test */
public function cairoShouldBeChecked() {
$this->assertXPath('//li/input[@checked="checked"][@value="1"]');
}
/** @test */
public function casablancaShouldBeChecked() {
$this->assertXPath('//li/input[@checked="checked"][@value="2"]');
}
/** @test */
public function parisShouldNotBeChecked() {
$this->assertNotXPath('//li/input[@checked="checked"][@value="3"]');
}
}
class BibControllerBibSelectionPostDispatchTest extends BibControllerBibSelectionAbstractTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('bib/selection', ['bib_select' => [1, 2]]);
}
/** @test */
public function seesionShouldContainsCasablancaAndCairo() {
$this->assertEquals([1, 2] ,$_SESSION['selection_bib']['id_bibs']);
}
/** @test */
public function sessionShouldNotContainsMessage() {
$this->assertFalse(array_key_exists('message', $_SESSION['selection_bib']));
}
/** @test */
public function sessionShouldNotContainsHtml() {
$this->assertFalse(array_key_exists('html', $_SESSION['selection_bib']));
}
}
class BibControllerBibSelectionWithProfilIdParamTest extends BibControllerBibSelectionAbstractTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('opac/index/index/id_profil/1', true);
}
/** @test */
public function sessionSlectionBibShouldNotExist() {
$this->assertFalse(array_key_exists('id_bibs', $_SESSION['selection_bib']));
}
}