<?php /** * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. * * BOKEH 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). * * BOKEH 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 BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AbstractControllerTestCase.php'; class JavaControllerWidthDefaultKiosqueTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); $cfg_accueil = ['modules' => ['1' => ['division' => 1, 'type_module' => 'KIOSQUE']], 'options' => []]; $this->profil_cache = Class_Profil::getLoader()->newInstanceWithId(5345) ->setBrowser('opac') ->setLibelle('Profil cache') ->setCfgAccueil($cfg_accueil); Class_Profil::setCurrentProfil(Class_Profil::getLoader()->newInstanceWithId(2) ->setLibelle('Accueil')); $_SESSION['id_profil'] = 2; $this->dispatch('java/kiosque?id_module=1&id_profil=5345', true); } /** @test */ public function sessionIdProfilShouldBeProfil2() { $this->assertEquals(2, $_SESSION['id_profil']); } /** @test */ public function vueShouldDefaultsToDiaporama() { $this->assertXPath('//script[contains(@src, "diaporama")]'); } } class JavaControllerCarrouselHorizontalTest extends AbstractControllerTestCase { 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 { public function setUp() { parent::setUp(); $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 { public function setUp() { parent::setUp(); Class_Notice::beVolatile(); $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 { public function setUp() { parent::setUp(); $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('getChamp856b') ->answers(23) ->whenCalled('getClefAlpha') ->answers('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")]', '//a/img[@title=' . $xpath_title . ']' ]], [$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")]', '//a/img[@alt=' . $xpath_title . ']']], [$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")]', '//a/img[@title=' . $xpath_title . ']' ]], [$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")]', '//img[@title=' . $xpath_title . ']' ]], [$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")]', '//a/img[@title=' . $xpath_title . ']' ]], [$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")]', '//a/img[@title=' . $xpath_title . ']' ]], [$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")]', '//a/img[@title=' . $xpath_title . ']' ]] ]; } /** * @test * @dataProvider datas */ public function contentFromUrlShouldSatisfyXPaths($url, $xpaths) { $this->dispatch($url, true); foreach($xpaths as $xpath) $this->assertXPath($xpath, $this->_response->getBody()); } }