An error occurred while loading the file. Please try again.
-
Patrick Barroca authoredf109b1a3
ProfilTest.php 38.19 KiB
<?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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ProfilVideTest extends ModelTestCase {
public function setUp() {
$this->profil_vide = new Class_Profil();
}
/** @test */
public function cfgAccueilShouldReturnArrayWithModules() {
$this->assertEquals(['page_css' => null,
'use_parent_css' => true,
'modules' => []],
$this->profil_vide->getCfgAccueilAsArray());
}
/** @test */
public function shouldBeValid() {
$this->assertTrue($this->profil_vide->isValid());
}
/** @test */
public function getBibLibelleShouldReturnEmptyString() {
$this->assertEquals('', $this->profil_vide->getBibLibelle());
}
/** @test */
public function getModuleAccueilPreferencesShouldReturnEmptyArray() {
$this->assertEquals(array(), $this->profil_vide->getModuleAccueilPreferences(1));
}
/** @test */
public function profilZonesTitreShouldReturn200_E_H_I() {
$this->assertEquals(['200$e', '200$h', '200$i'], Class_Profil::getCurrentProfil()->getZonesTitre());
}
/** @test **/
public function profilVidePathShouldBeSlahProfil() {
$this->assertEquals('/** nouveau profil **', $this->profil_vide->getPath());
}
}
class ProfilJeunesseAstrolabeTest extends ModelTestCase {
public function setUp() {
$cfg_accueil = ['modules' => ['1' => ['division' => '1',
'type_module' => 'RECH_SIMPLE',
'preferences' => []]],
'options' => []];
$this->profil_astro = Class_Profil::getLoader()
->newInstanceWithId(7)
->setIdSite(12)
->setLibelle("Jeunesse")
->setSkin('astrolabe')
->setCfgMenus(array())
->setHeaderCss('afi-opac3/userfiles/jeunesse.css')
->setCfgAccueil($cfg_accueil);
$this->bib_melun = Class_Bib::getLoader()
->newInstanceWithId(12)
->setLibelle('Melun');
Storm_Test_ObjectWrapper
::onLoaderOfModel('Class_Profil')
->whenCalled('findAllBy')
->answers(array());
Class_Profil::setFileWriter(Storm_Test_ObjectWrapper::mock()->whenCalled('fileExists')->answers(true));
}
/** @test */
public function getCfgMenuAsArrayShouldReturnDefaultMenus() {
$this->assertEquals(array(
'H' => array(
"libelle" => "Menu horizontal",
"picto" => "vide.gif",
'menus' => array()),
'V' => array(
"libelle" => "Menu vertical",
"picto" => "vide.gif",
'menus' => array())),
$this->profil_astro->getCfgMenusAsArray());
}
/** @test */
public function shouldAddMenuHorizontalIfNotExists() {
$this->profil_astro->setCfgMenus( array(
'V' => array(
"libelle" => "Les news",
"picto" => "home.gif",
"menus" => array()),
'4' => array(
"libelle" => "Mon menu",
"picto" => "home.png",
"menus" => array())));
$this->assertEquals(array(
'H' => array(
"libelle" => "Menu horizontal",
"picto" => "vide.gif",
"menus" => array()),
'V' => array(
"libelle" => "Les news",
"picto" => "home.gif",
"menus" => array()),
'4' => array(
"libelle" => "Mon menu",
"picto" => "home.png",
"menus" => array())),
$this->profil_astro->getCfgMenusAsArray());
}
/** @test */
public function getOrCreateConfigAccueilRechSimpleShouldCreatePreferences() {
$data = $this->profil_astro->getOrCreateConfigAccueil(1, 'RECH_SIMPLE');
$this->assertEquals('Rechercher', $data['titre']);
}
/** @test */
public function astroHeaderCssShouldBeJeunesse() {
$this->assertEquals('afi-opac3/userfiles/jeunesse.css', $this->profil_astro->getHeaderCss());
}
/** @test */
public function astroHeaderCssIE7ShouldBeIE7_Jeunesse() {
$this->assertEquals('ie7_jeunesse.css', $this->profil_astro->getHeaderCssIE(7));
}
/** @test */
public function astroHeaderCssIE7ShouldBeIE8_Jeunesse() {
$this->assertEquals('ie8_jeunesse.css', $this->profil_astro->getHeaderCssIE(8));
}
/** @test */
public function withoutCssHeaderCSSIE7ShouldBeEmpty() {
$this->profil_astro->setHeaderCss('');
$this->assertEmpty($this->profil_astro->getHeaderCssIE(7));
}
/** @test */
public function loadingAChildrenShouldNotRewriteParentAttributes() {
$row = array('ID_PROFIL' => 98, 'PARENT_ID' => 7, 'SKIN' => 'zork');
$child = Class_Profil::getLoader()->newFromRow($row);
$this->assertEquals('astrolabe', $child->getSkin());
$this->assertEquals('astrolabe', $this->profil_astro->getSkin());
}
/** @test */
public function getTitreSiteShouldReturnLibelleIfNoteSet() {
$this->assertEquals("Jeunesse",
$this->profil_astro->getTitreSite());
}
/** @test */
public function shouldBePublic() {
$this->assertTrue($this->profil_astro->isPublic());
}
/** @test */
public function getHauteurBanniereShouldReturn100() {
$this->assertEquals(100, $this->profil_astro->getHauteurBanniere());
}
/** @test */
public function getSkinShouldReturnAstrolabe() {
$this->assertEquals('astrolabe', $this->profil_astro->getSkin());
}
/** @test */
public function toArrayShouldContainsLibelleJeunesse() {
$attributes = $this->profil_astro->toArray();
$this->assertEquals('Jeunesse', $attributes['libelle']);
}
/** @test */
public function toArrayShouldContainsTitreSiteMediathequeAstrolabe() {
$attributes = $this->profil_astro->toArray();
$this->assertEquals("", $attributes['titre_site']);
}
/** @test */
public function getBoiteLoginInBanniereShouldReturnFalse() {
$this->assertFalse($this->profil_astro->getBoiteLoginInBanniere());
}
/** @test */
public function getBoiteRechercheInBanniereShouldReturnFalse() {
$this->assertFalse($this->profil_astro->getBoiteRechercheSimpleInBanniere());
}
/** @test */
public function setBoiteLoginInBanniereTrueShouldAddItToCfgAccueil() {
$this->profil_astro->setBoiteLoginInBanniere(true);
$this->assertTrue($this->profil_astro->getBoiteLoginInBanniere());
}
/** @test */
public function setBoiteLoginInBanniereTrueShouldGetIdTwo() {
$this->profil_astro->setBoiteLoginInBanniere(true);
$cfg_accueil = $this->profil_astro->getCfgAccueilAsArray();
$this->assertEquals('LOGIN', $cfg_accueil['modules'][2]['type_module']);
$this->assertEquals(2, $cfg_accueil['modules'][2]['preferences']['id_module']);
}
/** @test */
public function setBoiteRechercheSimpleInBanniereTrueShouldAddItToCfgAccueil() {
$this->profil_astro->setBoiteRechercheSimpleInBanniere(true);
$this->assertTrue($this->profil_astro->getBoiteRechercheSimpleInBanniere());
}
/** @test */
public function updateAttributesWithBoiteRechercheSimpleTrueShouldAddIt() {
$this->profil_astro->updateAttributes(array('boite_recherche_simple_in_banniere' => true));
$this->assertTrue($this->profil_astro->getBoiteRechercheSimpleInBanniere());
}
/** @test */
public function updateAttributesWithBoiteLoginTrueShouldAddIt() {
$this->profil_astro->updateAttributes(array('boite_login_in_banniere' => true));
$this->assertTrue($this->profil_astro->getBoiteLoginInBanniere());
}
/** @test */
public function hasSubProfilsShouldReturnFalse() {
$this->assertFalse($this->profil_astro->hasSubProfils());
}
/** @test */
public function getSubProfilsShouldReturnEmptyArray() {
$this->assertEquals(array(),
$this->profil_astro->getSubProfils());
return Class_Profil::getLoader();
}
/**
* @depends getSubProfilsShouldReturnEmptyArray
* @test
*/
public function profilLoaderShouldHaveFindAllByCalledWithParentIdOfAstrolabe($loader) {
$param = $loader->getFirstAttributeForLastCallOn('findAllBy');
$this->assertEquals('parent_profil', $param['role']);
$this->assertEquals($this->profil_astro->toArray(),
$param['model']->toArray());
}
/** @test */
public function hasParentProfilShouldReturnFalse() {
$this->assertFalse($this->profil_astro->hasParentProfil());
}
}
class PageBdAstrolabeTest extends Storm_Test_ModelTestCase {
protected $page_bd;
protected $profil_astro;
protected $bib_melun;
public function setup() {
parent::setup();
$cfg_accueil = ['modules' => ['1' => ['division' => '1',
'type_module' => 'RECH_SIMPLE',
'preferences' => ['header_css'=>'afi-opac3/userfiles/jeunesse.css']],
'3' => ['division' => '4',
'type_module' => 'LOGIN',
'preferences' => ['titre'=>'Connection']]],
'options' => []];
$this->profil_astro = Class_Profil::getLoader()
->newInstanceWithId(7)
->setIdSite(12)
->setLibelle("Jeunesse")
->setSkin('astrolabe')
->setCfgMenus(array())
->setHeaderCss('afi-opac3/userfiles/jeunesse.css')
->setCfgAccueil($cfg_accueil);
$this->bib_melun = Class_Bib::getLoader()
->newInstanceWithId(12)
->setLibelle('Melun');
Storm_Test_ObjectWrapper
::onLoaderOfModel('Class_Profil')
->whenCalled('findAllBy')
->answers(array());
Class_Profil::setFileWriter(
Storm_Test_ObjectWrapper::mock()
->whenCalled('fileExists')
->answers(true));
$this->page_bd = Class_Profil::getLoader()
->newInstanceWithId(6,
['parent_id' => $this->profil_astro->getId(),
'id_site' => 12,
'libelle' => 'Bdd',
'cfg_menus' => [],
'cfg_accueil' => [],
'page_css' => 'afi-opac3/userfiles/bd_jeunesse.css']);
$this->profil_astro->setSubProfils([$this->page_bd]);
}
/** @test **/
public function headerCssParentShouldReturnJeunesseCss() {
$this->assertEquals($this->page_bd->getParentProfil()->getHeaderCss(),$this->profil_astro->getHeaderCss());
}
/** @test **/
public function pageCssBDShouldBeBdJeunnesseCSS () {
$this->assertEquals($this->page_bd->getPageCss(), 'afi-opac3/userfiles/bd_jeunesse.css');
}
/** @test **/
public function useParentCssShouldReturnTrue() {
$this->assertTrue($this->page_bd->getUseParentCss()==1);
}
/** @test **/
public function useParentCssShouldBeInCfgAccueil() {
$this->assertEquals($this->page_bd->getUseParentCss(), $this->page_bd->getCfgAccueilAsArray()['use_parent_css']);
}
/** @test **/
public function pageCssShouldBeInCfgAccueil() {
$this->assertEquals($this->page_bd->getPageCss(), $this->page_bd->getCfgAccueilAsArray()['page_css']);
}
/** @test */
public function profilAstroConfigModuleTypeLoginShouldReturnConnexionAsTitrePreferences() {
$this->assertEquals('Connection',
$this->profil_astro->getModuleAccueilPreferencesByType('LOGIN')['titre']);
}
/** @test */
public function pageBdConfigModuleTypeLoginShouldReturnConnexionAsTitrePreferences() {
$this->assertEquals('Connection',
$this->page_bd->getModuleAccueilPreferencesByType('LOGIN')['titre']);
}
}
abstract class ProfilAdulteChatenayTestCase extends ModelTestCase {
public function setUp() {
parent::setUp();
$cfg_accueil = array('modules' => array('1' => array('division' => '4',
'type_module' => 'RECH_SIMPLE',
'preferences' => array()),
'2' => array('division' => '4',
'type_module' => 'LOGIN',
'preferences' => array()),
'4' => array('division' => '1',
'type_module' => 'NEWS')),
'options' => array());
$this->profil = Class_Profil::getLoader()
->newInstanceWithId(5)
->setTitreSite(null)
->setLibelle("Adulte")
->setHauteurBanniere(200)
->setNbDivisions(2)
->setLargeurSite(800)
->setLargeurDivision1(200)
->setLargeurDivision2(600)
->setLargeurDivision3(0)
->setCfgAccueil($cfg_accueil)
->setAccessLevel('-1')
->setMailSuggestionAchat('chatenay@chatenay.fr');
}
}
class ProfilAdulteChatenayTest extends ProfilAdulteChatenayTestCase {
public function setUp() {
parent::setUp();
$cfg_accueil_histoire = array('modules' => array(
'4' => array('division' => '1',
'type_module' => 'CRITIQUES'),
'7' => array('division' => '1',
'type_module' => 'KIOSQUE')),
'options' => array());
$this->page_histoire = Class_Profil::getLoader()
->newInstanceWithId(51)
->setParentId($this->profil->getId())
->setLibelle('Histoire')
->setCfgAccueil($cfg_accueil_histoire);
$this->page_politique = Class_Profil::getLoader()
->newInstanceWithId(51)
->setParentId($this->profil->getId())
->setLibelle('Politique');
$this->profil->setChildrenId([$this->page_politique]);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil')
->whenCalled('findAllBy')
->answers(array($this->page_politique,
$this->page_histoire))
->whenCalled('findFirstBy')
->answers($this->page_politique)
;
}
/** @test **/
public function profilPagepolitiquePathShouldBeSlahAdulteSlahPolitique() {
$this->assertEquals('/Adulte/Politique', $this->page_politique->getPath());
}
/** @test **/
public function withSlahAdulteSlashPolitqiueProfilShouldBePagePolitique() {
$this->assertEquals(Class_Profil::getRoot()->findByPath($this->page_politique->getPath()), $this->page_politique);
}
/** @test */
public function withNoBrowserPagePolitiqueShouldHavePathThemeOriginal() {
$this->page_politique->setBrowser('');
$this->assertEquals('/public/opac/skins/original/',$this->page_politique->getPathTheme());
}
/** @test */
public function hasSubPofilsShouldReturnsTrue() {
$this->assertTrue($this->profil->hasSubProfils());
}
/** @test */
public function getSubProfilsShouldContainsProfilHistoire() {
$this->assertEquals('Histoire',
array_first($this->profil->getSubProfils())->getLibelle());
}
/** @test */
public function getSubProfilsShouldContainsProfilPolitique() {
$this->assertEquals('Politique',
array_last($this->profil->getSubProfils())->getLibelle());
}
/** @test */
public function pagePolitiqueParentProfilShouldBeProfilAdulte() {
$this->assertEquals($this->profil,
$this->page_politique->getParentProfil());
}
/** @test */
public function pageHistoireParentShouldBeProfilAdulte() {
$this->assertEquals($this->profil,
$this->page_histoire->getParentProfil());
}
/** @test */
public function pageHistoireHasParentShouldReturnTrue() {
$this->assertTrue($this->page_histoire->hasParentProfil());
}
/** @test */
public function pageHistoireNbDivisionsShouldGetParentAttributes() {
$this->assertEquals(2, $this->page_histoire->getNbDivisions());
}
/** @test */
public function pageHistoireSetNbDivisionsShouldSetParentAttribute() {
$this->page_histoire->setNbDivisions(1);
$this->assertEquals(1, $this->page_histoire->getNbDivisions());
$this->assertEquals(1, $this->profil->getNbDivisions());
}
/** @test */
public function getLibelleShouldReturnLibelleWhenSiteNotSet() {
$this->assertEquals("Adulte", $this->profil->getLibelle());
}
/** @test */
public function shouldBePublic() {
$this->assertTrue($this->profil->isPublic());
}
/** @test */
public function getHauteurBanniereShouldReturn200() {
$this->assertEquals(200, $this->profil->getHauteurBanniere());
}
/** @test */
public function getLiensSortantOffShouldReturnFalse() {
$this->assertFalse($this->profil->getLiensSortantsOff());
}
/** @test */
public function getSkinShouldReturnOriginal() {
$this->assertEquals('original', $this->profil->getSkin());
}
/** @test */
public function shouldBeValid() {
$this->assertTrue($this->profil->isValid());
}
/** @test */
public function shouldHaveErrorLargeurSiteIfLessThan800() {
$this->profil->setLargeurSite(500);
$this->assertFalse($this->profil->isValid());
$this->assertContains("La largeur du site doit être comprise entre 800 et 2000 pixels.",
$this->profil->getErrors());
}
protected function _checkColorFormatValidFor($field) {
$valid_entries = array('#FFF', '#123456', '', null);
foreach($valid_entries as $entry) {
$this->profil->_set($field, $entry);
$this->assertTrue($this->profil->isValid(),
'Should be valid for value: "'.(string)$entry.'"');
}
$invalid_entries = array('zork', '#1', '#1234', '#1234567', '#R2D', '#3F33');
foreach($invalid_entries as $entry) {
$this->profil->_set($field, $entry);
$this->assertFalse($this->profil->isValid(),
'Should not be valid for value: "'.$entry.'"');
}
}
/** @test */
public function shouldBeValidIfCouleurTexteBandeauRightFormatted() {
$this->_checkColorFormatValidFor('couleur_texte_bandeau');
}
/** @test */
public function shouldBeValidIfCouleurLienBandeauRightFormatted() {
$this->_checkColorFormatValidFor('couleur_lien_bandeau');
}
/** @test */
public function getBoiteLoginInBanniereShouldReturnTrue() {
$this->assertTrue($this->profil->getBoiteLoginInBanniere());
}
/** @test */
public function getBoiteRechercheInBanniereShouldReturnTrue() {
$this->assertTrue($this->profil->getBoiteRechercheSimpleInBanniere());
}
/** @test */
public function setBoiteRechercheSimpleInBanniereFalseShouldRemoveIt() {
$this->profil->setBoiteRechercheSimpleInBanniere(false);
$this->assertFalse($this->profil->getBoiteRechercheSimpleInBanniere());
}
/** @test */
public function setBoiteLoginInBanniereFalseShouldRemoveIt() {
$this->profil->setBoiteLoginInBanniere(false);
$this->assertFalse($this->profil->getBoiteLoginInBanniere());
}
/** @test */
public function pageHistoireGetBoiteRechercheInBanniereShouldReturnTrue() {
$this->assertTrue($this->page_histoire->getBoiteRechercheSimpleInBanniere());
}
/** @test */
public function pagePolitiqueGetBoiteLoginInBanniereShouldReturnTrue() {
$this->assertTrue($this->page_politique->getBoiteLoginInBanniere());
}
/** @test */
public function deleteShouldCascadeOnPages() {
$loader = Class_Profil::getLoader()
->whenCalled('delete')
->answers(null)
->getWrapper();
$this->profil->delete();
$this->assertTrue($loader
->methodHasBeenCalledWithParams('delete',
array($this->page_politique)));
$this->assertTrue($loader
->methodHasBeenCalledWithParams('delete',
array($this->page_histoire)));
}
/** @test */
public function pagePolitiqueMailSuggestionAchatShouldBeChatenayAtChatenayDotFr() {
$this->assertEquals('chatenay@chatenay.fr', $this->page_politique->getMailSuggestionAchatOrPortail());
}
/** @test */
public function withoutMailSuggestionAchatPagePolitiqueShouldGetOneFromPortail() {
Class_Profil::getPortail()->setMailSuggestionAchat('suggest@chatenay.fr');
$this->profil->setMailSuggestionAchat('');
$this->assertEquals('suggest@chatenay.fr', $this->page_politique->getMailSuggestionAchatOrPortail());
}
/** @test */
public function withoutMailSuggestionAchatShouldGetMailSite() {
Class_Profil::getPortail()->setMailSuggestionAchat('');
$this->profil->setMailSuggestionAchat('')->setMailSite('contact@chatenay.fr');
$this->assertEquals('contact@chatenay.fr', $this->page_politique->getMailSuggestionAchatOrPortail());
}
/** @test */
public function withoutMailSuggestionAchatProfilPortailShouldGetMailSite() {
Class_Profil::getPortail()->setMailSuggestionAchat('')->setMailSite('admin@chatenay.fr');
$this->assertEquals('admin@chatenay.fr', Class_Profil::getPortail()->getMailSuggestionAchatOrPortail());
}
/** @test **/
public function withPanierAutoModulePanierShouldHaveBeendAdded() {
Class_AdminVar::newInstanceWithId('BOITE_PANIER_AUTO', ['valeur' => '1']);
$this->profil->getBoitesDivision(5);
$this->assertTrue($this->profil->hasBoitePanier());
}
/** @test **/
public function withoutPanierAutoModulePanierShouldHaveBeendAdded() {
Class_AdminVar::newInstanceWithId('BOITE_PANIER_AUTO', ['valeur' => '0']);
$this->profil->getBoitesDivision(5);
$this->assertFalse($this->profil->hasBoitePanier());
}
}
class ProfilAdulteChatenayMoveModuleMoveNEWSFromDiv1PosZeroToDivFourPositionOneTest extends ProfilAdulteChatenayTestCase {
public function setUp() {
parent::setUp();
$this->profil->moveModuleOldDivPosNewDivPos(1, 0, 4, 1);
$this->modules = array_at('modules', $this->profil->getCfgAccueilAsArray());
}
/** @test */
public function moduleIdFourShouldBeInDivFour() {
$this->assertEquals(4, $this->modules['4']['division']);
}
/** @test */
public function moduleIdFourShouldBeBetweenOneAndTwo() {
$this->assertEquals(array(1, 4, 2), array_keys($this->modules));
}
/** @test */
public function modulesCountShouldBeThree() {
$this->assertEquals(3, count($this->modules));
}
}
class ProfilAdulteChatenayMoveModuleLOGINToFirstPosInDivFourTest extends ProfilAdulteChatenayTestCase {
public function setUp() {
parent::setUp();
$this->profil->moveModuleOldDivPosNewDivPos(4, 1, 4, 0);
$this->modules = array_at('modules', $this->profil->getCfgAccueilAsArray());
}
/** @test */
public function moduleIdTwoShouldBeInDivFour() {
$this->assertEquals(4, $this->modules['2']['division']);
}
/** @test */
public function moduleIdTwoShouldBeOnTop() {
$this->assertEquals(array(2, 1, 4), array_keys($this->modules));
}
/** @test */
public function modulesCountShouldBeThree() {
$this->assertEquals(3, count($this->modules));
}
}
class ProfilAdulteChatenayMoveModuleRECH_SIMPLEToSecondPosInDivFourTest extends ProfilAdulteChatenayTestCase {
public function setUp() {
parent::setUp();
$this->profil->moveModuleOldDivPosNewDivPos(4, 0, 4, 1);
$this->modules = array_at('modules', $this->profil->getCfgAccueilAsArray());
}
/** @test */
public function moduleIdOneShouldBeInDivFour() {
$this->assertEquals(4, $this->modules['1']['division']);
}
/** @test */
public function moduleIdTwoShouldBeOnTop() {
$this->assertEquals(array(2, 4, 1), array_keys($this->modules));
}
/** @test */
public function modulesCountShouldBeThree() {
$this->assertEquals(3, count($this->modules));
}
}
class ProfilAdulteChatenayMoveModuleLOGINToLastPosInDivOneTest extends ProfilAdulteChatenayTestCase {
public function setUp() {
parent::setUp();
$this->profil->moveModuleOldDivPosNewDivPos(4, 1, 1, 1);
$this->modules = array_at('modules', $this->profil->getCfgAccueilAsArray());
}
/** @test */
public function moduleIdTwoShouldBeInDivOne() {
$this->assertEquals(1, $this->modules['2']['division']);
}
/** @test */
public function moduleIdTwoShouldBeLast() {
$this->assertEquals(array(1, 4, 2), array_keys($this->modules));
}
/** @test */
public function modulesCountShouldBeThree() {
$this->assertEquals(3, count($this->modules));
}
}
class ProfilEvenementsTest extends ModelTestCase {
public function setUp() {
$this->profil = new Class_Profil();
$this->profil
->setTitreSite(null)
->setLibelle("Evenements")
->setBoiteRechercheSimpleInBanniere(true)
->setBoiteLoginInBanniere(true)
->setAccessLevel(1);
$boites_banniere = $this->profil->getBoitesDivision(4);
$this->boite_recherche = $boites_banniere[1];
$this->boite_login = $boites_banniere[2];
}
/** @test */
public function getBoitesDivisionFourShouldReturnATwoElementsArray() {
$this->assertEquals(2, count($this->profil->getBoitesDivision(4)));
}
/** @test */
public function shouldNotBePublic() {
$this->assertFalse($this->profil->isPublic());
}
/** @test */
public function afterSetBoiteLoginTrueShouldStillHaveTwoBoites() {
$this->profil->setBoiteLoginInBanniere(true);
$this->assertEquals(2, count($this->profil->getBoitesDivision(4)));
}
/** @test */
public function afterSetRechercheSimpleTrueShouldStillHaveTwoBoites() {
$this->profil->setRechercheSimpleInBanniere(true);
$this->assertEquals(2, count($this->profil->getBoitesDivision(4)));
}
/** @test */
public function boiteRechercheSimpleTitreShouldBeRechercher() {
$this->assertEquals('Rechercher', $this->boite_recherche['preferences']['titre']);
}
/** @test */
public function boiteRechercheSimpleTemplateShouldBeBoiteBanniereGauche() {
$this->assertEquals('boite_banniere_gauche', $this->boite_recherche['preferences']['boite']);
}
/** @test */
public function boiteLoginTemplateShouldBeBoiteBanniereDroite() {
$this->assertEquals('boite_banniere_droite', $this->boite_login['preferences']['boite']);
}
/** @test */
public function boiteConnexionTitreShouldBeSeConnecter() {
$this->assertEquals('Se connecter', $this->boite_login['preferences']['titre']);
}
/** @test **/
public function boiteConnexionIdModuleShouldBeTwo() {
$this->assertEquals('2', $this->boite_login['preferences']['id_module']);
}
}
class ProfilPesseyValandryTranslatedTest extends ModelTestCase {
/**
* @var Class_Profil
*/
private $_profil;
public function setUp() {
$this->_profil = new Class_Profil();
$this->_profil
->setTitreSite('Médiathèque de pessey Valandry')
->setLibelle('Tout sur notre médiatheque')
->setAccessLevel(1)
->setCfgMenus(ProfilPesseyValandryFixtures::createMenusConfiguration())
->setCfgSite(ProfilPesseyValandryFixtures::createSiteConfiguration())
->setCfgAccueil(ProfilPesseyValandryFixtures::createAccueilConfiguration())
->setCfgNotice(ProfilPesseyValandryFixtures::createNoticeConfiguration())
->setCfgModules(ProfilPesseyValandryFixtures::createModulesConfiguration())
;
}
/** @test */
public function getCfgMenusAsArrayShouldCallTranslator() {
$mockTranslator = $this->_getMockTranslator();
$mockTranslator->expects($this->once())
->method('translate')
->with(ProfilPesseyValandryFixtures::createMenusConfiguration(), 'Menus')
;
$this->_profil->setTranslator($mockTranslator);
$menus = $this->_profil->getCfgMenusAsArray();
}
/** @test */
public function getCfgSiteAsArrayShouldCallTranslator() {
$mockTranslator = $this->_getMockTranslator();
$mockTranslator->expects($this->once())
->method('translate')
->with(ProfilPesseyValandryFixtures::createSiteConfiguration(), 'Site')
;
$this->_profil->setTranslator($mockTranslator);
$menus = $this->_profil->getCfgSiteAsArray();
}
/** @test */
public function getCfgAccueilAsArrayShouldCallTranslator() {
$mockTranslator = $this->_getMockTranslator();
$mockTranslator->expects($this->once())
->method('translate')
->with(ProfilPesseyValandryFixtures::createAccueilConfiguration(), 'Accueil')
;
$this->_profil->setTranslator($mockTranslator);
$menus = $this->_profil->getCfgAccueilAsArray();
}
/** @test */
public function getCfgNoticeAsArrayShouldCallTranslator() {
$mockTranslator = $this->_getMockTranslator();
$mockTranslator->expects($this->once())
->method('translate')
->with(ProfilPesseyValandryFixtures::createNoticeConfiguration(), 'Notice')
;
$this->_profil->setTranslator($mockTranslator);
$menus = $this->_profil->getCfgNoticeAsArray();
}
/** @test */
public function getCfgModulesAsArrayShouldCallTranslator() {
$mockTranslator = $this->_getMockTranslator();
$mockTranslator->expects($this->once())
->method('translate')
->with(ProfilPesseyValandryFixtures::createModulesConfiguration(), 'Modules')
;
$this->_profil->setTranslator($mockTranslator);
$menus = $this->_profil->getCfgModulesAsArray();
}
/**
* @return PHPUnit_Framework_MockObject_MockObject
*/
private function _getMockTranslator() {
return $this->getMockBuilder('Class_Profil_I18nTranslator')
->disableOriginalConstructor()
->getMock()
;
}
}
class ProfilPesseyValandryFixtures {
public static function createModulesConfiguration() {
return array('dummy_modules' => array('all' => 'the configurations'));
}
public static function createNoticeConfiguration() {
return array('dummy_notice' => array('all' => 'the configurations'));
}
public static function createMenusConfiguration() {
return array(
'H' => array(
'libelle' => 'Menu horizontal',
'picto' => 'vide.gif',
'menus' => array(
),
),
);
}
public static function createSiteConfiguration() {
return array('dummy_key' => 'dummy_value');
}
public static function createAccueilConfiguration() {
return [ 'page_css' => null,
'use_parent_css' => true,
'dummy_accueil' => ['all' => 'the configurations']];
}
}
class ProfilPortailTest extends ModelTestCase {
/** @var Class_Profil */
protected $_profil;
/** @var Storm_Test_ObjectWrapper */
protected $_wrapper;
public function setUp() {
parent::setUp();
$this->_wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil')
->whenCalled('delete')->answers(true)->getWrapper();
$this->_profil = Class_Profil::getLoader()->newInstanceWithId(1);
}
/** @test */
public function deletingPortalShouldNotBePossible() {
$this->_profil->delete();
$this->assertFalse($this->_wrapper->methodHasBeenCalled('delete'));
}
/** @test */
public function copyShouldBeNew() {
$this->assertFalse($this->_profil->isNew());
$this->assertTrue($this->_profil->copy()->isNew());
}
/** @test */
public function copyShouldNotHaveIdProfil() {
$this->assertEmpty($this->_profil->copy()->id_profil);
}
}
class ProfilWithPagesCopyTest extends Storm_Test_ModelTestCase {
protected $_clone;
public function setUp() {
parent::setUp();
$profil = $this->fixture('Class_Profil',
['id' => 1,
'nb_divisions' => 2])
->setSubProfils([ $this->fixture('Class_Profil', ['id' => 2]),
$this->fixture('Class_Profil', ['id' => 3]),
$this->fixture('Class_Profil', ['id' => 4,
'libelle' => 'CD']),
$this->fixture('Class_Profil', ['id' => 5])
]);
$profil->assertSave();
Class_Profil::clearCache();
$profil = Class_Profil::find(1);
$this->_clone = $profil->deepCopy();
$this->_clone->assertSave();
}
/** @test */
public function cloneShouldHaveFourPages() {
$this->assertEquals(4, $this->_clone->numberOfSubProfils());
}
/** @test */
public function cloneFirstPageLibelleShouldBeIndexedAtNouveauProfil() {
$this->assertEquals('** nouveau profil **', $this->_clone->getSubProfils()['** nouveau profil **']->getLibelle());
}
/** @test */
public function cloneSecondPageLibelleShouldBeIndexedAtNouveauProfil1() {
$this->assertEquals('** nouveau profil **', $this->_clone->getSubProfils()['** nouveau profil ** (1)']->getLibelle());
}
/** @test */
public function loadedClonedPageCDShouldHaveTwoDivisions() {
$page_cd = $this->_clone->getSubProfils()['CD'];
$this->assertEquals(2, $page_cd->getNbDivisions());
}
/** @test */
public function pageCdParentShouldBeClonedProfil() {
$this->assertSame($this->_clone, $this->_clone->getSubProfils()['CD']->getParentProfil());
}
/** @test */
public function cloneThirdPageLibelleShouldBeIndexedAtCD() {
$this->assertEquals('CD', $this->_clone->getSubProfils()['CD']->getLibelle());
}
/** @test */
public function cloneFourthPageLibelleShouldBeIndexedAtNouveauProfil2() {
$this->assertEquals('** nouveau profil **', $this->_clone->getSubProfils()['** nouveau profil ** (2)']->getLibelle());
}
/** @test */
public function cloneIdShouldBe6() {
$this->assertEquals(6, $this->_clone->getId());
}
/** @test */
public function cloneFirstPageIdShouldBe7() {
$this->assertEquals(7, array_values($this->_clone->getSubProfils())[0]->getId());
}
/** @test */
public function cloneFirstPageParentIdShouldBe6() {
$this->assertEquals(6, array_values($this->_clone->getSubProfils())[0]->getParentId());
}
/** @test */
public function cloneLastPageIdShouldBe10() {
$this->assertEquals(10, array_values($this->_clone->getSubProfils())[3]->getId());
}
/** @test */
public function cloneLastPageParentIdShouldBe6() {
$this->assertEquals(6, array_values($this->_clone->getSubProfils())[3]->getParentId());
}
}
class ProfilHeaderImgAccessTest extends Storm_Test_ModelTestCase {
public function setUp() {
parent::setUp();
$this->file_system = $this->mock()
->whenCalled('opendir')->answers(null)
->whenCalled('readdir')->answers(false)
->whenCalled('closedir')->answers(null);
Class_Profil::setFileSystem($this->file_system);
$this->profil = $this->fixture('Class_Profil',
['id' => 999, 'header_img_cycle' => true]);
}
/** @test */
public function whenBannersDirDoesNotExistShouldCreateIt() {
$this->file_system
->whenCalled('file_exists')->answers(false)
->whenCalled('mkdir')->answers(true);
$this->profil->getAllHeaderImg();
$this->assertTrue($this->file_system->methodHasBeenCalled('mkdir'));
}
/** @test */
public function whenBannersDirDoesNotExistAndCannotCreateItShouldNotOpenIt() {
$this->file_system
->whenCalled('file_exists')->answers(false)
->whenCalled('mkdir')->answers(false);
$this->profil->getAllHeaderImg();
$this->assertFalse($this->file_system->methodHasBeenCalled('opendir'));
}
/** @test */
public function whenBannersDirExistShouldNotCreateIt() {
$this->file_system
->whenCalled('file_exists')->answers(true);
$this->profil->getAllHeaderImg();
$this->assertFalse($this->file_system->methodHasBeenCalled('mkdir'));
}
}
abstract class ProfilUpdateConfigAccueilOnModuleInBannerTestCase
extends Storm_Test_ModelTestCase {
protected $_profil;
public function setUp() {
parent::setUp();
$this->_profil = $this->fixture('Class_Profil', ['id' => 1])
->setBoiteLoginInBanniere(true);
$this->prepareProfile();
$config = $this->_profil->getModuleAccueilConfig(1);
$config['preferences']['profil_redirect'] = 123;
$this->_profil->updateModuleConfigAccueil(1, $config);
}
protected function prepareProfile() {}
protected function getPreferenceOfModule($profil, $id_module, $preference) {
return $profil->getModuleAccueilConfig($id_module)['preferences'][$preference];
}
}
class ProfilUpdateConfigAccueilOnModuleInBannerTest
extends ProfilUpdateConfigAccueilOnModuleInBannerTestCase {
/** @test */
public function profilRedirectShouldBeUpdated() {
$this->assertEquals(123,
$this->getPreferenceOfModule($this->_profil,
1, 'profil_redirect'));
}
}
class ProfilUpdateConfigAccueilOnModuleInBannerWithParentTest
extends ProfilUpdateConfigAccueilOnModuleInBannerTestCase {
protected function prepareProfile() {
$this->_profil->setParentProfil($this->fixture('Class_Profil', ['id' => 2])
->setBoiteLoginInBanniere(true));
}
/** @test */
public function profilRedirectShouldBeUpdatedInParent() {
$this->assertEquals(123,
$this->getPreferenceOfModule($this->_profil->getParentProfil(),
1, 'profil_redirect'));
}
}
class ProfilGetModuleAccueilConfigTest extends Storm_Test_ModelTestCase {
protected $_profil, $_parent, $_module_config;
public function setUp() {
parent::setUp();
$this->_parent = $this->fixture('Class_Profil', ['id' => 1])
->setBoiteLoginInBanniere(true);
$this->_profil = $this->fixture('Class_Profil', ['id' => 2,
'parent_profil' => $this->_parent]);
$this->_module_config = $this->_profil->getModuleAccueilConfig(1);
}
/** @test */
public function parentShouldHaveLoginInBanner() {
$this->assertTrue($this->_parent->getBoiteLoginInBanniere());
}
/** @test */
public function moduleDivisionShouldBeBanner() {
$this->assertEquals(Class_Profil::DIV_BANNIERE, $this->_module_config['division']);
}
}
class ProfilPreferenceAuthRegisterTest extends Storm_Test_ModelTestCase {
public function setUp() {
parent::setUp();
$this->portal = $this->fixture('Class_Profil',
['id' => 1,
'libelle' => 'portail']);
$this->youth = $this->fixture('Class_Profil',
['id' => 5,
'libelle' => 'jeunesse']);
$this->modules = new Class_Systeme_ModulesAppli();
}
/** @test */
public function withoutConfigurationYouthProfilPrefsShouldBeDefaultValues() {
$this->assertEquals($this->modules->getValeursParDefaut('auth','register'),
$this->youth->getCfgModulesPreferences('auth', 'register'));
}
/** @test */
public function withConfigInPortalYouthProfilPrefsShouldBePortalValues() {
$this->portal->setModulePreference('auth', 'register', 'register_confirm', 'I confirm');
$this->assertEquals('I confirm',
$this->youth->getModulePreference('auth', 'register', 'register_confirm'));
}
/** @test */
public function withConfigInYouthProfilPrefsShouldBeYouthValues() {
$this->portal->setModulePreference('auth', 'register', 'register_confirm', 'I confirm');
$this->youth->setModulePreference('auth', 'register', 'register_confirm', 'Youpi');
$this->assertEquals('Youpi',
$this->youth->getModulePreference('auth', 'register', 'register_confirm'));
}
}
class ProfilIsPortalTest extends Storm_Test_ModelTestCase {
/** @test */
public function profilWithIdOneIntShouldBePortal() {
$this->assertTrue($this->fixture('Class_Profil', ['id' => 1])->isPortail());
}
/** @test */
public function profilWithIdOneStringShouldBePortal() {
$this->assertTrue($this->fixture('Class_Profil', ['id' => '1'])->isPortail());
}
/** @test */
public function profilWithIdSevenIntShouldBePortal() {
$this->assertFalse($this->fixture('Class_Profil', ['id' => 7])->isPortail());
}
/** @test */
public function profilWithIdSevenStringShouldNotBePortal() {
$this->assertFalse($this->fixture('Class_Profil', ['id' => '7'])->isPortail());
}
}
?>