You need to sign in or sign up before continuing.
Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* 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).
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
class IndexControllerSetupDomainTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
Class_Adminvar::beVolatile();
}
/** @test */
public function accessingIndexShouldSetupNomDomain() {
Class_Url::setForbidenUrls(['opac3']);
$this->dispatch('/');
$this->assertEquals('http://localhost/usr/local/bin/phpunit', Class_AdminVar::get('NOM_DOMAINE'));
}
/** @test */
public function withNomDomainAccessingIndexShouldNotSetupNomDomain() {
$this->fixture('Class_AdminVar',
['id' => 'NOM_DOMAINE',
'clef' => 'NOM_DOMAINE',
'valeur' => 'http://bokeh-library-protal.org']);
$this->dispatch('/');
$this->assertEquals('http://bokeh-library-protal.org', Class_Url::siteUrl());
}
/** @test */
public function setLocalhostAsForbidenUrlNomDomainShouldNotBeSet() {
Class_Url::setForbidenUrls(['localhost']);
$this->dispatch('/');
$this->assertEquals('', Class_AdminVar::get('NOM_DOMAINE'));
}
}
class IndexControllerAsInviteTest extends AbstractControllerTestCase {
protected function _loginHook($account) {
$account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::INVITE;
}
/** @test */
public function withOnlyParamQShouldRedirectToRecherche() {
$this->dispatch('index/index?q=test');
$this->assertRedirectTo('/recherche?q=test');
}
/** @test */
public function cssEditorShouldNotBeLoaded() {
$this->dispatch('/');
$this->assertNotXPathContentContains('//script', 'AFI-OPAC.js');
}
/** @test */
public function linkToConfigurePageShouldNotBeInFooter() {
Class_Profil::newInstanceWithId(1, ['cfg_menus' => '']);
$this->dispatch('/?id_profil=1');
$this->assertNotXPath('//a[contains(@href, "admin/profil/accueil/id_profil/1")]');
}
abstract class IndexControllerAsAdminTestCase extends AbstractControllerTestCase {
protected function _loginHook($account) {
$account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL;
}
Class_Profil::newInstanceWithId(1, ['header_css' => 'mycss.css']);
}
class IndexControllerAsAdminWithCssEditorAndNoHeaderCss extends IndexControllerAsAdminTestCase {
Class_Profil::find(1)->setHeaderCss('');
$this->dispatch('/?id_profil=1');
}
/** @test */
public function headerCssShouldNotBeIncluded() {
$this->assertNotXPath('//link[@id="profil_css"]');
}
/** @test */
public function linkToConfigurePageShouldBeInFooter() {
$this->assertXPath('//div[@class="footer"]//a[@class="edit_profil"][contains(@href, "admin/profil/accueil/id_profil/1")]');
}
class IndexControllerAsAdminWithCSSEditorTest extends IndexControllerAsAdminTestCase {
/** @test */
public function cssEditorShouldBeLoaded() {
$this->assertXPathContentContains('//script', 'AFI-OPAC.js');
}
/** @test */
public function headerCssShouldBeMyCssWithCacheWorkaround() {
$this->assertXPath('//link[contains(@href, "mycss.css")][contains(@href, "?cache=")]');
}

gloas
committed

gloas
committed
class IndexControllerWithInvitedLevelRestrictionForProfilTest extends AbstractControllerTestCase {
public function setup() {
parent::setup();
ZendAfi_Auth::getInstance()->clearIdentity();
Class_Profil::newInstanceWithId(1, ['access_level' => '0' ,'cfg_menus' => '']);
}
/** @test **/
public function anonymousAccessingProfilWithAccessLevelShouldBeRedirectedToOpacLogin() {
$this->dispatch('/opac/index/index/id_profil/1');
$this->assertRedirectRegex('|^'.BASE_URL.'/auth/login/id_profil/1|');
}

gloas
committed
}
class IndexControllerWithLoggedUserTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->logUser($this->fixture('Class_Users',
['id' => 1,
'login' => 'tom',
'password' => 'ok']));
$this->dispatch('index/index', true);
}
/** @test */
public function bodyShouldHaveDataLoggedTrue() {
$this->assertXPath('//body[@data-logged="true"]');
}
class IndexControllerAsPhoneWithPhoneProfilTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_USER_AGENT'] = 'iphone';
$this->fixture('Class_Profil',
['id' => 9999,
'browser' => 'telephone']);
/** @test */
public function messageToRedirectToPhoneModeShouldBePresent() {
$this->assertXPath('//div[@class="back_to_phone"]');
}
}
class IndexControllerAsPhoneWithNoPhoneProfilTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_USER_AGENT'] = 'iphone';
$this->dispatch('/opac', true);
}
/** @test */
public function messageToRedirectToPhoneModeShouldBePresent() {
$this->assertNotXPath('//div[@class="back_to_phone"]');
}
class IndexControllerSitemapTest extends AbstractControllerTestCase {
$this->_sitemap = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>'.BASE_URL.'?id_profil=1</loc>
<priority>1.0</priority>
</url>
<url>
<loc>'.BASE_URL.'?id_profil=2</loc>
<priority>0.5</priority>
</url>
</urlset>
';
$this->_file_system = $this->mock()
->whenCalled('file_exists')->answers(true)
->whenCalled('file_get_contents')->answers($this->_sitemap);
Class_Sitemap::setFileSystem($this->_file_system);
/** @test */
public function contentShouldBeXml() {
$this->assertHeaderContains('Content-Type', 'text/xml; charset=utf-8');
}
/** @test */
public function withNoSitemapShouldRedirectToIndex() {
$this->_file_system = $this->mock()
->whenCalled('file_exists')->answers(false);
Class_Sitemap::setFileSystem($this->_file_system);
$this->dispatch('/sitemap.xml', true);
/** @test */
public function contentShouldBeAsExpected() {
$this->assertEquals($this->_response->getBody(), $this->_sitemap);
}
class IndexControllerRewriteUrlTest extends AbstractControllerTestCase {
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->logUser($this->fixture('Class_Users',
['id' => 1,
'login' => 'guest',
'password' => 'guest',
'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE]));
$this->fixture('Class_Profil', ['id' => 345,
'libelle' => 'Zork - Main',
'parent_id' => null,
'rewrite_url' => 'zork',
'access_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
$this->fixture('Class_Profil', ['id' => 879,
'libelle' => 'Zork - Child',
'parent_id' => 345,
'rewrite_url' => 'zork-child']);
}
/** @test */
public function privateProfilShouldRedirectToLogin() {
$this->dispatch('/zork', true);
$this->assertModule('opac');
$this->assertController('auth');
$this->assertAction('login');
}
/** @test */
public function publicProfilWithPrivateParentProfilShouldRedirectToLogin() {
$this->dispatch('/zork-child', true);
$this->assertModule('opac');
$this->assertController('auth');
$this->assertAction('login');
}
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
}
abstract class IndexControllerCnilTrackingTestCase extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
protected $_expected_message = 'showNotification({"message":"En poursuivant votre navigation sur ce site, vous acceptez l\'utilisation de cookies.","autoClose":false';
public function tearDown() {
Class_Cnil::setCookieJar(null);
Class_Cnil::setTimeSource(null);
parent::tearDown();
}
}
class IndexControllerCnilTrackingFirstVisitTest
extends IndexControllerCnilTrackingTestCase {
protected $_cookie_jar;
public function setUp() {
parent::setUp();
Class_Cnil::setTimeSource($this->mock()
->whenCalled('time')
->answers(strtotime('2015-09-25 15:45:54')));
Class_Cnil::setCookieJar($this->_cookie_jar = $this->mock()
->whenCalled('setcookie')
->with('cnil8801b6c24c4d369a55a96252ed121d5c',
1,
1476884754)
->answers(null));
$this->dispatch('/', true);
}
/** @test */
public function shouldDisplayCnilMessage() {
$this->assertXPathContentContains('//script', $this->_expected_message);
}
/** @test */
public function shouldSetCnilCookieFor13Months() {
$this->assertTrue($this->_cookie_jar->methodHasBeenCalled('setcookie'));
}
}
class IndexControllerCnilTrackingSecondVisitTest
extends IndexControllerCnilTrackingTestCase {
/** @test */
public function shouldNotDisplayCnilMessage() {
$this->dispatch('/', true);
$this->_response->setBody('');
Class_ScriptLoader::resetInstance();
$this->dispatch('/', true);
$this->assertNotXPathContentContains('//script', $this->_expected_message);
}
}
class IndexControllerCnilTrackingExistingCookieVisitTest
extends IndexControllerCnilTrackingTestCase {
/** @test */
public function shouldNotDisplayCnilMessage() {
$_COOKIE['cnil' . md5(BASE_URL)] = 1;
$this->dispatch('/', true);
$this->assertNotXPathContentContains('//script', $this->_expected_message);
}