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

Ghislain Loas
committed
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'AbstractControllerTestCase.php';
abstract class BibControllerWithZoneTestCase extends AbstractControllerTestCase {
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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'));
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 {
/** @test */
public function bibListShouldBeVisible() {
$this->assertXPathContentContains("//table//td[@class='listeTitre']",
"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());
}
abstract class BibControllerMapViewTest extends BibControllerWithZoneTestCase {
$this->fixture('Class_Profil',
['id' => 3,
'libelle' => 'Annecy']);
}
class BibControllerMapViewWithProfilTest extends BibControllerMapViewTest {
$aff_zone = ['profilID' => '3',
'libelle' => 'Annecy',
'posX' => 2,
'posY' => 5,
'posPoint' => 'droite'];
$this->bib_annecy->setAffZone(ZendAfi_Filters_Serialize::serialize($aff_zone));
/** @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, 'index/index/id_profil/3')]", "Annecy", $this->_response->getBody());
}
}
class BibControllerMapViewWithoutProfilTest extends BibControllerMapViewTest {
$aff_zone = ['profilID' => '',
'libelle' => 'Annecy',
'posX' => 2,
'posY' => 5,
'posPoint' => 'droite'];
$this->bib_annecy->setAffZone(ZendAfi_Filters_Serialize::serialize($aff_zone));
/** @test */
public function bibAnnecyShouldBeVisibleOnMap() {
$this->assertXPathContentContains("//span[contains(@onclick, 'bibview/id/4')]", "Annecy", $this->_response->getBody());
}
}
class BibControllerBibViewAnnecyTest extends BibControllerWithZoneTestCase {
$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();
$this->_mock_sql
->whenCalled('fetchOne')
->answers('');
/** @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() {
$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');
$this->assertXPathContentContains('//a[contains(@href, "/cms/articleview/id/5")]',
'Retour');
}
/** @test */
public function withUrlRetourCmsOnlyShouldNotBeAccepted() {
$this->dispatch('bib/bibview/id/4?retour=cms');
$this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]',
'Retour');
}
}
class BibControllerBibViewInexistantTest extends BibControllerWithZoneTestCase {
/** @test */
public function responseShouldRedirectToIndex() {
$this->assertRedirectTo('/opac/bib/index');
}

Ghislain Loas
committed
abstract class BibControllerSelectionTestCase extends AbstractControllerTestCase {
unset($_REQUEST['geo_zone']);
unset($_REQUEST['geo_bib']);
unset($_SESSION['selection_bib']);

Ghislain Loas
committed
$this->fixture('Class_Zone',
['id' => 1,
'libelle' => 'Africa']);

Ghislain Loas
committed
$this->fixture('Class_Zone',
['id' => 2,
'libelle' => 'Europe']);
$cairo = $this->fixture('Class_Bib',
['id' => 1,
'id_site' => 1,
'libelle' => 'Cairo',
'id_zone' => 1,
'visibilite' => 2]);

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

Ghislain Loas
committed
$paris = $this->fixture('Class_Bib',
['id' => 3,
'id_site' => '2',
'libelle' => 'Paris',
'visibilite' => 2,
'id_zone' => 2]);
}
class BibControllerBibSelectionWithEmptySessionTest extends BibControllerSelectionTestCase {
$_SERVER['HTTP_REFERER'] = 'http://mybokeh.fr/index/index/profil/1';
$this->dispatch('bib/selection', true);
}

Ghislain Loas
committed
/** @test */
public function pageShouldBeHtml5Valid() {
$this->assertHTML5($this->_response->getBody());
}

Ghislain Loas
committed
/** @test */
public function cairoShouldBeInBibList() {
$this->assertXPathContentContains('//li/span', 'Cairo');
}

Ghislain Loas
committed
/** @test */
public function casablancaShouldBeInBibList() {
$this->assertXPathContentContains('//li/span', 'Casablanca');
}
/** @test */
public function inputTypeSubmitShouldBePresent() {
$this->assertXPath('//form//input[@type="submit"]');
}

Ghislain Loas
committed
}
class BibControllerBibSelectionWithBibsIdsInSessionTest extends BibControllerSelectionTestCase {
public function setUp() {
parent::setUp();
$this->_session->id_bibs = [1, 2];
$this->dispatch('bib/selection', true);
}

Ghislain Loas
committed
/** @test */
public function formActionShouldBeBibSelection() {
$this->assertXPath('//form[contains(@action, "bib/selection")]');
}
/** @test */
public function cairoShouldBeChecked() {
$this->assertXPath('//li/input[@checked="checked"][@value="1"]', $this->_response->getBody());
}

Ghislain Loas
committed
/** @test */
public function casablancaShouldBeChecked() {
$this->assertXPath('//li/input[@checked="checked"][@value="2"]');
}

Ghislain Loas
committed
/** @test */
public function parisShouldNotBeChecked() {
$this->assertNotXPath('//li/input[@checked="checked"][@value="3"]');
}

Ghislain Loas
committed
}
class BibControllerBibSelectionPostDispatchTest extends BibControllerSelectionTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_REFERER'] = 'http://mybokeh.org/recherche/simple/expressionRecherche/pomme/bib_select/2';
$this->postDispatch('bib/selection', ['update_bib_select' => 1, 'bib_select' => [1, 2]]);
/** @test */
public function shouldRedirectToRefererWithNewParams() {
$this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/bib_select/1%2C2');
}
public function sessionShouldContainsCasablancaAndCairo() {
$this->assertEquals([1, 2] , $this->_session->id_bibs);
}
}
class BibControllerBibSelectionUnselectPostDispatch extends BibControllerSelectionTestCase {
$_SERVER['HTTP_REFERER'] = 'http://mybokeh.org/recherche/simple/expressionRecherche/pomme/bib_select/2';
$this->postDispatch('bib/selection', ['update_bib_select' => 1]);
}
/** @test */
public function shouldRedirectToRefererWithNoNewParams() {
$this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme');
}
/** @test */
public function sessionShouldNotContainsCasablancaAndCairo() {
$this->assertEquals([] , $this->_session->id_bibs);
class BibControllerBibSelectionWithProfilIdParamTest extends BibControllerSelectionTestCase {
public function setUp() {
parent::setUp();
Class_Profil::setCurrentProfil(Class_Profil::find(1));
$this->_session->id_bibs = [1, 2];
$this->dispatch('opac/index/index/id_profil/1', true);
}
/** @test */
public function sessionSlectionBibShouldNotExist() {
$this->assertEquals([1,2], $this->_session->id_bibs);
}
class BibControllerBibSelectionWithProfilHasChangedTest extends BibControllerSelectionTestCase {
public function setUp() {
parent::setUp();
Class_Profil::setCurrentProfil(Class_Profil::find(1));
$this->_session->id_bibs = [1, 2];
$this->dispatch('opac/index/index/id_profil/2', true);
}
/** @test */
public function sessionSlectionBibShouldNotExist() {
$this->assertEmpty($this->_session->id_bibs);
}