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' . Class_Url::baseUrl(), 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');
}
}
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';

Alex Arnaud
committed
protected $_cookie_jar;

Alex Arnaud
committed
public function setUp() {
parent::setUp();

Alex Arnaud
committed
$this->fixture('Class_AdminVar', ['id' => 'CNIL_CONSENT_ENABLE',
'valeur' => true]);

Alex Arnaud
committed
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('cnil' . md5(BASE_URL),
1,
1476884754)
->answers(null));
}
public function tearDown() {
Class_Cnil::setCookieJar(null);
Class_Cnil::setTimeSource(null);
parent::tearDown();
}
}
class IndexControllerCnilTrackingFirstVisitTest
extends IndexControllerCnilTrackingTestCase {
public function setUp() {
parent::setUp();

Alex Arnaud
committed
$this->dispatch('/', true);
}
/** @test */
public function shouldDisplayCnilMessage() {
$this->assertXPath('//script[contains(text(), "En poursuivant votre navigation")][contains(text(), "\/help\/cookies")][contains(text(), "En savoir plus")]', $this->_response->getBody());
}
/** @test */
public function shouldSetCnilCookieFor13Months() {
$this->assertTrue($this->_cookie_jar->methodHasBeenCalled('setcookie'));
}
}

Alex Arnaud
committed
class IndexControllerCnilTrackingFirstVisitWithAdminVarDisabledTest
extends IndexControllerCnilTrackingTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_AdminVar', ['id' => 'CNIL_CONSENT_ENABLE',
'valeur' => false]);
$this->dispatch('/', true);
}

Alex Arnaud
committed
public function shouldDisplayCnilMessage() {
$this->assertNotXPathContentContains('//script', $this->_expected_message);
}
}
class IndexControllerCnilTrackingSecondVisitTest
extends IndexControllerCnilTrackingTestCase {

Alex Arnaud
committed
public function setUp() {
parent::setUp();
$this->dispatch('/', true);
$this->_response->setBody('');
Class_ScriptLoader::resetInstance();
$this->dispatch('/', true);

Alex Arnaud
committed
}

Alex Arnaud
committed
/** @test */
public function shouldNotDisplayCnilMessageOf() {
$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);
}
class IndexControllerInspectorGadgetTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/index/index/inspector_gadget/1', true);
}
/** @test */
public function sessionShouldContainsSmoethings() {
$session = Zend_Registry::get('session');
$calls = isset($session->inspectorCalls)
? $session->inspectorCalls
: [];
$this->assertEquals([], $calls);
}