Newer
Older

llaffont
committed
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*

llaffont
committed
* 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).
*

llaffont
committed
* 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

llaffont
committed
*/
require_once 'AbstractControllerTestCase.php';
class JavaControllerWidthDefaultKiosqueTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$cfg_accueil = ['modules' => ['1' => ['division' => 1,
'type_module' => 'KIOSQUE']],
'options' => []];

llaffont
committed
$this->profil_cache = Class_Profil::getLoader()->newInstanceWithId(5345)
->setBrowser('opac')
->setLibelle('Profil cache')
->setCfgAccueil($cfg_accueil);

llaffont
committed
Class_Profil::setCurrentProfil(Class_Profil::getLoader()->newInstanceWithId(2)
->setLibelle('Accueil'));
$_SESSION['id_profil'] = 2;

llaffont
committed
$this->dispatch('java/kiosque?id_module=1&id_profil=5345', true);
}

llaffont
committed
/** @test */
public function sessionIdProfilShouldBeProfil2() {
$this->assertEquals(2, $_SESSION['id_profil']);
}

llaffont
committed
/** @test */
public function vueShouldDefaultsToDiaporama() {
$this->assertXPath('//script[contains(@src, "diaporama")]');
}

llaffont
committed
}
class JavaControllerCarrouselHorizontalTest extends AbstractControllerTestCase {
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
public function setUp() {
parent::setUp();
$this->fixture('Class_Profil',
['id' => 3,
'browser' => 'opac',
'libelle' => 'kiosque test',
'cfg_accueil' => ['modules' => ['1' => ['division' => 1,
'type_module' => 'KIOSQUE',
'titre' => 'My kiosk test',
'vue' => 'mycarousel_horizontal',
'preferences' => ['op_speed' => 400]]],
'options' => []]])
->beCurrentProfil();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('getNoticesByPreferences')
->answers([$this->fixture('Class_Notice',
['id' => 4,
'titre' => 'Madagascar',
'vignette' => 'http://thumbnail.com/madagascar.jpg'])]);
$this->dispatch('java/kiosque/id_module/1/titre/title+%2F+with+some+%2F+slashes/vue/mycarousel_horizontal', true);
}
/** @test */
public function titleShouldBeRemovedBecauseOfPossibleApacheMisconfigurationOfAllowEncodedSlashes() {
$this->assertXPath('//div[@class="jMyCarousel"]//a[@href="/recherche/viewnotice/id/4/tri/1/id_module/1/id_profil/3"]');
}
/** @test */
public function jMyCarouselShouldBeLoaded() {
$this->assertContains('jMyCarousel', $this->_response->getBody());
}
class JavaControllerWithKiosqueMurPageTest extends AbstractControllerTestCase {
$cfg_accueil = ['modules' => ['1' => ['division' => 1,
'type_module' => 'KIOSQUE',
'preferences' => ['style_liste' => 'mur',
'nb_notices' => 10,
'nb_analyse' => 50,
'only_img' => 0]]]];
Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil);
$this->dispatch('java/page/no/2/id_module/1', true);
}
/** @test */
public function firstControlShouldLinkToPageOne() {
$this->assertXPath('//div[@class="controls"]/a[1][contains(@href, "java/page/no/1/id_module/1")]', $this->_response->getBody());
}
/** @test */
public function lastControlShouldLinkToPageThree() {
$this->assertXPath('//div[@class="controls"]/a[2][contains(@href, "java/page/no/3/id_module/1")]');
}
class JavaControllerWithKiosqueMurAndPanierDeletedTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$cfg_accueil = ['modules' => ['1' => ['division' => 1,
'type_module' => 'KIOSQUE',
'preferences' => ['style_liste' => 'mur',
'id_panier' => 99999,
'nb_notices' => 10,
'nb_analyse' => 50,
'titre' => 'Mon panier']]]];
Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil);
$this->dispatch('/', true);
}
/** @test */
public function titreMonPanierShouldBeDisplayed() {
$this->assertXPathContentContains('//h1', 'Mon panier', $this->_response->getBody());
}
class JavaControllerKiosqueSlideShowWidthWrongParamsTest extends AbstractControllerTestCase {
$cfg_accueil = ['modules' => ['1' => ['division' => 1,
'type_module' => 'MENU']],
'options' => []];
$this->profil = Class_Profil::newInstanceWithId(5345, ['browser' => 'opac',
'libelle' => 'Profil cache',
'cfg_acceuil' => $cfg_accueil]);
/** @test */
public function vueShouldDefaultsToDiaporama() {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('getNoticesByPreferences')
->answers( $this->fixture('Class_Notice',
['id' => 1,
'titres' => 'Pomme']));
$this->dispatch('java/kiosque?id_module=1&id_profil=5345', true);
$this->assertXPathContentContains('//script', 'slideshow');
}
/** @test */
public function withNoRecordsFoundBodyShouldContainsNoRecordsFoundMessage() {
$this->dispatch('java/kiosque?id_module=1&id_profil=5345', true);
$this->assertXPathContentContains('//p', utf8_encode('Aucun document n\'a été trouvé'), $this->_response->getBody());
}
class JavaControllerKiosqueSlideShowWithRedirectSettingsTest extends AbstractControllerTestCase {
$this->fixture('Class_Profil',
['id' => 3,
'libelle' => 'modules',
'cfg_accueil' => ['modules' => ['1' => ['division' => '1',
'type_module' => 'KIOSQUE',
'preferences' => ['titre' => "My Kiosk",
'profil_redirect' => 123]]]]
])->beCurrentProfil();
$notice = Storm_Test_ObjectWrapper::mock();
$notice
->whenCalled('getId')
->answers(10)
->whenCalled('getTypeDoc')
->answers(Class_TypeDoc::LIVRE)
->whenCalled('getTitrePrincipal')
->answers('Programmers <br> Hell\'s "code"')
->whenCalled('fetchUrlVignette')
->answers('/img/hell_code.png')
->whenCalled('getClefAlpha')
->answers('PROGRAMMER_HELL');
$article = Storm_Test_ObjectWrapper::mock();
$article
->whenCalled('getId')
->answers(12)
->whenCalled('getTypeDoc')
->answers(Class_TypeDoc::ARTICLE)
->whenCalled('getTitrePrincipal')
->answers('Return of Harlock')
->whenCalled('fetchUrlVignette')
->answers('/img/harlock.png');
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('getNoticesByPreferences')
->answers([$notice, $article]);
}
protected function javaUrlWithPreferences($display_mode, $redirect_profil) {
return 'java/kiosque/id_module/3-1/titre/title+%2F+with+some+%2F+slashes/vue/' . $display_mode. '/id_profil/'.$redirect_profil;
}
public function datas() {
$xpath_title = 'concat("Programmers <br> Hell", "\'", "s ", \'"\', \'code\', \'"\')';
$url_notice = '/recherche/viewnotice/clef/PROGRAMMER_HELL/id/10/tri/1/id_module/3-1/id_profil/123';
return [
[
$this->javaUrlWithPreferences('slide_show', 3),
['//div[@id="theImages"]//a[@href="' . $url_notice . '"]',
'//div[@id="theImages"]//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
[$this->javaUrlWithPreferences('protoflow', 3),
['//div[@id="protoflow"]//a[@href="' . $url_notice . '"]',
'//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")][contains(@target, "_parent")]',
[$this->javaUrlWithPreferences('cube', 3),
['//div[@id="linksCube"]//a[@href="' . $url_notice . '"]',
'//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
[$this->javaUrlWithPreferences('diaporama', 3),
['//div[@class="slideshow"]//img[contains(@onclick, "' . $url_notice . '")]',
'//img[contains(@onclick, "id_profil/123")][contains(@onclick, "cms/articleview")][contains(@onclick, "id/23")]',
[$this->javaUrlWithPreferences('jcarousel', 3),
['//ul[@id="mycarousel"]//a[@href="' . $url_notice . '"]',
'//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
[$this->javaUrlWithPreferences('mycarousel_horizontal', 3),
['//div[@class="jMyCarousel"]//a[@href="' . $url_notice . '"]',
'//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
[$this->javaUrlWithPreferences('mycarousel_vertical', 3),
['//div[@class="jMyCarousel"]//a[@href="' . $url_notice . '"]',
'//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
/**
* @test
* @dataProvider datas
*/
public function contentFromUrlShouldSatisfyXPaths($url, $xpaths) {
$this->dispatch($url, true);
foreach($xpaths as $xpath)
$this->assertXPath($xpath, $this->_response->getBody());
}