<?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
 */


abstract class RechercheControllerNoticeTestCase extends AbstractControllerTestCase {

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

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

    $this->fixture(Class_CodifAuteurFonction::class,
                   ['id' => '070',
                    'libelle' => 'Auteur']);

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

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

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

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

    $this->fixture(Class_CodifDewey::class,
                   ['id' => 1,
                    'id_dewey' => 1,
                    'libelle' => 'Philosophie et disciplines connexes']);

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

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

    $this->fixture(Class_Bib::class, ['id' => 1, 'libelle' => 'Romains']);
    $this->fixture(Class_Bib::class, ['id' => 2, 'nom_court' => 'Pringy']);

    $this->notice = $this->fixture(Class_Notice::class,
                                   ['id' => 345,
                                    'annee' => 2002,
                                    'isbn' => '1-234-56789-0',
                                    'type_doc' => Class_TypeDoc::LIVRE,
                                    'titres' => 'POMME MILLENIUMS',
                                    'type' => 1,
                                    'url_vignette' => 'NO',
                                    'url_image' => 'NO',
                                    'clef_alpha' => 'TESTINGALPHAKEY---101',
                                    'alpha_titre' => 'hades',
                                    'facettes' => 'A123 F2 G1 P4 Y2 B1 Lfre M1 Z3 D1',
                                    'date_creation' => '2013-12-31',
                                    'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/bernard_genin.uni')])
      ->setExemplaires([$this->fixture(Class_Exemplaire::class,
                                       ['id' => 34,
                                        'id_bib' => 456,
                                        'id_int_bib' => 1,
                                        'id_origine' => 12,
                                        'code_barres' => '12256663233656',
                                        'sigb_exemplaire' => ($this->mock()
                                                              ->whenCalled('isReservable')
                                                              ->answers(true))
                                       ])]);

  }
}




class RechercheControllerPrintTest extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_ModeleFusion::class,
                   ['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' => Class_ModeleFusion::RECORD_TEMPLATE]);
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('');
  }


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

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


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




class RechercheControllerViewNoticeBabelthequeTest
  extends RechercheControllerNoticeTestCase {

  /** @test */
  public function withoutBabelthequeJSShouldNotBeLoaded() {
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('');
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()));
    $this->assertNotXpath('//script[contains(@src, "babeltheque.js")]');
  }


  /** @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()));
    $this->assertXpath('//script[contains(@src, "babeltheque.js?bwid=666")]');
  }


  /** @test */
  public function noticeShouldNotHaveTome() {
    $this->notice->setClefChapeau("test")->save();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()));

    $this->assertNotXPathContentContains('//div[@class="entete_notice"]',"Voir tous les tomes");
  }
}




class RechercheControllerPagerTest extends RechercheControllerNoticeTestCase {

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

    ZendAfi_Auth::getInstance()->clearIdentity();

    foreach (range (1, 45) as $id)
      $this->fixture(Class_Notice::class,
                     ['id' => $id,
                      'titres' => 'POMME',
                      'type' => 1,
                      'facettes' => 'T3',
                      'clef_oeuvre' => '',
                      'url_vignette' => Class_WebService_Vignette::NO_DATA,
                      'url_image' => Class_WebService_Vignette::NO_DATA]);
  }


  /** @test */
  public function searchTermShouldNotBeEditable() {
    Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultatsimple' => ['search_term_editable' => 0,
                                                                                          'header_composition' => 'Advanced']]]);

    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4');
    $this->assertXPath('//div[@class="resultats_page"]//div[@class="expression-recherche"][contains(text(), "pomme")]');
  }


  /** @test */
  public function searchTermShouldBeEditable() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4');
    $this->assertXPath('//input[@name="expressionRecherche"][@value="pomme"]');
  }


  /** @test */
  public function pagerShouldBeDisplayedOnTop() {
    Class_AdminVar::newInstanceWithId('SEARCH_PAGINATE_POSITION', ['valeur' => 'TOP']);
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4');
    $this->assertXPath('//h1/following-sibling::node()[@class="pager"]');
  }


  /** @test */
  public function pagerShouldBeDisplayedOnBottom() {
    Class_AdminVar::newInstanceWithId('SEARCH_PAGINATE_POSITION', ['valeur' => 'BOTTOM']);
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4');
    $this->assertXPath('//div[@class="liste_notices"]/following-sibling::node()[@class="pager"]');
  }


  /** @test */
  public function pagerShouldBeDisplayedOnTopAndBottom() {
    Class_AdminVar::newInstanceWithId('SEARCH_PAGINATE_POSITION', ['valeur' => 'BOTH']);
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4');
    $this->assertXPathCount('//div[@class="pager"]', 2);
  }


  /** @test */
  public function urlPage2ShouldBeWithListeFormatParameter() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4');
    $this->assertXPath('//a[contains(@href, "/liste_format/4")][contains(@href,"/page/2")]');
  }


  /** @test */
  public function withPageSize10PageFiveShouldBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3');
    $this->assertXPath('//a[contains(@href,"/page/5")]');
  }


  /** @test */
  public function withPageSize100PageFiveShouldFallbackToMaximumPageSize50() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/100');
    $this->assertXPath('//a[contains(@href,"/page_size/50")]');
  }


  /** @test */
  public function withPageSize10PageSixShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3');
    $this->assertNotXPath('//a[contains(@href,"/page/6")]');
  }


  /** @test */
  public function urlWithPageSizeSevenShouldCallFindAllWithPageSize() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7');
    $this->assertXPath('//a[contains(@href, "/page_size/7")][contains(@href,"/page/2")]');
  }


  /** @test */
  public function withPageSizeSevenPageSevenShouldBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7');
    $this->assertXPath('//a[contains(@href,"/page/7")]');
  }


  /** @test */
  public function withPageSizeSevenPageHeightShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7');
    $this->assertNotXPath('//a[contains(@href,"/page/8")]');
  }
}




abstract class RechercheControllerViewNoticeCollectionWithPreferencesTest
  extends RechercheControllerNoticeTestCase {

  protected $_web_analytics_client;

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

    $preferences = [
                    'barre_nav' => 'Document',
                    'entete' =>"ABCDWFGIKLMNOPRSTtYZ8v9",
                    '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 RechercheControllerViewNoticeCollectionWithSerie
  extends RechercheControllerViewNoticeCollectionWithPreferencesTest {

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

    $this->notice
      ->setClefChapeau('ABCDEF')
      ->setTomeAlpha('v234')
      ->set_subfield('225', 'a', 'Gallimard Poche')
      ->assertSave();

    $this->dispatch('recherche/viewnotice/id/345');
  }


  /** @test */
  public function pageShouldContainLinkToRecordsSameCollectionGallimardPoche() {
    $this->assertXPathContentContains('//dd//a[contains(@href,"recherche/simple/rech_collection/Gallimard+Poche")]',
                                      'Gallimard Poche');
  }


  /** @test */
  public function linkToRecordSameCollectionShouldNotContainDocumentTitle() {
    $this->assertNotXPathContentContains('//div//a[contains(@href,"recherche/simple/serie/GALLIMARD+POCHE")]',
                                         $this->notice->getTitrePrincipal());
  }
}




class RechercheControllerViewNoticeCollectionWithoutSerie
  extends RechercheControllerViewNoticeCollectionWithPreferencesTest {

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

    $unimarc = new Class_NoticeUnimarc_Writer();
    $unimarc->setNotice($this->notice->getUnimarc());

    $this->notice
      ->setUnimarc($unimarc->toUnimarcISO2709())
      ->setTomeAlpha('24')
      ->assertSave();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => [
                                                            'liste_format' => $this->_liste_format ,
                                                            'liste_codes' => "TANC"]]]);

    $this->dispatch('recherche/viewnotice/id/345');
  }


  /** @test */
  public function pageShouldContainslinkToRecordSameCollectionPetitsCahiers() {
    $this->assertXPathContentContains('//div//a[contains(@href,"recherche/simple/rech_collection/Les+petits+cahiers")]',
                                      'Les petits cahiers');
  }
}




class RechercheControllerViewNoticeWithPreferencesTest
  extends RechercheControllerNoticeTestCase {

  protected $_web_analytics_client;

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

    Class_AdminVar::set('AUTHOR_PAGE', 0);

    $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')
      ->set_subfield('461','t', 'Gallimard serie')
      ->assertSave();

    $preferences = [
                    'barre_nav' => 'Document',
                    'entete' =>"ABCDWFGIKLMNOPRSTtYZ8v9",
                    '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 = $this->mock()
                                        ->whenCalled('trackEvent')
                                        ->answers(true);
    ZendAfi_Controller_Action_Helper_TrackEvent::setDefaultWebAnalyticsClient($this->_web_analytics_client);

    $this->dispatch('recherche/viewnotice/id/345');
  }


  /** @test **/
  public function enteteShouldDisplayNouveaute(){
    $this->assertXPathContentContains('//dl//dt[contains(@class,"nouveaute")]/following-sibling::dd','Oui');
  }


  /** @test **/
  public function noticeHtmlShouldContainsDivNoticeFlagWithSpanNouveaute(){
    $this->assertXpath('//div[@class="flags_notice"]//span[@class="nouveaute"]');
  }


  /** @test */
  public function enteteShouldDisplayAnnee2002() {
    $this->assertXPathContentContains('//dl//dd', '2002');
  }


  /** @test */
  public function enteteShouldDisplayDocumentDeLaMemeSerie() {
    $this->assertXPathContentContains('//div//a[contains(@href,"Gallimard+serie")]',
                                      'Voir tous les tomes de Gallimard serie');
  }


  /** @test */
  public function enteteShouldDisplayDocumentLinkOrderByDateNouveaute() {
    $this
      ->assertXPathContentContains('//div//a[contains(@href,"/Gallimard+serie-1/tri/date_creation+desc")]',
                                   'Voir tous les tomes de Gallimard serie');
  }


  /** @test */
  public function enteteShouldDisplayDtEditeur() {
    $this->assertXPathContentContains('//dl//dt', 'Editeur');
  }


  /** @test */
  public function enteteShouldDisplayEditeurCahiersDuCinema() {
    $this->assertXPathContentContains('//dl//dd//div', 'Cahiers du cinéma');
  }


  /** @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)');
  }


  /** @test */
  public function enteteShouldDisplayRebondInterestMarionettes() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/F2")]', 'marionettes');
  }


  /** @test */
  public function enteteShouldDisplayRebondTagEnfants() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/Z3")]', 'enfants');
  }


  /** @test */
  public function enteteShouldDisplayRebondPcdm4Rock() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/P4")]', 'rock');
  }


  /** @test */
  public function enteteShouldDisplayRebondGenreSpectacle() {
    $this->assertXPathContentContains('//dl//a[contains(@href, "recherche/simple/id/345/code_rebond/G1")]', 'spectacle');
  }


  /** @test */
  public function enteteLibelleGenreShouldBeGENRES() {
    $this->assertXPathContentContains('//dl//dt', 'GENRES');
  }


  /** @test */
  public function enteteShouldDisplayDtDdCollectionWithClassSecond() {
    $this->assertXPathContentContains('//dl//dt[contains(@class, "second")]', 'Collection');
  }


  /** @test */
  public function detailsBlocShouldHaveIdBloc_345_0() {
    $this->assertXPathContentContains('//div[@id="bloc_345_0"][@class="notice_bloc_titre"]', 'Details');
  }


  /** @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')");
  }


  /** @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')");
  }


  /** @test */
  public function noJavascriptShouldOpenThirdBlocExemplaires() {
    $this->assertNotXPathContentContains('//script', "infos_bloc(\"bloc_345_2\"");
  }


  /** @test */
  public function bibliographieOngletShouldHaveIdSet345_onglet_0() {
    $this->assertXPathContentContains('//div[@id="set345_onglet_0"][@class="titre_onglet"]', 'bibliographie');
  }


  /** @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')");
  }


  /** @test */
  public function videosOngletShouldHaveIdSet345_onglet_3() {
    $this->assertXPathContentContains('//div[@id="set345_onglet_3"][@class="titre_onglet"]', 'videos');
  }


  /** @test */
  public function noJavascriptShouldOpenSecondOnglet() {
    $this->assertNotXPathContentContains('//script', "infos_onglet('set345_onglet_1')");
  }


  /** @test */
  public function linkReserverShouldBeDisplayed() {
    $this->assertXPathContentContains('//a[contains(@onclick, "openDialogExemplaires")][not(@data-popup)]', 'Réserver');
  }


  /** @test */
  public function vignetteShouldBeGenerated() {
    $this->assertXPath('//div[@class="nothumbnail type_doc_1"]');
  }


  /** @test */
  public function vignetteForZoomShouldNotBeGenerated() {
    $this->assertNotXPath('//a[@id="vignette"]');
  }


  /** @test */
  public function divViewNoticeShouldHaveClassTypeDocOne() {
    $this->assertXPath('//div[@class="view_notice type_doc_1"]');
  }


  /** @test */
  public function tabTitleShouldContainTitle() {
    $this->assertXPath('//div[contains(@class, "titre_onglet") and h2]');
  }


  /** @test */
  public function pageShouldBeHTML5Valid() {
    $this->assertHTML5();
  }


  /** @test */
  public function pageShouldBeAccessible() {
    $this->assertAccessible(false, $this->_response->getBody());
  }


  /** @test */
  public function trackEventShouldContainsNoticeTitreAuteur() {
    $this->assertEquals(['recherche',
                         'notice',
                         '"titre: Gallimard serie<br />Cinéma d\'animation","auteur: Bernard Génin","editeur: \"Cahiers du cinéma\"","tome: ","support: livres"',
                         345],
                        $this->_web_analytics_client->getAttributesForLastCallOn('trackEvent'));
  }


  /**
   * @test
   * @group pagetitles
   */
  public function barreNavShouldContainsCinemaAnimation() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'Cinéma d\'animation');
  }


  /** @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');
  }
}




class RechercheControllerViewNoticeTest extends RechercheControllerNoticeTestCase {

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

    Class_AdminVar::set('AUTHOR_PAGE', 0);
    $this->dispatch('recherche/viewnotice/id/345');
  }


  /** @test */
  public function titleShouldBeDisplayed() {
    $this->assertXPathContentContains('//h1',
                                      array_first(explode('<br />', $this->notice->getTitrePrincipal())));
  }


  /** @test */
  public function pageShouldContainsOnlyTwoH1() {
    $this->assertXPathCount('//h1', 2);
  }


  /** @test */
  public function pageShouldContainsH1WithTitleAndAuthor() {
    $this->assertXPath('//h1//span[contains(text(), "Cinéma d\'animation")][following-sibling::span[text()="Bernard Génin"]]');
  }


  /** @test */
  public function tagReseauSociauxShouldBePresent() {
    $this->assertXPath('//div[@id="reseaux-sociaux"]');
  }


  /** @test */
  public function headShouldContainsRechercheJS() {
    $this->assertXPath('//head//script[contains(@src,"public/opac/js/recherche.js")]');
  }
}




class RechercheControllerViewNoticeMetasTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Notice::class,
                   ['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/cine.jpg',
                    'url_image' => 'http://linux.org/cine_BIG.jpg',
                    'facettes' => 'A123 F2 G1 P4 Y2 B1 Lfre M1 Z3 D1',
                    'date_creation' => '2013-12-31']);

    $this->dispatch('recherche/viewnotice/id/345');
  }


  /** @test */
  public function pageShouldContainTitleMeta() {
    $this->assertXPathContentContains('//meta[@property="og:title"]/@content', 'Cinéma d\'animation br/ 3D - Bernard Génin');
  }


  /** @test */
  public function pageShouldContainImageMeta() {
    $this->assertXPathContentContains('//meta[@property="og:image"]/@content', 'http://linux.org/cine_BIG.jpg');
  }


  /** @test */
  public function pageShouldContainOgTypeMeta() {
    $this->assertXPathContentContains('//meta[@property="og:type"]/@content', 'book');
  }


  /** @test */
  public function pageShouldContainDescriptionMeta() {
    $this->assertXPath('//meta[@property="og:description"]/@content');
  }


  /** @test */
  public function pageShouldContainOgUrlMeta() {
    $this->assertXPathContentContains('//meta[@property="og:url"][contains(@content,"recherche/viewnotice")]/@content',
                                      'id/345');
  }


  /** @test */
  public function thumbnailImgWidthAttributeShouldBeSet() {
    $this->assertXPath('//div[@class="notice_vignette"]/a/img[@src="http://linux.org/cine_BIG.jpg"][not(@width)][@style="width:100px"]');
  }
}




class RechercheControllerVignetteThumbnailTest extends RechercheControllerNoticeTestCase {

  /** @test */
  public function rechercheVignetteActionShouldRedirectToRawThumbnailAction() {
    $this->dispatch('recherche/vignette/id_notice/345');
    $this->assertRedirectTo(Class_Url::absolute('/recherche/raw-thumbnail/id/345'),
                            $this->getResponseLocation());
  }


  /** @test */
  public function rawThumbnailForIdNoticeTwoShouldAnswerPngImage() {
    $this->dispatch('/recherche/raw-thumbnail/id/345');
    $this->assertContains('iVBORw0', base64_encode($this->_response->getBody()));
  }
}




class RechercheControllerVignetteEmptyTest extends AbstractControllerTestCase {

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

    Class_Article::setFileWriter($this->mock()
                                 ->whenCalled('fileExists')
                                 ->with(Class_Url::baseUrl() . '/images/articles/img.png')
                                 ->answers(true)
                                 ->beStrict());

    $article = $this->fixture(Class_Article::class,
                              ['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');
  }


  /** @test */
  public function responseShouldRedirectToRawThumbnailUrl() {
    $this->assertRedirectTo(Class_Url::absolute('/recherche/raw-thumbnail/id/1'));
  }
}




class RechercheControllerViewNoticeClefAlphaTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Notice::class,
                   ['id' => 10,
                    'type' => 1,
                    'titres' => 'POMME MILLENIUMS',
                    'date_creation' => '2013-01-01']);

    $this->fixture(Class_Notice::class,
                   ['id' => 99,
                    'type' => 1,
                    'titres' => 'POMME MILLENIUMS',
                    'date_creation' => '2013-01-02']);

    $this->fixture(Class_Notice::class,
                   ['id' => 88,
                    'type' => 1,
                    'titres' => 'POMME MILLENIUMS',
                    'date_creation' => '2013-01-03']);

    $this->fixture(Class_Notice::class,
                   ['id' => 2,
                    'type' => 1,
                    'titres' => 'POMME MILLENIUMS',
                    'date_creation' => '2014-01-01']);

    $this->fixture(Class_Notice::class,
                   ['id' => 34,
                    'type' => 1,
                    'titres' => 'POMME MILLENIUMS',
                    'date_creation' => '2014-01-02']);

    $this->fixture(Class_Notice::class,
                   ['id' => 4,
                    'type' => 1,
                    'titres' => 'POMME MILLENIUMS',
                    'date_creation' => '2014-01-03']);

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


  /** @test */
  public function resetThumbnailButtonShouldContainsId345() {
    $this->assertXPath('//button[contains(@onclick, "admin/records/reset-thumbnail/id/345")]');
  }


  /** @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/expressionRecherche/Millenium/clef/TESTINGALPHAKEY---101/id/345/navigation/suivant")]',
                                      'Document suivant');
  }


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




class RechercheControllerViewNoticeClefAlphaWithDoublonsTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Notice::class,
                   ['id' => 2,
                    'titre_principal' => 'Twilight 1',
                    'clef_alpha' => 'TWILIGHT--SLADED-3-M6VIDEO-2010-4',
                    'url_vignette' => 'NO',
                    'url_image' => 'NO',
                    'type' => 1]);

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'titre_principal' => 'Twilight 2',
                    'clef_alpha' => 'TWILIGHT--SLADED-3-M6VIDEO-2010-4',
                    'type' => 1]);
  }


  /** @test */
  public function withOnlyClefResponseShouldRedirectToRechercheTWILIGHT_SLADED() {
    $this->dispatch('recherche/viewnotice/clef/'
                    . urlencode('TWILIGHT--SLADED-3-M6VIDEO-2010-4'));
    $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');
    $this->assertXPathContentContains('//div[contains(@class, "view_notice")]//h1', 'Twilight 2');
  }
}




class RechercheControllerUploadVignetteTest extends RechercheControllerNoticeTestCase {

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

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


  /** @test */
  public function linkToUploadVignetteShouldNotBePresentForAbonneSIGB() {
    Class_Users::getIdentity()->beAbonneSIGB();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()));
    $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()));
    $this->assertXPath('//button[contains(@title, "Modifier la vignette")]');
  }


  /** @test */
  public function dispatchWithIframeAndAdminLoggedShouldDisplayRecord() {
    Class_Users::getIdentity()->changeRoleTo(ZendAfi_Acl_AdminControllerRoles::MODO_BIB);
    $this->dispatch(sprintf('recherche/viewnotice/id/%d/render/iframe', $this->notice->getId()));
    $this->assertXPath('//button[contains(@title, "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()));
    $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()));
    $this->assertXPath('//button[contains(@title, "Modifier la vignette")]');
  }
}




class RechercheControllerGenerateThumbnailTest
  extends RechercheControllerNoticeTestCase {

  /** @test */
  public function linkToGenerateThumbnailShouldNotBePresentForAbonneSIGB() {
    Class_Users::getIdentity()->beAbonneSIGB();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()));
    $this->assertNotXPath('//button[contains(@onclick, "admin/records/reset-thumbnail")][contains(@title, "Supprimer et re-générer la vignette")]');
  }


  /** @test */
  public function linkToGenerateThumbnailShouldBePresentForModoBib() {
    Class_Users::getIdentity()->changeRoleTo(ZendAfi_Acl_AdminControllerRoles::MODO_BIB);
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()));
    $this->assertXPath('//button[contains(@onclick, "admin/records/reset-thumbnail")][contains(@title, "Supprimer et re-générer la vignette")]');
  }
}




class RechercheControllerViewNoticeAsAdminTest
  extends RechercheControllerNoticeTestCase {

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

    $this->notice->setTypeDoc(5);
    Class_Users::getIdentity()->beAdminPortail();

    Class_Profil::getCurrentProfil()
      ->setCfgMenus([0 => [
                           'type_module' => 'MENU',
                           'clef_profil' => 0,
                           'menus' => [['type_menu' => 'MENU',
                                        'libelle' => 'Pratique',
                                        'picto' => 'bookmark.png',
                                        'preferences' => [],
                                        'sous_menus' => [['type_menu' => 'ACCUEIL',
                                                          'libelle' => 'Accueil',
                                                          'picto' => 'vide.gif',
                                                          'preferences' => [],
                                                          'sous_menus' => '']]]]]]);

    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()));
  }


  /** @test */
  public function linkToUploadVignetteShouldBePresent() {
    $this->assertXPath('//button[contains(@title, "Modifier la vignette")]');
  }


  /** @test */
  public function linkToConfigModulesRechercheShouldHaveActionViewNotice() {
    $this->assertXPath('//a[contains(@href, "/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")]');
  }


  /** @test */
  public function pageShouldBeHTML5Valid() {
    $this->assertHTML5();
  }
}




/** @see http://forge.afi-sa.fr/issues/116900#note-3 */
class RechercheControllerViewNoticeAsAdminWithMenuIdZeroTest
  extends RechercheControllerNoticeTestCase {

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

    Class_Users::getIdentity()->beAdminPortail();

    Class_Profil::getCurrentProfil()
      ->setCfgMenus([0 => [
                           'type_module' => 'MENU',
                           'clef_profil' => 0,
                           'menus' => [['type_menu' => 'MENU',
                                        'libelle' => 'Pratique',
                                        'picto' => 'bookmark.png',
                                        'preferences' => [],
                                        'sous_menus' => [['type_menu' => 'ACCUEIL',
                                                          'libelle' => 'Accueil',
                                                          'picto' => 'vide.gif',
                                                          'preferences' => [],
                                                          'sous_menus' => '']]]]]]);

    $this->dispatch('recherche/viewnotice/id/' . $this->notice->getId());
  }


  /** @test */
  public function linkToConfigModulesRechercheShouldHaveActionViewNotice() {
    $this->assertXPath('//a[contains(@href, "/admin/modules/recherche/config/site/type_module/recherche/id_profil/2/action1/viewnotice")]');
  }
}




class RechercheControllerViewNoticeAndResnumeriqueTabAsAdminTest
  extends RechercheControllerNoticeTestCase {

  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],
                                   'recounts' =>        ['titre' => 'Dépouillements',
                                                         'aff' => '1',
                                                         'ordre' => '190',
                                                         'largeur' => 12],
                                   '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],
                                   'babeltheque' =>     ['titre' => 'Bab Tech',
                                                         'aff' => '2',
                                                         '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()));
  }


  /** @test */
  public function resnumeriquesBlocShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="resnumeriques block_info_notice"]//h2', 'Ressources nu');
  }


  /** @test */
  public function babelBlocShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="babeltheque block_info_notice"]//h2', 'Bab Tech');
  }
}




class RechercheControllerViewNoticeAndRecountsTest
  extends RechercheControllerNoticeTestCase {

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

    Class_Users::getIdentity()->beAdminPortail();

    $preferences = ['barre_nav' => 'Document',
                    'entete' =>"ABCDEFGIKLMNOPRSTtYZ8v9",
                    'analytics' => '464',
                    'analytics_title' => 'a',
                    'analytics_authors' => 'f',
                    'onglets' =>  ['detail' =>          ['titre' => 'Details',
                                                         'aff' => '1',
                                                         'ordre' => 1,
                                                         'largeur' => 10],
                                   'recounts' =>        ['titre' => 'Depouillements',
                                                         'aff' => '1',
                                                         'ordre' => '190',
                                                         'largeur' => 12],
                                   '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::class,
                   ['id' => 1,
                    'libelle' => 'Afibre'])
         ->setBarreNavOn(true)
         ->setCfgModules(['recherche' => ['viewnotice1' => $preferences]])
         ->beCurrentProfil();

    $this->fixture(Class_Notice::class,
                   ['id' => 12,
                    'type_doc' => Class_TypeDoc::LIVRE,
                    'unimarc' => file_get_contents(ROOT_PATH . 'tests/fixtures/mobiclic.uni')]);

    $this->dispatch('recherche/viewnotice/id/12');
  }


  /** @test */
  public function recountsTabShouldBePresent() {
    $this->assertXpathContentContains('//div//h2', 'Depouillements');
  }
}




class RechercheControllerReadNoticeTest extends RechercheControllerNoticeTestCase {

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

    $this->dispatch(sprintf('recherche/readnotice/id/%d', $this->notice->getId()));
  }


  /** @test */
  public function titreShouldBeDisplayed() {
    $this->assertXPathContentContains('//p', 'Titre: Cinéma d\'animation');
  }


  /** @test */
  public function auteurShouldBeDisplayed() {
    $this->assertXPathContentContains('//p', 'Auteur: Bernard Génin');
  }

  /** @test */
  public function anneeShouldBe2002() {
    $this->assertXPathContentContains('//p', 'Année: 2002');
  }
}




abstract class RechercheAvanceeControllerSimpleActionTestCase
  extends RechercheControllerNoticeTestCase {

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

    Class_AdminVar::newInstanceWithId('FACETTE_TYPE_DOC_LIBELLE', ['valeur' => 'Type de document']);
  }
}




class RechercheAvanceeControllerSimpleActionWithDefaultConfigTest
  extends RechercheAvanceeControllerSimpleActionTestCase {

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

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

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

    $mock_moteur_recherche = $this->mock();
    $mock_search_result = $this->mock();

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

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

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

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

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

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

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

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

      ->whenCalled('fetchFacetsAndTags')
      ->answers(['facettes' => [],
                 'suggests' => [
                                [
                                 'id' => 'M1355',
                                 'label' => 'CD (Sujet)'
                                ]
                 ],
                 'bookmarks' => [
                                 [
                                  'id' => 'HCCCC0001',
                                  'label' => 'Music'
                                 ],
                                 [
                                  'id' => 'YMEL',
                                  'label' => 'Lille Metro'
                                 ]
                 ],
                 'tags' => [
                            1=>[
                                "id" => "M1355",
                                "libelle"  => "CD",
                                "nombre" => 10],
                            2=>[
                                "id" => "M12",
                                "libelle"  => "DVD",
                                "nombre" => 5],
                 ]])

      ->whenCalled('setDuration')
      ->answers($mock_search_result)

      ->whenCalled('getDuration')
      ->answers(0.4)

      ->whenCalled('setSettings')
      ->answers($mock_search_result)

      ->whenCalled('getSettings')
      ->answers(Class_Profil::getCurrentProfil()->getSearchResultSettings())

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

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

      ->whenCalled('shouldDisplaySearchExtensionAboveFacet')
      ->answers(false)
      ;

    $mock_moteur_recherche
      ->whenCalled('lancerRecherche')
      ->answers($mock_search_result);

    Class_MoteurRecherche::setInstance($mock_moteur_recherche);

    $this->fixture(Class_Catalogue::class,
                   ['id' => 1,
                    'libelle' => 'Des BD',
                    'indexer' => 1]);

    $this->fixture(Class_Bib::class,
                   ['id' => 3,
                    'libelle' => 'I like real fixtures']);

    $lok = $this->fixture(Class_Users::class,
                          ['id' => 1,
                           'login' => 'Lok',
                           'password' => 'Lik']);

    (new Class_User_Settings($lok))
      ->setBookmarkedLibraries(['3'])
      ->setBookmarkedDomains(['1'])
      ->save();

    ZendAfi_Auth::getInstance()->logUser($lok);

    $this->dispatch('/recherche/simple?rech_titres=maupassant');
  }


  /** @test */
  public function pageShouldContainsRechTitresMaupassantWrappedInSlahes() {
    $this->assertXPath('//a[contains(@href, "/rech_titres/maupassant")]');
  }


  /** @test */
  public function userSettingBookmarkedDomainShouldBeOne() {
    $this->assertEquals([Class_Catalogue::find(1)],
                        (new Class_User_Settings(Class_Users::find(1)))
                        ->getBookmarkedDomains());
  }


  /** @test */
  public function userSettingZorkShouldBeEmpty() {
    $this->assertEmpty((new Class_User_Settings(Class_Users::find(1)))->get('zork'));
  }


  /** @test */
  public function userSettingSetZorkToGlubShouldSetIt() {
    (new Class_User_Settings(Class_Users::find(1)))->set('zork', 'glub');
    Class_Users::find(1)->save();
    Class_Users::clearCache();

    $this->assertEquals('glub',
                        (new Class_User_Settings(Class_Users::find(1)))
                        ->get('zork'));
  }


  /** @test */
  public function tagsCloudLevel5ShouldBePresent() {
    $this->assertXPath('//a[contains(@class,"nuage_niveau5")]');
  }


  /** @test */
  public function tagsCloudLevel10ShouldBePresent() {
    $this->assertXPath('//a[contains(@class,"nuage_niveau10")]');
  }


  /** @test */
  public function orderSelectShouldHaveLabel() {
    $this->assertXPath('//label[@for="tri"]');
  }


  /** @test */
  public function suggestsBoxShouldContainsLinkToReboundCD() {
    $this->assertXPathContentContains('//div[@class="suggests facette"]/ul/li/a[contains(@href, "code_rebond/M1355")]',
                                      'CD (Sujet)');
  }


  /** @test */
  public function bookmarksWidgetShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="filtre_recherche"]//div[contains(@class, "bookmarks_outer")]', 'favoris');
  }


  /** @test */
  public function bookmarkFacetLinkShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="filtre_recherche"]//div[contains(@class, "bookmark")]//a[contains(@href, "/facette/HCCCC0001")]', 'Music');
  }


  /** @test */
  public function bookmarkLibraryFacetLinkShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="filtre_recherche"]//div[contains(@class, "bookmark")]//a[contains(@href, "/facette/YMEL")]', 'Lille Metro');
  }
}




abstract class RechercheControllerSimpleActionTestCase
  extends RechercheControllerNoticeTestCase {

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

    Class_AdminVar::newInstanceWithId('FACETTE_TYPE_DOC_LIBELLE', ['valeur' => 'Type de document']);
  }
}




class RechercheControllerWithBookmarkableLibrariesDisabledTest
  extends RechercheControllerNoticeTestCase {

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

    Class_AdminVar::set('ENABLE_BOOKMARKABLE_LIBRARIES', 0);
  }


  /** @test */
  public function librariesBookmarksShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/');
    $this->assertNotXPath('//div[contains(@class, "bookmarks_outer")]');
  }


  /** @test */
  public function withNoSessionManageYourBookmarksShouldNotBePresent() {
    ZendAfi_Auth::getInstance()->clearIdentity();
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/');
    $this->assertNotXPathContentContains('//div//p', 'Vous devez être connecté pour gérer vos favoris');
  }
}




class RechercheControllerSimpleActionWithDefaultConfigTest
  extends RechercheControllerSimpleActionTestCase {

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

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

    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur asc');
  }


  /** @test */
  public function pageShouldContainsSearchDurationInSecondes() {
    $this->assertXPathContentContains('//div', 'secondes)');
  }


  /** @test */
  public function pageShouldContainsLinkToAtomFormat() {
    $this->assertXPath('//a[contains(@href, "/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur+asc/format/atom")]/img[contains(@src, "rss")]');
  }


  /** @test */
  public function pommeShouldBePresentInRedirectedPageAsResultatInSession() {
    $this->assertXPathContentContains('//div', 'pomme');
  }


  /** @test */
  public function pageShouldContainsLinkToSuggestionAchats() {
    $this->assertXPathContentContains('//a[contains(@href, "/abonne/suggestion-achat")]',
                                      'Suggérer un achat');
  }


  /** @test */
  public function selectedTriShouldBeAlphaAuteur() {
    $this->assertXPath('//select[@name="tri"]//option[@value="alpha_auteur asc"][@selected="selected"]');

  }


  /** @test */
  public function facetteWidgetTitleShouldBeAsExpected() {
    $this->assertXPathContentContains('//div[@class="facette_outer"]/h2', 'Affiner le résultat...');
  }


  /** @test */
  public function tagsCloudWidgetTitleShouldBeAsExpected() {
    $this->assertXPathContentContains('//div[contains(@class,"nuage_outer")]/h2', 'Elargir la recherche...');
  }
}




class RechercheControllerIndexActionTestWithParamQ
  extends RechercheControllerSimpleActionTestCase {

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

    $this->dispatch('/recherche/index?q=pomme');
  }


  /** @test */
  public function pommeShouldBePresentInResult() {
    $this->assertXPathContentContains('//div', 'pomme');
  }
}




class RechercheControllerSimpleActionWithConfigWithoutSuggestionAchatAsAdminTest
  extends RechercheControllerSimpleActionTestCase {

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

    Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultatsimple' => ['suggestion_achat' => 0,
                                                                                          'liste_format' => 3]]]);
    Class_Users::getIdentity()->beAdminPortail();
    $this->dispatch('/recherche/simple');
  }


  /** @test */
  public function pageShouldNotContainsLinkToSuggestionAchats() {
    $this->assertNotXPath('//a[contains(@href, "/abonne/suggestion-achat")]');
  }


  /** @test */
  public function linkToConfigModulesRechercheShouldHaveActionResultatAction2Simple() {
    $this->assertXPath('//a[contains(@href, "admin/modules/recherche/config/site/type_module/recherche/id_profil/2/action1/resultat/action2/simple")]');
  }
}




class RechercheControllerSimpleActionWithWrongParametersTest
  extends RechercheControllerSimpleActionTestCase {

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

    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/zork');
  }


  /** @test */
  public function pageShouldDisplayResults() {
    $this->assertXPathContentContains('//div', 'pomme');
  }
}




class RechercheControllerSimpleActionWithNoResultsTest
  extends RechercheControllerSimpleActionTestCase {

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

    $this->dispatch('/recherche/simple/expressionRecherche/%nuaisteauei');
  }


  /** @test */
  public function pageShouldDisplayAucunResultatTrouve() {
    $this->assertXPathContentContains('//div//div//h2',
                                      'Aucun résultat trouvé');
  }
}




abstract class RechercheControllerSimpleActionListeFormatTestCase
  extends AbstractControllerTestCase {

  protected
    $_liste_format,
    $_search_term_editable = 0,
    $_nb_par_page = 10;

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

    Class_CosmoVar::newInstanceWithId('types_docs',
                                      ['liste' =>  "1:cd\r\n200:non identifié\r\n201:livres\r\n202:bd"]);

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => [
                                                            'liste_format' => $this->_liste_format ,
                                                            'liste_codes' => "TANWCR",
                                                            'liste_nb_par_page' => $this->_nb_par_page,
                                                            'search_term_editable' => $this->_search_term_editable]]])
      ->setSelTypeDoc('1;2;3;4;5');

    $this->fixture(Class_Bib::class,
                   ['id' => 1,
                    'sigb_exemplaire' =>  false,
                    'libelle' => 'Tombouctou']);
    $this->fixture(Class_IntBib::class,
                   ['id' => 1,
                    'nom_court' => 'Annecy',
                    'comm_sigb' => null
                   ]);
    $this->fixture(Class_TypeDoc::class,
                   [ 'id' => 1,
                     'label' => 'Livres']);
    $this->fixture(Class_TypeDoc::class,
                   [ 'id' => 2,
                     'label' => 'Périodique']);

    $potter_marc = file_get_contents(ROOT_PATH.'/tests/fixtures/dvd_potter.uni');
    $fetch_all_result = [];
    foreach(range(1, 15) as $id) {
      $this->fixture(Class_Notice::class,
                     ['id' => $id,
                      'type_doc' => Class_TypeDoc::LIVRE,
                      'titres' => (Class_Indexation::getInstance()
                                   ->codeAlphaTitre('Harry potter contre le monde')),
                      'unimarc' => $potter_marc,
                      'annee' => 2010,
                      'collection' => 'Potter',
                      'url_vignette' => 'hp.png',
                      'url_image' => 'hp_big.png',
                      'facettes' => 'T1 B1 D123 A400 Y2',
                      'clef_oeuvre' => 'HPELPA',
                      'clef_alpha' => 'POTTER',
                      'exemplaires' => []]);
      $fetch_all_result []= [$id, 'B1 T1 A1234'];
    }

    $this->fixture(Class_CodifAuteur::class,
                   ['id' => 1234,
                    'libelle' => 'Chris Columbus',
                    'formes' => 'COLUMBUSxCHRIS']);

    $mock_sql = $this->mock()
                     ->whenCalled('fetchAll')
                     ->answers($fetch_all_result);

    Zend_Registry::set('sql', $mock_sql);
  }
}




class RechercheControllerSimpleActionWithListeFormatMurTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected
    $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR,
    $_nb_par_page = 5;

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

    Class_AdminVar::set('AUTHOR_PAGE', 0);
    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2');
  }


  /** @test **/
  public function resumeNoticeLinkShouldBeReset() {
    $sql = Zend_Registry::get('sql');
    $this->assertXPathContentContains('//head/script', "/noticeajax/resumenotice';");
  }


  /** @test */
  public function pageShouldContainsDivNotice() {
    $this->assertXPath('//div[@class="liste_mur"]//div[@class="notice"]');
  }


  /** @test */
  public function urlForSousFacettesShouldContainsFacettesT1AndB1() {
    $this->assertXPath('//div[@class="facette"]//a[contains(@href,"/facettes/T1-B1")]');
  }


  /** @test */
  public function urlForSousFacettesShouldNotContainsPage() {
    $this->assertNotXPath('//div[@class="facette"]//a[contains(@href,"/page/2")]');
  }


  /** @test */
  public function urlForAuthorInRecordReboundShouldNotContainsPage() {
    $this->assertXPath('//span[@class="notice_auteur"]//a[contains(@href,"code_rebond/A")][not(contains(@href, "page/2"))]');
  }


  /** @test */
  public function criteresRechercheShouldContainsBibTombouctou() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div[2]', 'Bibliothèque: Tombouctou');
  }


  /** @test */
  public function facetteBibAnnecyShouldHaveLinkToRemove() {
    $this->assertXPath('//div[@class="criteres_recherche"]//div[2]//a[@href="/recherche/simple/expressionRecherche/potter/facettes/T1"]');
  }


  /** @test */
  public function criteresRechercheShouldContainsTypeDocLivre() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div', 'Type de document: Livre');
  }


  /** @test */
  public function iconeSupportShouldHaveTitleDocTypeLivres() {
    $this->assertXPath('//img[@class="icone_support"][@title="Type de document: Livres"]');
  }


  /** @test */
  public function pageShouldBeAccessible() {
    $this->assertAccessible(false);
  }
}




class RechercheControllerListeVignetteHTML5Test
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected
    $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_VIGNETTES,
    $_nb_par_page = 5,
    $_search_term_editable = 1;

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

    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2');
  }


  /** @test */
  public function pageResultatMurShouldBeHTML5Valid() {
    $this->assertHTML5();
  }
}




class RechercheControllerListeCodeWithNouveauteTest
  extends RechercheControllerNoticeTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR;

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

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

    $this->fixture(Class_Notice::class,
                   ['id' => 8,
                    'clef_alpha' => 'Nouvelle année',
                    'titre_principal' => 'Nouvelle année',
                    'titres' => 'HELLO',
                    'type' => 1,
                    'facettes' => 'T1',
                    'clef_oeuvre' => 'NA',
                    'url_vignette' => 'no',
                    'url_image' => 'no',
                    'date_creation' => '2013-12-30']);

    $this->fixture(Class_Notice::class,
                   ['id' => 9,
                    'clef_alpha' => 'New Year',
                    'clef_oeuvre' => 'NY',
                    'titres' => 'HELLO',
                    'type' => 1,
                    'facettes' => 'T1',
                    'url_vignette' => 'no',
                    'url_image' => 'no',
                    'date_creation' => '2013-12-30']);

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => [
                                                            'liste_format' => $this->_liste_format ,
                                                            'liste_codes' => "TAN9"]]]);
  }


  /** @test **/
  public function pageShouldContainsNoticeWithDivNouveauté() {
    $this->dispatch('/recherche/simple/expressionRecherche/hello/tri/%2A/facette/T1/');

    $this->assertXPathContentContains('//div[@class="liste_mur"]//div[@class="notice"]//span[@class="notice_nouveaute"]','Nouveauté');
  }


  /** @test */
  public function withFacetsT1OrT4NoticeNouvelleAnneeShouldBeFind() {
    $this->dispatch('/recherche/simple/expressionRecherche/hello/tri/%2A/multifacets/T1-T4/');

    $this->assertXPathContentContains('//div[@class="notice"]//span[@class="notice_titre"]/a', 'Nouvelle année');
  }
}




class RechercheControllerFacetteSelectedTest extends AbstractControllerTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR;

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

    ZendAfi_Auth::getInstance()->clearIdentity();
    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => [
                                                            'liste_format' => $this->_liste_format ,
                                                            'liste_codes' => "TANECR"]]])
      ->setSelTypeDoc('1;2;3;4;5');

    $this->fixture(Class_Notice::class,
                   ['id' => 8,
                    'titres' => 'HELLO',
                    'type' => 1,
                    'facettes' => 'T1',
                    'clef_alpha' => 'Hello',
                    'titre_principal' => 'Hello',
                    'clef_oeuvre' => 'NA',
                    'url_vignette' => 'no',
                    'url_image' => 'no',
                    'date_creation' => '2013-12-30']);

    $this->fixture(Class_Notice::class,
                   ['id' => 9,
                    'titres' => 'HELLO',
                    'type' => 1,
                    'facettes' => 'T1',
                    'clef_alpha' => 'Hello',
                    'clef_oeuvre' => 'NY',
                    'url_vignette' => 'no',
                    'url_image' => 'no',
                    'date_creation' => '2013-12-30']);

    $this->dispatch('/recherche/simple/expressionRecherche/hello/tri/%2A/facette/T1');
  }


  /** @test */
  public function pageShouldContainsDivNotice() {
    $this->assertXPath('//div[@class="liste_mur"]//div[@class="notice"]');
  }


  /** @test */
  public function pageShouldContainsFacettes() {
    $this->assertXPath('//div[@class="facette"]');
  }


  /** @test */
  public function facetteLivresShouldBeChecked() {
    $this->assertXPath('//div[@class="facette"]//li[contains(@class," selected")]');
  }


  /** @test */
  public function liFacetteLivresShouldHaveSiblingsAWidthHrefRemoveFacetteLivre() {
    $this->assertXPath('//div[@class="facette"]//li[contains(@class," selected")]/a[@href="/recherche/simple/expressionRecherche/hello/tri/%2A"]');
  }
}




class RechercheControllerSimpleActionLibelleFacetteTest
  extends RechercheControllerNoticeTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR;

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

    Class_AdminVar::set('FACETTE_AUTEUR_LIBELLE', 'Les super auteurs');
    Class_AdminVar::set('FACETTE_DEWEY_LIBELLE', 'DEWEY ?!@');

    $this->fixture(Class_CodifGenre::class,
                   ['id' => 19,
                    'libelle' => 'Manga']);

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 2,
                    'libelle' => 'Sujet géographique',
                    'id_thesaurus' => 'SUJE',
                    'id_origine' => '',
                    'code' => 'SUJE',
                    'rules' => null,
                    'index_labels' => true]);

    $this->dispatch('/recherche/simple/?'.
                    'operateur_titres=and'.
                    '&rech_titres='.
                    '&operateur_auteurs=and'.
                    '&rech_auteurs=musso'.
                    '&operateur_matieres=and'.
                    '&rech_matieres='.
                    '&operateur_dewey=and'.
                    '&rech_dewey=pomme'.
                    '&operateur_editeur=and'.
                    '&rech_editeur=l%27ecole'.
                    '&operateur_collection=and'.
                    '&rech_collection='.
                    '&type_recherche=fulltext'.
                    '&tri=*'.
                    '&annee_debut='.
                    '&annee_fin='.
                    '&nouveaute='.
                    '&annexe='.
                    '&genre=1%3B19'.
                    '&section='.
                    '&rech_thesaurus_SUJE=Japon'.
                    '&rech_thesaurus_UNKN=Unknown+stuff');
  }


  /** @test */
  public function criteresRechercheShouldContainsLesAuteurs() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div',
                                      'Les super auteurs');
  }


  /** @test */
  public function criteresRechercheShouldContainsGenreMangaOrSpectacle() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div//a[@href="/recherche/simple/operateur_auteurs/and/rech_auteurs/musso/operateur_dewey/and/rech_dewey/pomme/operateur_editeur/and/rech_editeur/l%27ecole/type_recherche/fulltext/tri/%2A/rech_thesaurus_SUJE/Japon/rech_thesaurus_UNKN/Unknown+stuff"]',
                                      'Genre: spectacle OU Manga');
  }


  /** @test */
  public function criteresRechercheShouldContainsLEcole() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div//a[@href="/recherche/simple/operateur_auteurs/and/rech_auteurs/musso/operateur_dewey/and/rech_dewey/pomme/type_recherche/fulltext/tri/%2A/genre/1%3B19/rech_thesaurus_SUJE/Japon/rech_thesaurus_UNKN/Unknown+stuff"]',
                                      'Éditeur : l\'ecole');
  }


  /** @test */
  public function criteresRechercheShouldContainsDEWEY() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div', 'DEWEY ?!@');
  }


  /** @test */
  public function criteresRechercheShouldContainsSujetGéographiqueJaponWithUrlWithoutCriteria() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div/a[not(contains(@href, "rech_thesaurus_SUJE/Japon/"))][contains(@href, "rech_thesaurus_UNKN")]',
                                      'Sujet géographique : Japon');
  }


  /** @test */
  public function criteresRechercheShouldContainsUnknownCriteria() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//div/a[not(contains(@href, "rech_thesaurus_UNKN"))][contains(@href, "rech_thesaurus_SUJE")]',
                                      'UNKN : Unknown stuff');
  }
}




class RechercheControllerSimpleActionWithListeFormatVignettesTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_VIGNETTES;

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

    Class_Notice::find(15)->set_subfield(225, 'a', 'Collection potter');
    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facettes/B1/page/2');
  }


  /** @test */
  public function popupLoginShouldBeInitialized() {
    $this->assertXPathContentContains('//script', 'initializePopups');
  }


  /** @test */
  public function linkAddToCartShouldBePresent() {
    $this->assertXPath('//div[@class="vignette_lien_panier"]//a[contains(@href, "/panier/add-record-ajax/id_notice/")][@data-popup="true"]');
  }


  /** @test */
  public function pageShouldContainsDivListeVignette() {
    $this->assertXPath('//div[@class="liste_vignettes"]');
  }


  /** @test */
  public function pageShouldContainsTdAnnee() {
    $this->assertXPathContentContains('//div[@class="liste_vignettes"]//dt', 'Année');
  }


  /** @test */
  public function pageShouldContainsTdEditeur() {
    $this->assertXPathContentContains('//div[@class="liste_vignettes"]//dt', 'Editeur');
  }


  /** @test */
  public function pageShouldContainsTdCollection() {
    $this->assertXPathContentContains('//div[@class="liste_vignettes"]//dt', 'Collection');
  }


  /** @test */
  public function pageShouldContainsTdResume() {
    $this->assertXPathContentContains('//div[@class="liste_vignettes"]//dt', 'Résumé');
  }


  /** @test */
  public function pageShouldContainsButterflyLibraryLoading() {
    $this->assertXPathContentContains('//script/@src', 'butterfly.min.js');
  }


  /** @test */
  public function noticeUrlShouldContainsExpressionRecherchePotter() {
    $this->assertXPath('//div[@class="vignette_titre"]//a[contains(@href,"expressionRecherche/potter")]');
  }
}




class RechercheControllerSimpleActionWithListeFormatVignettesHtml5ValidTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_VIGNETTES;

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

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => [
                                                            'liste_format' => $this->_liste_format ,
                                                            'liste_nb_par_page' => 5,
                                                            'search_term_editable' => $this->_search_term_editable]]]);

    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facettes/B1/page/2');
  }


  /** @test */
  public function searchResultShouldBeHtml5Valid() {
    $this->assertHTML5();
  }
}




class RechercheControllerSimpleActionWithListeFormatChronoTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_CHRONO;

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

    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2');
  }


  /** @test */
  public function pageShouldContainsDivListeChrono() {
    $this->assertXPath('//div[@class="liste_chrono"][@id="liste_chrono_1"]');
  }


  /** @test */
  public function timelineJSShouldBeLoaded() {
    $this->assertXPath('//script[contains(@src, "public/opac/TimelineJS3-3.5.1/compiled/js/timeline-embed.js")]');
  }


  /** @test */
  public function createStoryJSFunctionShouldBeIncluded() {
    $this->assertXPathContentContains('//script', 'createStoryJS');
    $this->assertXPathContentContains('//script', '"embed_id":"liste_chrono_3"');
  }


  /** @test */
  public function withListeFormat3InUrlShouldDisplayWithModeVignettes() {
    $this->bootstrap();
    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2/liste_format/3');
    $this->assertXPath('//div[@class="liste_vignettes"]');
  }
}




class RechercheControllerSimpleActionWithListeFormatTableauTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_TABLEAU;

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

    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2');
  }


  /** @test */
  public function pageShouldContainsTdWithListeTitres() {
    $this->assertXPath('//td[@class="listeTitre"]');
  }
}




class RechercheControllerSimpleByISBNActionTest
  extends RechercheControllerSimpleActionTestCase {

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

    $this->dispatch('/recherche/simple/expressionRecherche/2-203-00119-4');
  }


  /** @test */
  public function pageResultatRechecheShouldBeDisplayed() {
    $this->assertXPathContentContains('//span', '2-203-00119-4');
  }
}




class RechercheControllerRebondTest extends AbstractControllerTestCase {

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

    $this->dispatch('/recherche/simple/expressionRecherche/Potter/code_rebond/T1/tri/alpha_titre asc');
  }


  /** @test */
  public function comboTriShouldHaveAnneePublicationSelected() {
    $this->assertXPathContentContains('//select[@id="tri"]//option[@value="alpha_titre asc"][@selected="selected"]',
                                      'Titre');
  }


  /** @test */
  public function lienRetourRechercheInitialeShouldBeRechercheSimple() {
    $this->assertXPathContentContains('//a[@href="/recherche/saisie/expressionRecherche/Potter/tri/alpha_titre+asc"]',
                                      'Retour');
  }


  /** @test */
  public function lienNouvelleRechercheShouldBeRechercheSimple() {
    $this->assertXPathContentContains('//a[@href="/recherche/simple"]',
                                      'Nouvelle recherche');
  }
}




class RechercheControllerRebondWithFacettesTest extends AbstractControllerTestCase {

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

    $this->fixture(Class_CodifMatiere::class,
                   ['id' => 111,
                    'libelle' => 'Geo FRANCE']);

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'type' => 1,
                    'facettes' => 'T1 M111',
                    'titres' => 'FRANCE']);

    $this->dispatch('/recherche/simple/expressionRecherche/france/facette/T1/tri/alpha_titre/page/2');
  }


  /** @test */
  public function rebondUrlShouldNotContainsFacettesAndPage() {
    $this->assertXPath("//div[@class=\"nuage\"]//a[contains(@href,'/recherche/simple/expressionRecherche/france/tri/alpha_titre/code_rebond/')]");
  }
}




class RechercheControllerWithPanierTest extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'clef_alpha' => 'COMBAT ORDINAIRE']);

    $this->fixture(Class_Notice::class,
                   ['id' => 12,
                    'clef_alpha' => 'BLACKSAD']);

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => ['liste_nb_par_page' => 1]]]);

    Class_PanierNotice::newInstanceWithId(2,
                                          ['id_panier' => 1,
                                           'libelle' => 'Mes BD',
                                           'date_maj' => '10/02/2011',
                                           'notices' => 'COMBAT ORDINAIRE;BLACKSAD']);

    $this->dispatch('/recherche/simple/id_panier/2/retour_panier/2');
  }


  /** @test */
  public function retourRechercheInitialeShouldLinkToPanierAbonne() {
    $this->assertXPath('//a[contains(@href, "/panier/index/id_panier/2")]');
  }


  /** @test **/
  public function MesBDLibelleShouldBeDisplay() {
    $this->assertXPathContentContains('//span', "Mes BD");
  }


  /** @test */
  public function urlPage2ShouldBeRechercheSimpleWithIdPanerAndRetourAndPage2() {
    $this->assertXPath('//a[contains(@href,"/recherche/simple/id_panier/2/retour_panier/2/page/2")]');
  }


  /** @test */
  public function orderSelectShouldHaveBasketOrderSelected() {
    $this->assertXPathContentContains('//select[@name="tri"]/option[@value="*"][@selected="selected"]', 'Ordre du panier');
  }
}




class RechercheControllerSimpleActionWithCatalogueAndDomainBrowserWidgetTest
  extends RechercheControllerSimpleActionTestCase {

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

    Class_CodifThesaurus::beVolatile();

    $mock_moteur_recherche = $this->mock();
    $mock_search_result = $this->mock();
    $mock_moteur_recherche
      ->whenCalled('lancerRecherche')
      ->willDo(
               function($criteres) use ($mock_search_result){
                 $mock_search_result
                   ->whenCalled('getCriteresRecherche')
                   ->answers($criteres)
                   ->whenCalled('getMatchingSearchTerms')
                   ->answers([]);
                 return $mock_search_result;
               });

    $settings = Class_Profil::getCurrentProfil()->getSearchResultSettings();
    $settings['liste_format'] = 3;

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

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

      ->whenCalled('hasRecords')
      ->answers(true)

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

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

      ->whenCalled('fetchRecords')
      ->answers([ $this->notice ])

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

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

      ->whenCalled('setDuration')
      ->answers($mock_search_result)

      ->whenCalled('getDuration')
      ->answers(0.5)

      ->whenCalled('setSettings')
      ->answers($mock_search_result)

      ->whenCalled('getSettings')
      ->answers($settings)

      ->whenCalled('getRecords')
      ->answers([$this->fixture('Class_Notice',
                                ['id' => 1])])

      ->whenCalled('shouldDisplaySearchExtensionAboveFacet')
      ->answers(false)
      ;

    Class_MoteurRecherche::setInstance($mock_moteur_recherche);

    Class_Profil::getCurrentProfil()
      ->updateModuleConfigAccueil(9,
                                  ['type_module' => 'DOMAIN_BROWSER',
                                   'division' => 1,
                                   'id_module' => 9,
                                   'preferences' => ['display_mode' => Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR,
                                                     'root_domain_id' =>4
                                   ]])
      ->updateModuleConfigAccueil(10,
                                  ['type_module' => 'RSS',
                                   'division' => 1,
                                   'id_module' => 10,
                                  ]);

    $this->fixture(Class_Catalogue::class,
                   ['id' => 4,
                    'libelle' => 'A',
                    'domaine_parent' => $this->fixture(Class_Catalogue::class,
                                                       ['id' => 3,
                                                        'libelle' => 'Nouveautés'])]);
    Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultatsimple' => ['search_term_editable' => 0]]]);
  }


  /** @test **/
  public function onRechercheSimpleCatalogue3IdModule9LibelleNouveautesShouldBeDisplay() {
    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9');
    $this->assertXPathContentContains('//div[@class="expression-recherche"]',
                                      'Nouveautés');
  }


  /** @test **/
  public function onRechercheSimpleCatalogue3IdModule9OrderByTitreShouldBeOrderByTitle() {
    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/tri/alpha_titre asc');
    $this->assertXPath('//select[@name="tri"]//option[@value="alpha_titre asc"][@selected="selected"]');
  }


  /** @test */
  public function onRechercheSimpleCatalogue3IdModule9BreadcrumbShouldBeDisplayed() {
    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9');
    $this->assertXPath('//div[@class="domains liste_mur"]//div[@class="breadcrumb"]//a[@href="/"]');
  }


  /** @test */
  public function onRechercheSimpleCatalogue3IdModule9BreadcrumbPageShouldBeHtml5Valid() {
    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/liste_format/4');
    $this->assertHTML5();
  }


  /** @test */
  public function onRechercheSimpleCatalogue3IdModule10BreadcrumbShouldNotBeDisplayed() {
    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/10');
    $this->assertNotXPath('//div[@class="domains liste_mur"]//div[@class="breadcrumb"]');
  }
}




class RechercheControllerSimpleActionWithCatalogueAndNoParentsTest
  extends RechercheControllerSimpleActionTestCase {

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

    Class_CodifThesaurus::beVolatile();

    $this->fixture(Class_Catalogue::class,
                   ['id' => 4,
                    'libelle' => 'A',
                    'domaine_parent' => $this->fixture(Class_Catalogue::class,
                                                       ['id'=>3,
                                                        'libelle' => 'Nouveautés'])]);

    Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultatsimple' => ['search_term_editable' => 0]]]);

    $this->dispatch('/recherche/simple/id_catalogue/3');
  }


  /** @test **/
  public function catalogueLibelleShouldBeDisplay() {
    $this->assertXPathContentContains('//div[@class="expression-recherche"]', "Nouveautés");
  }


  /** @test **/
  public function removableFacetCatalogueShouldBeDisplay() {
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a[@href="/recherche/simple"]', "Nouveautés");
  }


  /** @test */
  public function catalogueBreadcrumbShouldNotDisplay() {
    $this->assertNotXPath('//div[@class="liste_mur breadcrumb_domains"]');
  }
}




class RechercheControllerActionSimpleWithResetTest
  extends RechercheControllerNoticeTestCase {

  /** @test */
  public function responseShouldRedirectToActionSaisie() {
    $this->dispatch('/recherche/simple/statut/reset');
    $this->assertRedirectTo('/opac/recherche/saisie');
  }
}




class RechercheControllerAjoutNoticePanierUrlMurTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR;

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

    ZendAfi_Auth::getInstance()->clearIdentity();

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'titres' => 'POMME',
                    'type' => 1,
                    'facettes' => 'T1']);

    $this->fixture(Class_Catalogue::class,
                   ['id' => 34,
                    'libelle' => 'Les BDs',
                    'langue' => 'fr',
                    'indexer' => true]);

    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur asc');
  }


  /** @test */
  public function pommeShouldBePresentInRedirectedPageAsResultatInSession() {
    $this->assertXPathContentContains('//div', 'pomme');
  }


  /** @test */
  public function correctPunctuationSpacesShouldBeDisplayed() {
    $this->assertXPathContentContains('//div',"pour : ");
  }


  /** @test */
  public function pageShouldContainsLinkToSuggestionAchats() {
    $this->assertXPathContentContains('//a[contains(@href, "/abonne/suggestion-achat")]',
                                      'Suggérer un achat');
  }


  /** @test */
  public function selectedTriShouldBeAlphaAuteur() {
    $this->assertXPath('//select[@name="tri"]//option[@value="alpha_auteur asc"][@selected="selected"]');
  }


  /** @test */
  public function withOutLoggedUserPopupLoginShouldBeInitialized() {
    $this->assertXPathContentContains('//script', 'initializePopups');
  }


  /** @test */
  public function linksAjoutPanierShouldHaveDataPopupTrue() {
    $this->assertXPath('//a[contains(@href, "/panier/add-record-ajax/id_notice/")][@data-popup="true"]');
  }


  /** @test */
  public function manageYourBookmarsShouldBePresent() {
    $this->assertXPathContentContains('//div//p', 'Vous devez être connecté pour gérer vos favoris');
  }
}




class RechercheControllerPermalinkMurTest
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR;

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

    ZendAfi_Auth::getInstance()->clearIdentity();
    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2');
  }


  /** @test **/
  public function permalinkShouldBeDisplay() {
    $this->assertXPath('//img[contains(@class, "permalink")][contains(@data-url, "/recherche/viewnotice/clef/POTTER/id/15/expressionRecherche/potter/facettes/T1/facette/B1/page/2")]');
  }
}




abstract class RechercheControllerPermalinkWithIdIntBibTestCase
  extends RechercheControllerSimpleActionListeFormatTestCase {

  protected $_liste_format = Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR;

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

    Class_CosmoVar::setValueOf('mode_doublon',
                               '' . Class_CosmoVar::DOUBLE_SEARCH_NONE);

    Class_Notice::find(15)
      ->setType($this->_getNoticeType())
      ->setExemplaires([$this->fixture(Class_Exemplaire::class,
                                       ['id' => 999,
                                        'type' => $this->_getNoticeType(),
                                        'id_bib' => 1,
                                        'id_int_bib' => 1,
                                        'id_origine' => 1111])])
      ->assertSave();

    $this->_dispatch();
  }


  protected function _dispatch() : void {
    $this->dispatch('/recherche/simple/expressionRecherche/potter/facettes/T1/facette/B1/page/2/id_profil/2');
  }


  protected function _getNoticeType() : int {
    return 0;
  }
}




class RechercheControllerPermalinkWithIdIntBibAndTypeBibliographicTest
  extends RechercheControllerPermalinkWithIdIntBibTestCase {

  protected function _getNoticeType() : int {
    return Class_Notice::TYPE_BIBLIOGRAPHIC;
  }


  /** @test */
  public function permalinkShouldBeDisplay() {
    $this->assertXPath('//img[contains(@class, "permalink")][contains(@data-url, "/recherche/viewnotice/id_sigb/1111/id_int_bib/1")]');
  }


  /** @test */
  public function contextfacebookLinkShouldContainsIdIntBib() {
    $this->assertXPath('//div[contains(@class, "reseaux-sociaux")]/img[contains(@onclick, "id_int_bib")]');
  }


  /** @test */
  public function permalinkShouldNotBeDisplayedWithContextExpressionRecherche() {
    $this->assertNotXPath('//img[contains(@class, "permalink")][contains(@data-url, "id_sigb/1111/id_int_bib/1/expressionRecherche")]');
  }


  /** @test */
  public function permalinkShouldNotBeDisplayedWithIdProfil() {
    $this->assertNotXPath('//img[contains(@class, "permalink")][contains(@data-url, "id_sigb/1111/id_int_bib/1?id_profil")]');
  }


  /** @test */
  public function othersLinkShouldNotBeDisplayedWithIdIntBib() {
    $this->assertNotXPath('//a[contains(@href, "id_sigb/1111/id_int_bib/1")]');
  }


  /** @test */
  public function permalinkWithIdIntBibShouldBeDisplayOnlyOnce() {
    $this->assertXPathCount('//img[contains(@class, "permalink")][contains(@data-url, "/recherche/viewnotice/id_sigb/1111/id_int_bib/1")]', 1);
  }
}




class RechercheControllerPermalinkWithIdIntBibAndTypeBibliographicInTemplateTest
  extends RechercheControllerPermalinkWithIdIntBibTestCase {

  protected function _getNoticeType() : int {
    return Class_Notice::TYPE_BIBLIOGRAPHIC;
  }


  protected function _dispatch() : void {
    $this->_buildTemplateProfil(['id' => '2']);
    parent::_dispatch();
  }


  /** @test */
  public function permalinkViewNoticeWithIdSigb1111AndIdIntBib1ShouldBeDisplay() {
    $this->assertXPath('//body[@data-template="INTONATION"]//a[contains(@class, "view_permalink permalink")][contains(@href, "/recherche/viewnotice/id_sigb/1111/id_int_bib/1")]');
  }


  /** @test */
  public function onlyOneLinkShouldContainIdIntBibOne() {
    $this->assertXPathCount('//a[contains(@href, "id_int_bib/1")]', 1);
  }
}




class RechercheControllerViewNoticePermalinkWithIdIntBibInTemplateTest
  extends RechercheControllerPermalinkWithIdIntBibTestCase {

  protected function _getNoticeType() : int {
    return Class_Notice::TYPE_BIBLIOGRAPHIC;
  }


  protected function _dispatch() : void {
    $sql = Zend_Registry::get('sql');
    $sql
      ->whenCalled('fetchOne')
      ->answers([0])

      ->whenCalled('execute')
      ->answers(null);

    $this->_buildTemplateProfil(['id' => '2']);
    $this->dispatch('/recherche/viewnotice/id/15');
  }


  /** @test */
  public function permalinkViewNoticeWithIdSigb1111AndIdIntBib1ShouldBeDisplay() {
    $this->assertXPath('//body[@data-template="INTONATION"]//a[contains(@class, "view_permalink permalink")][contains(@href, "/recherche/viewnotice/id_sigb/1111/id_int_bib/1")]');
  }


  /** @test */
  public function onlyOneLinkShouldContainIdIntBibOne() {
    $this->assertXPathCount('//a[contains(@href, "id_int_bib/1")]', 1);
  }
}




class RechercheControllerNavigationTest extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Notice::class,
                   ['id' => 28,
                    'type' => 1,
                    'alpha_titre' => 'appolon']);

    $this->fixture(Class_Notice::class,
                   ['id' => 12,
                    'type' => 1,
                    'alpha_titre' => 'ares']);

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'type' => 1,
                    'alpha_titre' => 'poseidon']);

    $this->fixture(Class_Notice::class,
                   ['id' => 99,
                    'type' => 1,
                    'alpha_titre' => 'zeus']);
  }


  /** @test */
  public function navigationSuivantShouldRedirectToId_1_Viewnotice() {
    $this->dispatch('/recherche/viewnotice/id/345/tri/alpha_titre/navigation/suivant');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/1/tri/alpha_titre|');
  }


  /** @test */
  public function navigationPrecedentShouldRedirectToId_12_Viewnotice() {
    $this->dispatch('/recherche/viewnotice/id/345/tri/alpha_titre/navigation/precedent');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/12/tri/alpha_titre|');
  }


  /** @test */
  public function navigationPrecedentOnTheFirstNoticeId_28_ShouldRedirectToId_28() {
    $this->dispatch('/recherche/viewnotice/id/28/tri/alpha_titre/navigation/precedent');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/28/tri/alpha_titre|');
  }


  /** @test */
  public function navigationSuivantOnTheLastNoticeId_99_ShouldRedirectToId_99() {
    $this->dispatch('/recherche/viewnotice/id/99/tri/alpha_titre/navigation/suivant');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/99/tri/alpha_titre|');
  }


  /** @test */
  public function navigationSuivantOnTheFirstNoticeId_28_ShouldRedirectToId_12() {
    $this->dispatch('/recherche/viewnotice/id/28/tri/alpha_titre/navigation/suivant');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/12/tri/alpha_titre|');
  }


  /** @test */
  public function navigationPrecedentOnTheLastNoticeId_99_ShouldRedirectToId_1() {
    $this->dispatch('/recherche/viewnotice/id/99/tri/alpha_titre/navigation/precedent');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/1/tri/alpha_titre|');
  }
}




class RechercheControllerNavigationEmptyResultTest extends RechercheControllerNoticeTestCase {

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

    Class_Notice::find(345)
      ->setType(2)
      ->assertSave();

    $this->fixture(Class_Notice::class,
                   ['id' => 99,
                    'type' => 2,
                    'alpha_titre' => 'zeus']);
  }


  /** @test */
  public function navigationSuivantOnNoticeId_99_ShouldRedirectToCurrentNotice() {
    $this->dispatch('/recherche/viewnotice/id/99/tri/alpha_titre/navigation/suivant');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/99/tri/alpha_titre|');
  }
}




class RechercheControllerNavigationOneResultTest extends RechercheControllerNoticeTestCase {

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

    Class_Notice::find(345)
      ->setType(2)
      ->assertSave();

    $this->fixture(Class_Notice::class,
                   ['id' => 28,
                    'type' => 1,
                    'alpha_titre' => 'appolon']);
  }


  /** @test */
  public function navigationSuivantOnNoticeId_28_ShouldRedirectToCurrentNotice() {
    $this->dispatch('/recherche/viewnotice/id/28/tri/alpha_titre/navigation/suivant');
    $this->assertRedirectRegex('|/recherche/viewnotice/id/28/tri/alpha_titre|');
  }
}




class RechercheControllerViewNoticeWhichIsInMyPanier
  extends RechercheControllerNoticeTestCase {

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

    $this->user = $this->fixture(Class_Users::class,
                                 ['id' => 23,
                                  'pseudo' => 'Pioup',
                                  'nom' => 'Jojo',
                                  'login' => 'Super',
                                  'password' => '123789']);

    ZendAfi_Auth::getInstance()->logUser($this->user);

    $this->panier_bd = $this->fixture(Class_PanierNotice::class,
                                      ['id' => 2,
                                       'id_panier' => 1,
                                       'libelle' => 'Mes BD',
                                       'date_maj' => '10/02/2011',
                                       'notices' => 'POMME;POIRE',
                                       'user' => $this->user]);

    $this->panier_bd_2 = $this->fixture(Class_PanierNotice::class,
                                        ['id' => 3,
                                         'id_panier' => 1,
                                         'libelle' => 'Indispensables',
                                         'date_maj' => '10/02/2011',
                                         'notices' => 'POIRE',
                                         'user' => $this->user
                                        ]);

    $pomme = $this->fixture(Class_Notice::class,
                            ['id' => 10,
                             'titre_principal' => 'Le combat des pommes',
                             'clef_alpha' => 'POMME',
                             'date_creation' => '2010-01']);

    $poire = $this->fixture(Class_Notice::class,
                            ['id' => 12,
                             'titre_principal' => 'Le combat des poires',
                             'clef_alpha' => 'POIRE',
                             'date_creation' => '2010-01']);
  }


  /** @test **/
  public function viewNoticePommeShouldContainsLinkAddToPanier() {
    $this->dispatch('recherche/viewnotice/id/10');
    $this->assertXpath('//div[@class="navigation"]/a[@class="panier dans_panier"]');
  }


  /** @test **/
  public function viewnoticeLinkAddToPanierTitleShouldBeAccessible() {
    $this->dispatch('recherche/viewnotice/id/10');
    $this->assertXpath('//div[@class="navigation"]/a[@title=\'Ajouter "Le combat des pommes" dans un panier\']');
  }


  /** @test **/
  public function viewNoticePommeShouldContainsTagDansPanierBd() {
    $this->dispatch('recherche/viewnotice/id/10');
    $this->assertXpath('//div[@class="flags_notice"]/span[@class="dans_panier"][@title="Dans le panier Mes BD"]');
  }


  /** @test **/
  public function viewNoticePoireShouldContainsTagDansPanierBdAndIndispensables() {
    $this->dispatch('recherche/viewnotice/id/12');
    $this->assertXpath('//div[@class="flags_notice"]/span[@class="dans_panier"][contains(@title, "Mes BD")][contains(@title, "Indispensables")]');
  }


  /** @test **/
  public function withOutLoggedUserFlagsNoticeShouldNotContainsDansPanier() {
    ZendAfi_Auth::getInstance()->clearIdentity();
    $this->dispatch('recherche/viewnotice/id/12');
    $this->assertNotXpath('//div[@class="flags_notice"]/span[@class="dans_panier"]');
  }
}




class RechercheControllerSuggestAjaxActionTest
  extends RechercheControllerNoticeTestCase {

  /** @test */
  public function suggestForHarryPotterShouldNotBeEmpty() {
    Class_Autocomplete_Index::setSearcher(
                                          $this->mock()
                                          ->whenCalled('search')->answers(['Harry à la plage']));

    $this->dispatch('/opac/recherche/suggestajax/startsWith/harry+potter');
    $response = json_decode($this->_response->getBody());
    $this->assertFalse(empty($response));
  }
}




class RechercheControllerViewnoticeWithPreferencesFromOtheProfile
  extends RechercheControllerNoticeTestCase {

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

    $target_pref = ['entete' => 'N'];
    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['viewnotice1' => $target_pref]])
      ->save();

    $locale_pref = ['entete' => 'A'];
    $this->fixture('Class_Profil',
                   ['id' => 15])
         ->setCfgModules(['recherche' => ['viewnotice1' => $locale_pref]]);

    $this->dispatch('/opac/recherche/viewnotice/id_profil/15/id_module/2-4/id/345/id_catalogue/8');
  }


  /** @test */
  public function docTypeShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="entete_notice"]//dd', '2002');
  }


  /** @test */
  public function authorShouldNotBePresent() {
    $this->assertNotXPathContentContains('//div[@class="entete_notice"]//a', 'Bernard Génin');
  }


  /** @test */
  public function backLinkShouldContainsIdCatalog() {
    $this->assertXPath('//a[@class="retour"][contains(@href, "id_catalogue/8")]');
  }
}




abstract class RechercheControllerViewnoticeWithBreadcrumbTestCase
  extends RechercheControllerNoticeTestCase {

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

    Class_Profil::getCurrentProfil()
      ->setBarreNavOn(true);
  }
}




class RechercheControllerViewnoticeWithBreadcrumbAndParamsTest
  extends RechercheControllerViewnoticeWithBreadcrumbTestCase {

  /** @test */
  public function breadcrumbShouldContainsMyTitle() {
    $this->dispatch('recherche/viewnotice/id/345/titre/my-title');
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'my-title');
  }


  /** @test */
  public function breadcrumbWithRubriqueShouldDisplayRechercheGuidee() {
    $this->mock_sql
      ->whenCalled('fetchAll')
      ->with("select * from codif_dewey where id_dewey like '2%' and LENGTH(id_dewey)=2 order by id_dewey")
      ->answers([]);

    $this->dispatch('recherche/viewnotice/id/345/rubrique/D2');
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'Recherche guidée');
  }
}




class RechercheControllerViewnoticeWithBreadcrumbAndIdModuleParamTest
  extends RechercheControllerViewnoticeWithBreadcrumbTestCase {

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

    $profil = $this->fixture(Class_Profil::class,
                             ['id' => 18]);
    $profil->setCfgAccueil(['modules' => ['8' => ['division' => 1,
                                                  'type_module' => 'KIOSQUE',
                                                  'preferences' => ['titre' => 'my kiosk']]]])
           ->save();

    $this->dispatch('recherche/viewnotice/id/345/id_module/18-8');
  }


  /** @test */
  public function breadcrumbShouldContainsMyKiosk() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'my kiosk');
  }


  /** @test */
  public function breadcrumbShouldContainsMainTitle() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span[3]', 'Cinéma d\'animation');
  }


  /** @test */
  public function titlePageShouldBeAsExpected() {
    $this->assertXPathContentContains('//title', '- my kiosk - Cinéma d\'animation');
  }
}




class RechercheControllerViewnoticeWithBreadcrumbAndIdCatalogueParamTest
  extends RechercheControllerViewnoticeWithBreadcrumbTestCase {

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

    $this->fixture(Class_Catalogue::class,
                   ['id'=> 2,
                    'libelle' => 'my catalogue']);

    $this->dispatch('recherche/viewnotice/id/345/id_catalogue/2');
  }


  /** @test */
  public function breadcrumbShouldContainsMyCatalogue() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'my catalogue');
  }
}




class RechercheControllerViewnoticeWithBreadcrumbAndIdPanierParamTest
  extends RechercheControllerViewnoticeWithBreadcrumbTestCase {

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

    $this->fixture(Class_PanierNotice::class,
                   ['id'=> 2,
                    'libelle' => 'my panier']);

    $this->dispatch('recherche/viewnotice/id/345/id_panier/2');
  }


  /** @test */
  public function breadcrumbShouldContainsMyPanier() {
    $this->assertXPathContentContains('//div[@class="barre_nav"]//span', 'my panier');
  }


  /** @test */
  public function pageTitleShouldBeAsExpected() {
    $this->assertXPathContentContains('//head', 'my panier - Cinéma d\'animation');
  }
}




class RechercheControllerSimpleActionWithEmptyDomainSettingsTest
  extends AbstractControllerTestCase {

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

    $this->fixture(Class_Catalogue::class,
                   ['id'=>3,
                    'libelle' => 'Nouveautés',
                    'auteur' => 'Paul']);

    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1');
  }


  /** @test */
  public function onRechercheSimpleCatalogue3IdModule9ResultsShouldBeEmpty() {
    $this->assertXPathContentContains('//div[@class="info-recherche"]',
                                      'Aucun résultat trouvé');
  }


  /** @test */
  public function statRechercheEchecShouldHaveBeenCreated() {
    $this->assertNotEmpty(Class_StatRechercheEchec::findAll());
  }
}




class RechercheControllerNoResultOnSubscriberLinkTest
  extends AbstractControllerTestCase {

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

    $this->dispatch('/recherche/simple/retour_abonne/viewavis/retour_avis/8/page/2/id_module/8/code_rebond/G1');
  }


  /** @test */
  public function noResultMesssageShouldBeDisplay() {
    $this->assertXPathContentContains('//div[@class="resultat_recherche"]',
                                      'Aucun résultat trouvé');
  }


  /** @test */
  public function statRechercheEchecShouldNotHaveBeenCreated() {
    $this->assertEmpty(Class_StatRechercheEchec::findAll());
  }
}




class RechercheControllerSimpleActionWithEmptyDomainSettingsAndSiteLinkedTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Catalogue::class,
                   ['id' => 3,
                    'libelle' => 'Nouveautés']);

    $this->fixture(Class_Sitotheque::class,
                   ['id' => 1,
                    'titre' => 'Mon lien',
                    'url' => 'http://monlien.com',
                    'domaine_ids' => 3]);

    Class_Sitotheque::find(1)->index();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' =>
                       ['resultatsimple' =>
                        ['liste_format' =>  Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR]]]);

    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1');
  }


  /** @test */
  public function monLienShouldExistsAsANotice() {
    $this->assertEquals('MON LIEN', Class_Notice::find(346)->getAlphaTitre());
  }


  /** @test */
  public function sitoDomainEShouldExists() {
    $this->assertNotNull(Class_NoticeDomain::find(1));
  }


  /** @test */
  public function onRechercheSimpleCatalogueSitoShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a', 'Mon lien');
  }
}




class RechercheControlleSimpleActionWithMultifacetsThesauriTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 3,
                    'libelle' => 'Document',
                    'libelle_facette' => 'Document',
                    'id_thesaurus' => 'DOCU',
                    'id_origine' => null,
                    'code' => 'DOCU']);

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 30,
                    'libelle' => 'Musique',
                    'libelle_facette' => 'Musique',
                    'id_thesaurus' => 'MUSI',
                    'id_origine' => null,
                    'code' => 'MUSI']);

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 4,
                    'libelle' => 'SIFI',
                    'libelle_facette' => 'Science fiction',
                    'id_thesaurus' => 'DOCU0001',
                    'code' => 'SIFI']);

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 5,
                    'libelle' => 'BD',
                    'libelle_facette' => 'Bande dessinee',
                    'id_thesaurus' => 'DOCU0002',
                    'code' => 'BD']);

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 6,
                    'libelle' => 'BD',
                    'libelle_facette' => 'Manga',
                    'id_thesaurus' => 'DOCU00020001',
                    'code' => 'Manga']);

    $this->fixture(Class_CodifThesaurus::class,
                   ['id' => 31,
                    'libelle' => 'Experimentale',
                    'libelle_facette' => 'Experimentale',
                    'id_origine' => 30,
                    'id_thesaurus' => 'MUSI0001',
                    'code' => 'EXPE']);

    $this->fixture(Class_Article::Class,
                   ['id' => 1,
                    'titre' => 'News of the sprint',
                    'id_user' => 1,
                    'indexation' => 1,
                    'contenu' => 'Articles are going to be auto indexed !',
                    'domaine_ids' => '3']);

    Class_Article::find(1)->index();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' =>
                       ['resultatsimple' =>
                        ['liste_format' =>  Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR]]]);

    $this->dispatch('/recherche/simple/multifacets/HDOCU0001-HDOCU0002-HDOCU00020001-HMUSI0001');
  }


  /** @test */
  public function newsOfTheSPrintShouldExistsAsANotice() {
    $this->assertNotNull(Class_Notice::find(346));
  }
}




class RechercheControlleSimpleActionWithEmptyDomainSettingsAndArticlesLinkedTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Catalogue::class,
                   ['id'=>3,
                    'libelle' => 'News']);

    $this->fixture(Class_Article::class,
                   ['id' => 1,
                    'titre' => 'News of the sprint',
                    'id_user' => 1,
                    'indexation' => 1,
                    'contenu' => 'Articles are going to be auto indexed !',
                    'domaine_ids' => '3']);

    Class_Article::find(1)->index();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' =>
                       ['resultatsimple' =>
                        ['liste_format' =>  Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR]]]);

    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1');
  }


  /** @test */
  public function newsOfTheSPrintShouldExistsAsANotice() {
    $this->assertNotNull(Class_Notice::find(346));
  }


  /** @test */
  public function noticeAuthorShouldBeAsExpected() {
    $this->assertEquals('', Class_Notice::find(346)->getAuteurPrincipal());
  }


  /** @test */
  public function newsOfTheSprintDomainShouldExists() {
    $this->assertNotNull(Class_NoticeDomain::find(1));
  }


  /** @test */
  public function searchOnNewsShouldContainsNewsOfTheSprint() {
    $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a', 'News of the sprint');
  }
}




class RechercheControllerSimpleActionDisableSuggestionTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_AdminVar::class,
                   ['id' => 'DISABLE_SUGGESTIONS',
                    'valeur' => '1']);
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/alpha_auteur');
  }


  /** @test */
  public function pageShouldNotContainsLinkToSuggestAchats() {
    $this->assertNotXPathContentContains('//a[contains(@href, "/abonne/suggestion-achat")]',
                                         'Suggérer un achat');
  }
}




class RechercheControlleSiteInResultAndModeThumbnailTest
  extends RechercheControllerNoticeTestCase {

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

    $this->fixture(Class_Catalogue::class,
                   ['id' => 3,
                    'libelle' => 'Nouveautés']);

    $this->fixture(Class_Sitotheque::class,
                   ['id' => 1,
                    'titre' => 'Mon lien',
                    'url' => 'http://monlien.com',
                    'domaine_ids' => 3]);

    Class_Sitotheque::find(1)->index();

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' =>
                       ['resultatsimple' =>
                        ['liste_format' =>  Class_Systeme_ModulesAppli::LISTE_FORMAT_VIGNETTES]]]);

    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1');
  }


  /** @test */
  public function anchorWithMonLienShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a[contains(@href,"://monlien.com")]', 'Ouvrir le lien dans un nouvel onglet');
  }
}




class RechercheControllerMultiFacettesTest extends RechercheControllerNoticeTestCase {

  /** @test */
  public function postShouldRedirectToMultifacetsT1T4() {
    $this->postDispatch('/recherche/simple/expressionRecherche/pomme/tri/*',
                        ['multifacet_T1' => 1, 'multifacet_T4' => 1]);

    $this->assertRedirectTo('/recherche/simple/expressionRecherche/pomme/tri/%2A/multifacets/T1-T4');
  }


  /** @test */
  public function multifacetsFormShouldContainsExpressionRechercheParamOnSearchResult() {
    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => ['facettes_codes'=>'MFSABZLYHTHEMHTES1V',
                                                            'facettes_actif' => 1]]])
      ->assertSave();

    $this->dispatch('/recherche/simple/expressionRecherche/pomme');
    $this->assertXPath('//div[@class="facette"]/form[@method="POST"][@action="/recherche/simple/expressionRecherche/pomme"]');
  }


  /** @test */
  public function activeFacetsShouldBeT1OrT4() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/multifacets/T1-T4');

    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a', 'Type de document: Livres OU DVD');
  }


  /** @test */
  public function postQueryWithoutMultifacetsShouldRedirectToZendFormedUrl() {
    $this->postDispatch('/recherche/simple',
                        ['expressionRecherche' => 'pear']);
    $this->assertRedirectTo('/recherche/simple/expressionRecherche/pear');
  }


  /** @test */
  public function activeFacetsShouldBeT3() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/multifacets/T3');

    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a', 'Type de document: Disques');
  }


  /** @test */
  public function activeFacetsShouldBeT1OrT4OrT3() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/multifacets/T3-T4/facettes/T1');


    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a', 'Type de document: Livres');
    $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a', 'Type de document: Disques OU DVD');
  }
}




class RechercheControllerSimpleSearchTest extends AbstractControllerTestCase {

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

    Class_CriteresRecherche::setMaxSearchResults(2);

    $this->fixture(Class_Notice::class,
                   ['id' => 1,
                    'type' => 1]);

    $this->fixture(Class_Notice::class,
                   ['id' => 2,
                    'type' => 1]);

    $this->dispatch('/opac/recherche/simple/expressionRecherche/*');
  }


  public function tearDown() {
    Class_CriteresRecherche::setMaxSearchResults('');
    parent::tearDown();
  }


  /** @test */
  public function limitedToTwoResultShouldBeDisplay() {
    $this->assertXPathContentContains('//div', 'Il y a plus de ');
  }
}




class RechercheControllerNoExtensionTest extends AbstractControllerTestCase {

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

    $this->fixture(Class_AdminVar::class,
                   ['id' => 'EXTENDED_SEARCH',
                    'valeur' => '0']);

    $this->dispatch('/opac/recherche/simple/expressionRecherche/La+vie+des+geeks');
  }


  /** @test */
  public function noResultShouldBeDisplay() {
    $this->assertXPathContentContains('//div[@class="liste_notices"]/h2', 'Aucun résultat trouvé');
  }
}




class RechercheControllerSimpleAccentsSpeciauxTest extends AbstractControllerTestCase {

  protected $_notice;

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

    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' =>
                       ['resultatsimple' =>
                        ['liste_format' => Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR,
                         'liste_nb_par_page' => 5]]]);

    $this->fixture(Class_Exemplaire::class,
                   [ 'id' => 5,
                     'id_notice' => 1,
                     'id_bib' => $this->fixture(Class_IntBib::class,
                                                ['id' => 4,
                                                 'nom' => 'MaBib',
                                                 'nom_court' => 'MaBib',]),

                     'code_barres' => '12345']);

    $this->_notice =
      $this->fixture(Class_Notice::class,
                     [ 'id' => 1,
                       'type_doc' => 3,
                       'alpha_titre' => 'SYMPHONY N 9   FROM THE NEW WORLD',
                       'alpha_auteur' => 'DVO AK ANTONIN',
                       'titres' =>'SYMPHONY SINFONI 9  FROM THE NEW WORLD ORL MI MINEUR MINER VLTAVA MOLDAU MOLDO BOHEMIA BOEMIA S00 WOODS OU AND FIELDS FIEL',
                       'auteurs' => 'DVORAK ANTONIN SMETANA BEDRICH KUBELIK RAFAEL RAFEL BERLINER BERLIN PHILHARMONIKER FILARMONIK KUBEL KUBELXIKXRAFAEL KUBELXIKXRAFEL 1914 1996 BLECHBL ASER AS ENSEMBLE ANSANBL DER',
                       'unimarc' =>'01170njm0 2200313   450 0010009000000050017000090350016000260710044000420730018000861000041001041010008001451260025001531270011001782000140001892100030003292150011003593300131003704640066005014640041005674640053006086860015006617000038006767010037007147020036007517110033007878010022008209900006008429960008008481/39108020201010142545.0  aGAM1269595800a4783378bDeutsche Grammophond12,85 EUR 0a0028947833789  a20200525d2011    u  y0frey0103    ba0 azxx  aagbzhxxe     cdbbex  a0108001 aSymphony N?9, "From the New World"fAntonin DvorakgBedrich SmetanagRafael KubelikgBoston Symphony OrchestragBerliner Philharmoniker  cDeutsche Grammophond2011  a1 d.c.  a<iframe src="https://www.gamannecy.com/upload/htmls/0028947833789.html" width="100%" height="360px" frameborder="0" ></iframe> 0tSymphony N?9, "From the New World", mi mineurfAntonin Dvorak 0tVltava (The Moldau)fBedrich Smetana 0tFrom Bohemia\'s woods and fieldsfBedrich Smetana  a3.242pcdm 14230aDvo?ákbAntonínf1841-1904 14230aSmetanabBedrichf1824-1884 14250aKubelikbRafaelf1914-196702aBerliner Philharmoniker4545 0aFRbGAMc20200525  a1  fMUS']);

    $this->dispatch('/recherche/simple/expressionRecherche/Dvořák');
  }


  /** @test */
  public function pageShouldContainsSymphonyN9() {
    $this->assertXPathContentContains('//a[contains(@href,"viewnotice/id/1")]', 'Symphony');
  }
}




class RechercheControllerWithEmptyPanierTest extends AbstractControllerTestCase {

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

    $this->_buildTemplateProfil(['id' => 789]);

    $this->fixture(Class_PanierNotice::class,
                   ['id' => 289,
                    'libelle' => 'panier vide']);

    $this->dispatch('/recherche/simple/id_panier/289');
  }


  /** @test */
  public function shouldRenderNoResult() {
    $this->assertXPathContentContains('//p', 'Aucun résultat');
  }
}