Skip to content
Snippets Groups Projects
JavaControllerTest.php 11.6 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
 * 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).
 *
Laurent's avatar
Laurent committed
 * 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
Laurent's avatar
Laurent committed
 * along with BOKEH; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
class JavaControllerWidthDefaultKiosqueTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $cfg_accueil = ['modules' => ['1' => ['division' => 1,
                                          'type_module' => 'KIOSQUE']],
                    'options' =>  []];
Patrick Barroca's avatar
Patrick Barroca committed
    $this->profil_cache = Class_Profil::getLoader()->newInstanceWithId(5345)
                                                   ->setBrowser('opac')
                                                   ->setLibelle('Profil cache')
                                                   ->setCfgAccueil($cfg_accueil);
Patrick Barroca's avatar
Patrick Barroca committed
    Class_Profil::setCurrentProfil(Class_Profil::getLoader()->newInstanceWithId(2)
                                   ->setLibelle('Accueil'));
    $_SESSION['id_profil'] = 2;
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('java/kiosque?id_module=1&id_profil=5345', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function sessionIdProfilShouldBeProfil2() {
    $this->assertEquals(2, $_SESSION['id_profil']);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function vueShouldDefaultsToDiaporama() {
    $this->assertXPath('//script[contains(@src, "diaporama")]');
  }
class JavaControllerCarrouselHorizontalTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  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 {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
gloas's avatar
gloas committed

Patrick Barroca's avatar
Patrick Barroca committed
    $cfg_accueil = ['modules' => ['1' => ['division' => 1,
                                          'type_module' => 'KIOSQUE',
                                          'preferences' =>  ['style_liste' => 'mur',
                                                             'nb_notices' => 10,
                                                             'nb_analyse' => 50,
                                                             'only_img' => 0]]]];
Patrick Barroca's avatar
Patrick Barroca committed
    Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('java/page/no/2/id_module/1', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstControlShouldLinkToPageOne() {
    $this->assertXPath('//div[@class="controls"]/a[1][contains(@href, "java/page/no/1/id_module/1")]', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function lastControlShouldLinkToPageThree() {
    $this->assertXPath('//div[@class="controls"]/a[2][contains(@href, "java/page/no/3/id_module/1")]');
  }


class JavaControllerWithKiosqueMurAndPanierDeletedTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  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 {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    Class_Notice::beVolatile();
Patrick Barroca's avatar
Patrick Barroca committed
    $cfg_accueil = ['modules' => ['1' => ['division' => 1,
                                          'type_module' => 'MENU']],
                    'options' =>  []];
Patrick Barroca's avatar
Patrick Barroca committed
    $this->profil = Class_Profil::newInstanceWithId(5345, ['browser' => 'opac',
                                                           'libelle' => 'Profil cache',
                                                           'cfg_acceuil' => $cfg_accueil]);
Patrick Barroca's avatar
Patrick Barroca committed
    }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @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');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @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 {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    $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();
Patrick Barroca's avatar
Patrick Barroca committed
    $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');
Patrick Barroca's avatar
Patrick Barroca committed
    $article = Storm_Test_ObjectWrapper::mock();
    $article
      ->whenCalled('getId')
      ->answers(12)
Patrick Barroca's avatar
Patrick Barroca committed
      ->whenCalled('getTypeDoc')
      ->answers(Class_TypeDoc::ARTICLE)
Patrick Barroca's avatar
Patrick Barroca committed
      ->whenCalled('getTitrePrincipal')
      ->answers('Return of Harlock')
Patrick Barroca's avatar
Patrick Barroca committed
      ->whenCalled('getChamp856b')
      ->answers(23)
Patrick Barroca's avatar
Patrick Barroca committed
      ->whenCalled('getClefAlpha')
      ->answers('HARLOCK')
Patrick Barroca's avatar
Patrick Barroca committed
      ->whenCalled('fetchUrlVignette')
      ->answers('/img/harlock.png');
Patrick Barroca's avatar
Patrick Barroca committed
    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
      ->whenCalled('getNoticesByPreferences')
      ->answers([$notice, $article]);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  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;
  }
Patrick Barroca's avatar
Patrick Barroca committed
  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),
Patrick Barroca's avatar
Patrick Barroca committed
             ['//div[@id="theImages"]//a[@href="' . $url_notice . '"]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//div[@id="theImages"]//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a/img[@title=' . $xpath_title . ']' ]],
Patrick Barroca's avatar
Patrick Barroca committed
            [$this->javaUrlWithPreferences('protoflow', 3),
             ['//div[@id="protoflow"]//a[@href="' . $url_notice . '"]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")][contains(@target, "_parent")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a/img[@alt=' . $xpath_title . ']']],
Patrick Barroca's avatar
Patrick Barroca committed
            [$this->javaUrlWithPreferences('cube', 3),
             ['//div[@id="linksCube"]//a[@href="' . $url_notice . '"]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a/img[@title=' . $xpath_title . ']' ]],
Patrick Barroca's avatar
Patrick Barroca committed
            [$this->javaUrlWithPreferences('diaporama', 3),
             ['//div[@class="slideshow"]//img[contains(@onclick, "' . $url_notice . '")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//img[contains(@onclick, "id_profil/123")][contains(@onclick, "cms/articleview")][contains(@onclick, "id/23")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//img[@title=' . $xpath_title . ']' ]],
Patrick Barroca's avatar
Patrick Barroca committed
            [$this->javaUrlWithPreferences('jcarousel', 3),
             ['//ul[@id="mycarousel"]//a[@href="' . $url_notice . '"]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a/img[@title=' . $xpath_title . ']' ]],
Patrick Barroca's avatar
Patrick Barroca committed
            [$this->javaUrlWithPreferences('mycarousel_horizontal', 3),
             ['//div[@class="jMyCarousel"]//a[@href="' . $url_notice . '"]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a/img[@title=' . $xpath_title . ']' ]],
Patrick Barroca's avatar
Patrick Barroca committed
            [$this->javaUrlWithPreferences('mycarousel_vertical', 3),
             ['//div[@class="jMyCarousel"]//a[@href="' . $url_notice . '"]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a[contains(@href, "id_profil/123")][contains(@href, "cms/articleview")][contains(@href, "id/23")]',
Patrick Barroca's avatar
Patrick Barroca committed
              '//a/img[@title=' . $xpath_title . ']' ]]
    ];
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /**
   * @test
   * @dataProvider datas
   */
  public function contentFromUrlShouldSatisfyXPaths($url, $xpaths) {
    $this->dispatch($url, true);
    foreach($xpaths as $xpath)
      $this->assertXPath($xpath, $this->_response->getBody());
  }