Skip to content
Snippets Groups Projects
RechercheControllerTest.php 102 KiB
Newer Older
llaffont's avatar
llaffont committed
<?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
llaffont's avatar
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).
 *
Laurent's avatar
Laurent committed
 * BOKEH is distributed in the hope that it will be useful,
llaffont's avatar
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
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
llaffont's avatar
llaffont committed
 */
require_once 'AbstractControllerTestCase.php';

abstract class RechercheControllerNoticeTestCase extends AbstractControllerTestCase {
  protected $_storm_default_to_volatile = true;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_CodifAuteur',
                   ['id' => 123,
                    'libelle' => 'Bernard Génin']);

    $this->fixture('Class_CodifCentreInteret',
                   ['id' => 2,
                    'libelle' => 'marionettes']);

    $this->fixture('Class_CodifGenre',
                   ['id' => 1,
                    'libelle' => 'spectacle']);

    $this->fixture('Class_CodifTags',
                   ['id' => 3,
                    'libelle' => 'enfants']);

    $this->fixture('Class_CodifPcdm4',
                   ['id' => 4,
                    'libelle' => 'rock']);

    $this->fixture('Class_CodifDewey',
                   ['id' => 2,
                    'id_dewey' => 2,
                    'libelle' => 'enfants']);



    $this->mock_sql = $this->mock()
                     ->whenCalled('execute')->answers('')
                     ->whenCalled('fetchOne')->answers(null)
                     ->whenCalled('fetchAll')->answers([ [1, ''] ]);
    Zend_Registry::set('sql', $this->mock_sql);


Patrick Barroca's avatar
Patrick Barroca committed
    Class_Notice::beVolatile();
    Class_Exemplaire::beVolatile();
    $this->notice = Class_Notice::newInstanceWithId(345,
                                                    ['annee' => 2002,
                                                     'editeur' => 'Gallimard',
                                                     'isbn' => '1-234-56789-0',
                                                     'type_doc' => Class_TypeDoc::LIVRE,
                                                     'url_vignette' => 'NO',
                                                     'url_image' => 'NO',
                                                     'facettes' => 'A123 F2 G1 P4 Y2 B1 Lfre M1 Z3 D1',
                                                     'date_creation' => '2013-12-31',
                                                     'unimarc' => "01570nam0 2200325   450 0010007000000100033000070200017000400210027000571000041000841010008001251020007001331050018001401060006001582000106001642100075002702150044003452250023003893000125004123000020005373000137005573300265006943450018009594100051009775120027010286060033010556060060010886760012011487000045011608010039012052218529  a2-86642-370-4bbr.d8,95 EUR  aFRb00347575  aFRbDLE-20031204-51138  a20031107d2003    m  h0frey0103    ba| afre  aFR  ay   z   000y|  ar1 aCinéma d'animationbTexte impriméedessin animé, marionnettes, images de synthèsefBernard Génin  a[Paris]c\"Cahiers du cinéma\"cSCEREN-CNDPdcop. 2003gimpr. en Italie  a95 p.cill., couv. ill. en coul.d19 cm2 aLes petits cahiers  aLa couv. porte en plus : \"du crayon à l'ordinateur, pour ou contre Disney, Europe-Japon : le dessin animé aujourd'hui\"  aBibliogr. p. 93  aSCEREN = Services, cultures, éditions, ressources pour l'éducation nationale. CNDP = Centre national de documentation pédagogique  aPrésente un historique du cinéma d'animation, un survol des différentes productions nationales à travers le monde (Etats-Unis, Japon, France, Canada), les techniques du volume animé, l'image de synthèse, mais aussi l'oeuvre de Disney et le film d'auteur.  b9782866423704 032525826tLes Petits cahiers (Paris)x1633-90531 aLe cinéma d'animation| 31053394aAnimation (cinéma)| 31031625aDessins animés32195497xHistoire et critique  a791.431 |32547161aGéninbBernardf1946-....4070 0aFRbBNFc20031107gAFNOR2intermrc"])
      ->setExemplaires([Class_Exemplaire::getLoader()->newInstanceWithId(34)
                        ->setIdBib('456')
                        ->setIdOrigine('12')
                        ->setCodeBarres('12256663233656')
                        ->setSigbExemplaire(Storm_Test_ObjectWrapper::mock()
                                            ->whenCalled('isReservable')
                                            ->answers(true))]);

  }
class RechercheControllerPrintTest extends RechercheControllerNoticeTestCase {
  public function setUp() {

    parent::setUp();
  	$this->fixture('Class_ModeleFusion', ['id' => 1,
																				'nom' => 'article',
																				'contenu' => '<p><h1> {notice.titre_principal}</h1> <div>{notice.article.contenu} </div>
{notice.avis[<p>{avis}</p>]}
</p>',
                                          'profil_ids' => '3;4',
                                          'type' =>'Notice_View']);
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('');

  }

  /** @test */
  public function pageOnProfilOneShouldNotContainsPrintLink() {
    $this->home_profil = $this->fixture('Class_Profil',
                                        ['id'=> 1,
                                         'libelle'=> 'HomePage']);
    Class_Profil::setCurrentProfil($this->home_profil);

    $this->dispatch('/recherche/viewnotice/id/'.$this->notice->getId());
    $this->assertNotXPathContentContains('//div', 'Imprimer', $this->_response->getBody());
  }

  /** @test */
  public function pageOnProfilThreeShouldContainsPrintLink() {
    $this->home_profil = $this->fixture('Class_Profil',
                                        ['id'=> 3,
                                         'libelle'=> 'HomePage']);
        Class_Profil::setCurrentProfil($this->home_profil);
    $this->dispatch('/recherche/viewnotice/id/'.$this->notice->getId());
    $this->assertXPathContentContains('//div', 'Imprimer', $this->_response->getBody());
  }

}
class RechercheControllerReseauTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    ZendAfi_View_Helper_ShareUrl::setDefaultWebClient(Storm_Test_ObjectWrapper::mock()
                                                      ->whenCalled('open_url')
                                                      ->answers(false));
    parent::setUp();
    $this->dispatch(sprintf('recherche/reseau/id_notice/%d/type_doc/1',
                            $this->notice->getId()),
                    true);
  }


  public function tearDown() {
    parent::tearDown();
    ZendAfi_View_Helper_ShareUrl::setDefaultWebClient(null);
  }


  /** @test */
  public function getResauShouldContainsTwitterGif() {
    $this->assertXPath('//img[contains(@src, "twitter.gif")]');
  }


  /** @test */
  public function getResauShouldContainsTwitterLink() {
    $this->assertContains("$.getScript('/social-network/share/id_notice/345/type_doc/1/on/twitter/url",
                          $this->_response->getBody());
  }
class RechercheControllerViewNoticeBabelthequeTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutBabelthequeJSShouldNotBeLoaded() {
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('');
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertNotXpath('//script[contains(@src, "babeltheque.js")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withBabelthequeJSShouldBeLoadedWithRightId() {
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('http://www.babeltheque.com/bw_666.js');
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertXpath('//script[contains(@src, "babeltheque.js?bwid=666")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeShouldNotHaveTome() {
    $this->notice->setClefChapeau("test")->save();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertNotXPathContentContains('//div[@class="entete_notice"]',"Voir tous les tomes");
  }
class RechercheControllerPagerTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_notice;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $records = array_map(function($i) { return [$i, ''];}, range(1, 45) );
    $this->mock_sql
Patrick Barroca's avatar
Patrick Barroca committed
                     ->whenCalled('fetchAll')
                     ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE) order by (MATCH(alpha_titre) AGAINST(' POMME') * 1.5) + (MATCH(alpha_auteur) AGAINST(' POMME')) desc",
                            true,
                            false)
                     ->answers($records)
Patrick Barroca's avatar
Patrick Barroca committed
                     ->beStrict();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_notice = $this->fixture('Class_Notice', ['id' => 34, 'clef_oeuvre' => '']);
    $this->onLoaderOfModel('Class_Notice')
         ->whenCalled('find')
         ->with(34)
         ->answers($this->_notice)
         ->whenCalled('findAllByIds')
         ->with(range(1, 45), 10, null)
Patrick Barroca's avatar
Patrick Barroca committed
         ->answers([$this->_notice])
         ->whenCalled('findAllByIds')
         ->with(range(1, 45), 50, null)
Patrick Barroca's avatar
Patrick Barroca committed
         ->answers([$this->_notice])
         ->whenCalled('findAllByIds')
         ->with(range(1, 45), 7, null)
Patrick Barroca's avatar
Patrick Barroca committed
         ->answers([$this->_notice])
Patrick Barroca's avatar
Patrick Barroca committed
         ->beStrict();
  }


  /** @test */
  public function urlPage2ShouldBeWithListeFormatParameter() {
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4', true);
    $this->assertXPath('//a[contains(@href, "/liste_format/4")][contains(@href,"/page/2")]',$this->_response->getBody());
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSize10PageFiveShouldBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3', true);
    $this->assertXPath('//a[contains(@href,"/page/5")]',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSize100PageFiveShouldFallbackToMaximumPageSize50() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/100', true);
    $this->assertXPath('//a[contains(@href,"/page_size/50")]',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSize10PageSixShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3', true);
    $this->assertNotXPath('//a[contains(@href,"/page/6")]',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function urlWithPageSizeSevenShouldCallFindAllWithPageSize() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7', true);
    $this->assertXPath('//a[contains(@href, "/page_size/7")][contains(@href,"/page/2")]',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSizeSevenPageSevenShouldBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7', true);
    $this->assertXPath('//a[contains(@href,"/page/7")]',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSizeSevenPageHeightShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7', true);
    $this->assertNotXPath('//a[contains(@href,"/page/8")]',$this->_response->getBody());
  }
class RechercheControllerViewNoticeWithPreferencesTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_web_analytics_client;

  public function setUp() {
    parent::setUp();

    $time_source = new TimeSourceForTest('2013-12-27 09:00:00');
    Class_Notice::setTimeSource($time_source);

    Class_AdminVar::newInstanceWithId('FACETTE_GENRE_LIBELLE', ['valeur' => 'GENRES']);
    Class_AdminVar::newInstanceWithId('FACETTE_DEWEY_LIBELLE', ['valeur' => 'Classification']);
    Class_AdminVar::newInstanceWithId('FACETTE_PCDM4_LIBELLE', ['valeur' => 'Classification']);

    $this->notice->setClefChapeau('Gallimard serie');
    $this->notice->set_subfield('461','t', 'Gallimard serie');
    $preferences = [
                    'barre_nav' => 'Document',
                    'entete' =>"ABCDEFGIKLMNOPRSTtYZ8v9",
                    'onglets' =>  [
                                   'detail' =>          ['titre' => 'Details',      'aff' =>  '1', 'ordre' => 1, 'largeur' => 10],
                                   'avis' =>            ['titre' => 'avis',         'aff' =>  '1', 'ordre' => 2, 'largeur' => 10],
                                   'exemplaires' =>   ['titre' => 'exemplaires',  'aff' =>  '2', 'ordre' => 3, 'largeur' => 10],
                                   'resume' =>          ['titre' => 'resume',       'aff' =>  '2', 'ordre' => 4, 'largeur' => 10],
                                   'tags' =>            ['titre' => 'tags',         'aff' =>  '2', 'ordre' => 5, 'largeur' => 10],
                                   'biographie' =>      ['titre' => 'biographie',   'aff' =>  '2', 'ordre' => 6, 'largeur' => 10],
                                   'similaires' =>      ['titre' => 'similaires',   'aff' =>  '2', 'ordre' => 7, 'largeur' => 10],
                                   'bibliographie' => ['titre' => 'bibliographie','aff' =>  '3', 'ordre' => 7, 'largeur' => 10],
                                   'morceaux' =>        ['titre' => 'morceaux',     'aff' =>  '3', 'ordre' => 8, 'largeur' => 10],
                                   'bandeAnnonce' =>    ['titre' => 'bande annonce','aff' =>  '3', 'ordre' => 9, 'largeur' => 10],
                                   'photos' =>          ['titre' => 'photos',       'aff' =>  '3', 'ordre' => 14, 'largeur' =>  10],
                                   'videos' =>          ['titre' => 'videos',       'aff' =>  '3', 'ordre' => 11, 'largeur' =>  10],
                                   'resnumeriques' => ['titre' => 'ressources n', 'aff' =>  '3', 'ordre' => 12, 'largeur' =>  10],
                                   'babeltheque' =>   ['titre' => 'babeltheque',  'aff' =>  '3', 'ordre' => 13, 'largeur' =>  10],
                                   'frbr' =>            ['titre' => 'frbr',         'aff' =>  '0', 'ordre' => 10, 'largeur' =>  10],
                                   'serie' =>         ['titre' => 'serie',        'aff' =>  '0', 'ordre' => 11, 'largeur' =>  10]],
                    'boite' =>  null];

    Class_Profil::getCurrentProfil()
      ->setBarreNavOn(true)
      ->setCfgModules(['recherche' => ['viewnotice1' => $preferences]]);

    Class_TypeDoc::find(Class_TypeDoc::LIVRE)->setLabel('livres');

    $this->_web_analytics_client = Storm_Test_ObjectWrapper::mock()
      ->whenCalled('trackEvent')
      ->answers(true);
    ZendAfi_Controller_Action_Helper_TrackEvent::setDefaultWebAnalyticsClient($this->_web_analytics_client);

    $this->dispatch('recherche/viewnotice/id/345', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test **/
  public function enteteShouldDisplayNouveaute(){
    $this->assertXPathContentContains('//dl//dt[contains(@class,"nouveaute")]/following-sibling::dd','Oui',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test **/
  public function noticeHtmlShouldContainsDivNoticeFlagWithSpanNouveaute(){
    $this->assertXpath('//div[@class="flags_notice"]//span[@class="nouveaute"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayAnnee2002() {
    $this->assertXPathContentContains('//dl//dd', '2002');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayDocumentDeLaMemeSerie() {
    $this->assertXPathContentContains('//div//a[contains(@href,"Gallimard+serie")]', 'Voir tous les tomes de Gallimard serie',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayDocumentLinkOrderByDateNouveaute() {
    $this->assertXPathContentContains('//div//a[contains(@href,"Gallimard+serie/tri/date_creation+desc")]', 'Voir tous les tomes de',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayDtEditeur() {
    $this->assertXPathContentContains('//dl//dt', 'Editeur');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayEditeurGallimard() {
    $this->assertXPathContentContains('//dl//dd', 'Gallimard');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayRebondAuteurBernardGenin() {
    $this->assertXPathContentContains('//dl//dd[contains(@class, "first")]/a[contains(@href, "recherche/simple/id/345/code_rebond/A123")]', 'Bernard Génin (Auteur)', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayRebondInterestMarionettes() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/F2")]', 'marionettes', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayRebondTagEnfants() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/Z3")]', 'enfants', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayRebondPcdm4Rock() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/P4")]', 'rock', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayRebondGenreSpectacle() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/G1")]', 'spectacle');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteLibelleGenreShouldBeGENRES() {
    $this->assertXPathContentContains('//dl//dt', 'GENRES');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function enteteShouldDisplayDtDdCollectionWithClassSecond() {
    $this->assertXPathContentContains('//dl//dt[contains(@class, "second")]', 'Collection',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function detailsBlocShouldHaveIdBloc_345_0() {
    $this->assertXPathContentContains('//div[@id="bloc_345_0"][@class="notice_bloc_titre"]', 'Details');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function javascriptShouldOpenFirstBlocDetails() {
    $this->assertXPathContentContains('//script',
                                      "infos_bloc(\"bloc_345_0\",'1-234-56789-0','detail',0,'',0, 'http://localhost".BASE_URL."/noticeajax/detail/id/345')",$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function javascriptShouldOpenSecondBlocAvis() {
    $this->assertXPathContentContains('//script',
                                      "infos_bloc(\"bloc_345_1\",'1-234-56789-0','avis',0,'',1, 'http://localhost".BASE_URL."/noticeajax/avis/id/345')");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noJavascriptShouldOpenThirdBlocExemplaires() {
    $this->assertNotXPathContentContains('//script', "infos_bloc(\"bloc_345_2\"",$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function bibliographieOngletShouldHaveIdSet345_onglet_0() {
    $this->assertXPathContentContains('//div[@id="set345_onglet_0"][@class="titre_onglet"]', 'bibliographie');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function javascriptShouldOpenFirstOngletBibliographie() {
    $this->assertXPathContentContains('//script',
                                      "infos_onglet('set345_onglet_0','1-234-56789-0','bibliographie',0,'',0, 'http://localhost".BASE_URL."/noticeajax/bibliographie/id/345')");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function videosOngletShouldHaveIdSet345_onglet_3() {
    $this->assertXPathContentContains('//div[@id="set345_onglet_3"][@class="titre_onglet"]', 'videos',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noJavascriptShouldOpenSecondOnglet() {
    $this->assertNotXPathContentContains('//script', "infos_onglet('set345_onglet_1')");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function linkReserverShouldBeDisplayed() {
    $this->assertXPathContentContains('//a[contains(@onclick, "openDialogExemplaires")]', 'Réserver');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function vignetteShouldBeGenerated() {
    $this->assertXPath('//div[@class="nothumbnail type_doc_1"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function vignetteForZoomShouldNotBeGenerated() {
    $this->assertNotXPath('//a[@id="vignette"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function divViewNoticeShouldHaveClassTypeDocOne() {
    $this->assertXPath('//div[@class="view_notice type_doc_1"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function tabTitleShouldContainTitle() {
    $this->assertXPath('//div[contains(@class, "titre_onglet") and h2]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldBeHTML5Valid() {
    $this->assertHTML5();
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /**
   * @test
   */
  public function trackEventShouldContainsNoticeTitreAuteur() {
    $this->assertEquals(['recherche',
                         'notice',
                         '"titre: Gallimard serie<br /> Cinéma d\'animation","auteur: Bernard Génin","editeur: Gallimard","tome: ","support: livres","ressource: http://localhost'.BASE_URL.'/recherche/viewnotice/id/345"',
                         345],
                        $this->_web_analytics_client->getAttributesForLastCallOn('trackEvent'));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /**
   * @test
   * @group pagetitles
   */
  public function barreNavShouldContainsCinemaAnimation() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'Cinéma d\'animation');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function deweyAndPcdm4WithSameLibelleShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="entete_notice"]//dt[contains(@class, "classification")]', 'Classification');
    $this->assertXPathContentContains('//div[@class="entete_notice"]//dt[contains(@class, "classification")]/following::dd', 'Philosophie et disciplines connexes');
    $this->assertXPathContentContains('//div[@class="entete_notice"]//dt[contains(@class, "classification")]', 'Classification');
    $this->assertXPathContentContains('//div[@class="entete_notice"]//dt[contains(@class, "classification")]/following::dd', 'rock');
  }
}
Patrick Barroca's avatar
Patrick Barroca committed
class RechercheControllerViewNoticeTest extends RechercheControllerNoticeTestCase {
  public function setUp() {
    parent::setUp();
    $this->dispatch('recherche/viewnotice/id/345', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titleShouldBeDisplayed() {
    $this->assertXPathContentContains('//h1',
                                      array_first(explode('<br />', $this->notice->getTitrePrincipal())),
                                      $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsOnlyTwoH1() {
    $this->assertXPathCount('//h1', 2, $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsH1WithTitleAndAuthor() {
    $this->assertXPath('//h1//span[contains(text(), "Cinéma d\'animation")][following-sibling::span[text()="Bernard Génin"]]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function tagReseauSociauxShouldBePresent() {
    $this->assertXPath('//div[@id="reseaux-sociaux"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function headShouldContainsRechercheJS() {
    $this->assertXPath('//head//script[contains(@src,"public/opac/js/recherche.js")]');
  }

class RechercheControllerViewNoticeMetasTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_Notice',
                   ['id' => 345,
                    'titre_principal' => 'Cinéma d\'animation<br/>3D',
                    'auteur_principal' => 'Bernard Génin',
                    'annee' => 2002,
                    'editeur' => 'Gallimard',
                    'isbn' => '1-234-56789-0',
                    'type_doc' => Class_TypeDoc::LIVRE,
                    'url_vignette' => 'http://linux.org',
                    'url_image' => 'http://linux.org',
                    'facettes' => 'A123 F2 G1 P4 Y2 B1 Lfre M1 Z3 D1',
                    'date_creation' => '2013-12-31']);

    $this->dispatch('recherche/viewnotice/id/345', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainTitleMeta() {
    $this->assertXPathContentContains('//meta[@property="og:title"]/@content', 'Cinéma d\'animation br/ 3D - Bernard Génin', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainImageMeta() {
    $this->assertXPathContentContains('//meta[@property="og:image"]/@content', 'http://linux.org');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainDescriptionMeta() {
    $this->assertXPath('//meta[@property="og:description"]/@content');
  }
Laurent's avatar
Laurent committed

class RechercheControllerVignetteTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('recherche/vignette/id_notice/345', true);
  }

  /** @test */
  public function responseShouldRedirectToVignetteUrl() {
    $this->assertContains('/temp/vignettes_titre/notice_345.png',
                          $this->getResponseLocation());
  }
class RechercheControllerVignetteEmptyTest extends RechercheControllerNoticeTestCase {
  protected $_storm_default_to_volatile = true;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    $article = $this->fixture('Class_Article',
                   ['id' => 123,
                    'titre' => 'An article with img',
                    'contenu' => 'This article should contains an image like this <img src="/images/articles/img.png" />']);
    $article->index();
    $this->dispatch('recherche/vignette/id_notice/1', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function responseShouldRedirectToVignetteUrl() {
    $this->assertContains('/temp/vignettes_titre/notice_1.png',
                          $this->getResponseLocation());
  }
class RechercheControllerViewNoticeClefAlphaTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    $this->mock_sql
                     ->whenCalled('fetchAll')
                     ->with("select id_notice, facettes from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(MILLENIUM MILLENIUMS MILENIUM)' IN BOOLEAN MODE) order by (MATCH(alpha_titre) AGAINST(' MILLENIUM') * 1.5) + (MATCH(alpha_auteur) AGAINST(' MILLENIUM')) desc", true, null)
                     ->answers([
                                [10, ''],
                                [99, ''],
                                [88, ''],
                                [$this->notice->getId(), ''],
                                [2, ''],
                                [34,''],
                                [4, '']
                                ]);
Patrick Barroca's avatar
Patrick Barroca committed

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
      ->whenCalled('findAllBy')
      ->with(['clef_alpha' => 'TESTINGALPHAKEY---101'])
Patrick Barroca's avatar
Patrick Barroca committed

    $this->dispatch('recherche/viewnotice/clef/TESTINGALPHAKEY---101/expressionRecherche/Millenium', true);
  }

  /** @test */
  public function retourListeShouldLinkToRechercheSimpleWithHashTagIdNotice() {
    $this->assertXPathContentContains('//div/a[@class="retour"][contains(@href, "/recherche/simple/expressionRecherche/Millenium#345")]',
                                      'Retour à la liste');
  }

  /** @test */
  public function resultatSuivantShouldLinkToNavigationSuivant() {
    $this->assertXPathContentContains('//div//a[contains(@href, "recherche/viewnotice/clef/TESTINGALPHAKEY---101/expressionRecherche/Millenium/navigation/suivant")]',
                                      'Document suivant', $this->_response->getBody());
  }

  /** @test */
  public function resultatPrecedentShouldLinkToNavigationPrecedent() {
    $this->assertXPathContentContains('//div//a[contains(@href, "recherche/viewnotice/clef/TESTINGALPHAKEY---101/expressionRecherche/Millenium/navigation/precedent")]',
                                      'Document précédent', $this->_response->getBody());
  }

class RechercheControllerViewNoticeClefAlphaWithDoublonsTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
      ->whenCalled('findAllBy')
      ->with(['clef_alpha' => 'TWILIGHT--SLADED-3-M6VIDEO-2010-4'])
      ->answers([Class_Notice::newInstanceWithId($this->notice->getId())
                 ->setTitrePrincipal('Twilight 1')
                 ->setClefAlpha('TWILIGHT--SLADED-3-M6VIDEO-2010-4')
                 ->setFacettes('')
                 ->setUrlVignette('NO')
                 ->setUrlImage('NO'),

                 Class_Notice::newInstanceWithId(1)
                 ->setTitrePrincipal('Twilight 2')
                 ->setClefAlpha('TWILIGHT--SLADED-3-M6VIDEO-2010-4')
                 ->setFacettes('')
                 ->setUrlVignette('')
                 ->setUrlImage('')
                 ->setDateCreation('')
                 ]);
  }


  /** @test */
  public function withOnlyClefResponseShouldRedirectToRechercheTWILIGHT_SLADED() {
    $this->dispatch('recherche/viewnotice/clef/'.urlencode('TWILIGHT--SLADED-3-M6VIDEO-2010-4'), true);
    $this->assertRedirectTo('/opac/recherche?q=TWILIGHT+SLADED');
  }


  /** @test */
  public function withClefAndIdResponseShouldRenderTwilight2() {
    $this->dispatch('recherche/viewnotice/clef/'.urlencode('TWILIGHT--SLADED-3-M6VIDEO-2010-4').'/id/1', true);
    $this->assertXPathContentContains('//div[contains(@class, "view_notice")]//h1', 'Twilight 2');
  }
class RechercheControllerUploadVignetteTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_CodifTypeDoc::beVolatile();

    $this->notice->setTypeDoc(5);
  }


  /** @test */
  public function linkToUploadVignetteShouldNotBePresentForAbonneSIGB() {
    Class_Users::getIdentity()->beAbonneSIGB();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertNotXPathContentContains('//a', 'Modifier la vignette');
  }


  /** @test */
  public function linkToUploadVignetteShouldBePresentForModoBib() {
    Class_Users::getIdentity()->changeRoleTo(ZendAfi_Acl_AdminControllerRoles::MODO_BIB);
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertXPathContentContains('//a', 'Modifier la vignette');
  }


  /** @test */
  public function linkToUploadVignetteShouldNotBePresentForTypeDocMoreThanFive() {
    Class_Users::getIdentity()->beAdminPortail();
    $this->notice->setTypeDoc(6);
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertNotXPathContentContains('//a', 'Modifier la vignette');
  }


  /** @test */
  public function linkToUploadVignetteShouldBePresentForTypeDocThanFiveWhenInKnownFamille() {
    Class_Users::getIdentity()->beAdminPortail();
    $this->notice->setTypeDoc(Class_TypeDoc::EPUB);
    $this->fixture('Class_CodifTypeDoc', ['id' => Class_TypeDoc::EPUB,
                                          'famille_id' => Class_CodifTypeDoc::LIVRE]);

    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertXPathContentContains('//a', 'Modifier la vignette');
  }
class RechercheControllerViewNoticeAsAdminTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->notice->setTypeDoc(5);
    Class_Users::getIdentity()->beAdminPortail();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function linkToUploadVignetteShouldBePresent() {
    $this->assertXPathContentContains('//a', 'Modifier la vignette',$this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function linkToConfigModulesRechercheShouldHaveActionViewNotice() {
    $this->assertXPath('//img[contains(@onclick, "admin/modules/recherche?config=site&type_module=recherche&id_profil=2&action1=viewnotice&action2=5")]');
  }
  /** @test */
  public function linkToDeleteBlockShouldNotBePresent() {
    $this->assertNotXPath('//a[contains(@href, "/admin/accueil/delete-block")]');
  }


  /** @test */
  public function linkToAddBlockShouldNotBePresent() {
    $this->assertNotXPath('//img[contains(@onclick, "/admin/accueil/add-block")]');
  }


Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldBeHTML5Valid() {
    $this->assertHTML5();
  }
class RechercheControllerViewNoticeAndResnumeriqueTabAsAdminTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_Users::getIdentity()->beAdminPortail();

    $preferences = ['barre_nav' => 'Document',
                    'entete' =>"ABCDEFGIKLMNOPRSTtYZ8v9",
                    'onglets' =>  ['detail' =>          ['titre' => 'Details',
                                                         'aff' => '1',
                                                         'ordre' => 1,
                                                         'largeur' => 10],
                                   'avis' =>            ['titre' => 'avis',
                                                         'aff' => '1',
                                                         'ordre' => 2,
                                                         'largeur' => 10],
                                   'exemplaires' =>     ['titre' => 'exemplaires',
                                                         'aff' => '2',
                                                         'ordre' => 3,
                                                         'largeur' => 10],
                                   'resume' =>          ['titre' => 'resume',
                                                         'aff' => '2',
                                                         'ordre' => 4,
                                                         'largeur' => 10],
                                   'tags' =>            ['titre' => 'tags',
                                                         'aff' => '2',
                                                         'ordre' => 5,
                                                         'largeur' => 10],
                                   'biographie' =>      ['titre' => 'biographie',
                                                         'aff' => '2',
                                                         'ordre' => 6,
                                                         'largeur' => 10],
                                   'similaires' =>      ['titre' => 'similaires',
                                                         'aff' => '2',
                                                         'ordre' => 7,
                                                         'largeur' => 10],
                                   'bibliographie' =>   ['titre' => 'bibliographie',
                                                         'aff' => '3',
                                                         'ordre' => 7,
                                                         'largeur' => 10],
                                   'morceaux' =>        ['titre' => 'morceaux',
                                                         'aff' => '3',
                                                         'ordre' => 8,
                                                         'largeur' => 10],
                                   'bandeAnnonce' =>    ['titre' => 'bande annonce',
                                                         'aff' => '3',
                                                         'ordre' => 9,
                                                         'largeur' => 10],
                                   'photos' =>          ['titre' => 'photos',
                                                         'aff' => '3',
                                                         'ordre' => 14,
                                                         'largeur' => 10],
                                   'videos' =>          ['titre' => 'videos',
                                                         'aff' => '3',
                                                         'ordre' => 11,
                                                         'largeur' => 10],
                                   'resnumeriques' =>   ['titre' => 'ressources n',
                                                         'aff' => '2',
                                                         'ordre' => 12,
                                                         'largeur' => 10],
                                   'babeltheque' =>     ['titre' => 'babeltheque',
                                                         'aff' => '3',
                                                         'ordre' => 13,
                                                         'largeur' => 10],
                                   'frbr' =>            ['titre' => 'frbr',
                                                         'aff' => '0',
                                                         'ordre' => 10,
                                                         'largeur' => 10],
                                   'serie' =>           ['titre' => 'serie',
                                                         'aff' => '0',
                                                         'ordre' => 11,
                                                         'largeur' => 10]],
                    'boite' =>  null];

    Class_Profil::beVolatile();
    $this->fixture('Class_Profil', ['id' => 1,
                                    'libelle' => 'Afibre'])
      ->setBarreNavOn(true)
      ->setCfgModules(['recherche' => ['viewnotice1' => $preferences]])
      ->beCurrentProfil();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
  }


  /** @test */
  public function resnumeriquesBlocShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="resnumeriques block_info_notice"]//h2', 'ressources n');
  }
class RechercheControllerReadNoticeTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch(sprintf('recherche/readnotice/id/%d', $this->notice->getId()), true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titreShouldBeDisplayed() {
    $this->assertXPathContentContains('//p', 'Titre: Cinéma d\'animation');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function auteurShouldBeDisplayed() {
    $this->assertXPathContentContains('//p', 'Auteur: Bernard Génin');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function anneeShouldBe2002() {
    $this->assertXPathContentContains('//p', 'Année: 2002');
  }
Laurent's avatar
Laurent committed


abstract class RechercheAvanceeControllerSimpleActionTestCase extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_AdminVar::newInstanceWithId('FACETTE_TYPE_DOC_LIBELLE', ['valeur' => 'Type de document']);
  }
Laurent's avatar
Laurent committed


class RechercheAvanceeControllerSimpleActionWithDefaultConfigTest extends RechercheAvanceeControllerSimpleActionTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    Class_Profil::getCurrentProfil()->setCfgModules([]);

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
      ->whenCalled('findAllByRequeteRecherche')
      ->answers([$this->fixture('Class_Notice', ['id' => 8])]);

Laurent's avatar
Laurent committed
    $mock_moteur_recherche = Storm_Test_ObjectWrapper::mock();
    $mock_search_result = Storm_Test_ObjectWrapper::mock();

    $mock_search_result
      ->whenCalled('getCriteresRecherche')
      ->answers(new Class_CriteresRecherche())

      ->whenCalled('getRecordsCount')
      ->answers(5)

      ->whenCalled('getRubrics')
      ->answers([])

      ->whenCalled('getBreadcrumb')
      ->answers([])

      ->whenCalled('fetchRecords')
      ->answers([])

      ->whenCalled('isError')
      ->answers(false)

      ->whenCalled('fetchFacetsAndTags')
      ->answers(['facettes' => [],