Skip to content
Snippets Groups Projects
RechercheControllerTest.php 145 KiB
Newer Older
llaffont's avatar
llaffont committed
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
 * BOKEH is free software; you can redistribute it and/or modify
llaffont's avatar
llaffont committed
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation.
 *
 * There are special exceptions to the terms and conditions of the AGPL as it
 * is applied to this software (see README file).
 *
Laurent's avatar
Laurent committed
 * BOKEH is distributed in the hope that it will be useful,
llaffont's avatar
llaffont committed
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
Laurent's avatar
Laurent committed
 * along with BOKEH; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
abstract class RechercheControllerNoticeTestCase extends AbstractControllerTestCase {
  protected $_storm_default_to_volatile = true;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    $this->fixture(Class_CodifAuteur::class,
Patrick Barroca's avatar
Patrick Barroca committed
                   ['id' => 123,
                    'libelle' => 'Bernard Génin']);

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

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

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

Patrick Barroca's avatar
Patrick Barroca committed
                   ['id' => 3,
                    'libelle' => 'enfants']);

    $this->fixture(Class_CodifPcdm4::class,
Patrick Barroca's avatar
Patrick Barroca committed
                   ['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)
                           ->whenCalled('fetchAll')->answers([ [1, ''] ]);
    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']);
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
    $this->notice = Class_Notice::newInstanceWithId(345,
                                                    ['annee' => 2002,
                                                     'isbn' => '1-234-56789-0',
                                                     'type_doc' => Class_TypeDoc::LIVRE,
                                                     'url_vignette' => 'NO',
                                                     'url_image' => 'NO',
                                                     'clef_alpha' => 'TESTINGALPHAKEY---101',
Patrick Barroca's avatar
Patrick Barroca committed
                                                     '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_origine' => 12,
                                        'code_barres' => '12256663233656',
                                        'sigb_exemplaire' => ($this->mock()
                                                              ->whenCalled('isReservable')
                                                              ->answers(true))
                                       ])]);
Patrick Barroca's avatar
Patrick Barroca committed

  }
class RechercheControllerPrintTest extends RechercheControllerNoticeTestCase {


    $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());
Ghislain Loas's avatar
Ghislain Loas committed
    $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 {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutBabelthequeJSShouldNotBeLoaded() {
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('');
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertNotXpath('//script[contains(@src, "babeltheque.js")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withBabelthequeJSShouldBeLoadedWithRightId() {
    Class_AdminVar::newInstanceWithId('BABELTHEQUE_JS')->setValeur('http://www.babeltheque.com/bw_666.js');
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
    $this->assertXpath('//script[contains(@src, "babeltheque.js?bwid=666")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeShouldNotHaveTome() {
    $this->notice->setClefChapeau("test")->save();
    $this->dispatch(sprintf('recherche/viewnotice/id/%d', $this->notice->getId()), true);
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertNotXPathContentContains('//div[@class="entete_notice"]',"Voir tous les tomes");
  }
class RechercheControllerPagerTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_notice;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    ZendAfi_Auth::getInstance()->clearIdentity();

    $records = array_map(function($i) { return [$i, ''];}, range(1, 45) );
    $this->mock_sql
      ->whenCalled('fetchAll')
      ->with("select id_notice, facettes from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey, other_terms) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) and MATCH(facettes) AGAINST('+T3' IN BOOLEAN MODE)) and type=1 order by (MATCH(titres) AGAINST(' POMME') * 1.5) + (MATCH(auteurs) AGAINST(' POMME')) desc",
             true,
             false)
      ->answers($records)
      ->beStrict();
    $this->_notice = $this->fixture('Class_Notice',
                                    ['id' => 34,
                                     'clef_oeuvre' => '',
                                     'url_vignette' => Class_WebService_Vignette::NO_DATA,
                                     'url_image' => Class_WebService_Vignette::NO_DATA]);

Patrick Barroca's avatar
Patrick Barroca committed
    $this->onLoaderOfModel('Class_Notice')
         ->whenCalled('findAllByIds')
         ->with(range(1, 45), 10, null)
Patrick Barroca's avatar
Patrick Barroca committed
         ->answers([$this->_notice])
         ->whenCalled('findAllByIds')
         ->with(range(1, 45), 50, null)
Patrick Barroca's avatar
Patrick Barroca committed
         ->answers([$this->_notice])
         ->whenCalled('findAllByIds')
         ->with(range(1, 45), 7, null)
Patrick Barroca's avatar
Patrick Barroca committed
         ->answers([$this->_notice])
Patrick Barroca's avatar
Patrick Barroca committed
         ->beStrict();
  }
efalcy's avatar
efalcy committed
  /** @test */
  public function searchTermShouldNotBeEditable() {
    Class_Profil::getCurrentProfil()->setCfgModules(['recherche' => ['resultatsimple' => ['search_term_editable' => 0,
                                                                                          'header_composition' => 'Advanced']]]);
efalcy's avatar
efalcy committed
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4', true);
    $this->assertXPath('//div[@class="resultats_page"]//div[@class="expression-recherche"][contains(text(), "pomme")]');
efalcy's avatar
efalcy committed
  }


  /** @test */
  public function searchTermShouldBeEditable() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4', true);
    $this->assertXPath('//input[@name="expressionRecherche"][@value="pomme"]');
efalcy's avatar
efalcy committed
  }
  /** @test */
  public function pagerShouldBeDisplayedOnTop() {
    Class_AdminVar::newInstanceWithId('SEARCH_PAGINATE_POSITION', ['valeur' => 'TOP']);
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4', true);
    $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', true);
    $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', true);
    $this->assertXPathCount('//div[@class="pager"]', 2);
  /** @test */
  public function urlPage2ShouldBeWithListeFormatParameter() {
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/liste_format/4', true);
    $this->assertXPath('//a[contains(@href, "/liste_format/4")][contains(@href,"/page/2")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSize10PageFiveShouldBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3', true);
    $this->assertXPath('//a[contains(@href,"/page/5")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSize100PageFiveShouldFallbackToMaximumPageSize50() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/100', true);
    $this->assertXPath('//a[contains(@href,"/page_size/50")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSize10PageSixShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3', true);
    $this->assertNotXPath('//a[contains(@href,"/page/6")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function urlWithPageSizeSevenShouldCallFindAllWithPageSize() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7', true);
    $this->assertXPath('//a[contains(@href, "/page_size/7")][contains(@href,"/page/2")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSizeSevenPageSevenShouldBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7', true);
    $this->assertXPath('//a[contains(@href,"/page/7")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withPageSizeSevenPageHeightShouldNotBePresent() {
    $this->dispatch('/recherche/simple/expressionRecherche/pomme/tri/*/facette/T3/page_size/7', true);
    $this->assertNotXPath('//a[contains(@href,"/page/8")]');
Patrick Barroca's avatar
Patrick Barroca committed
  }
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', true);
  }


  /** @test */
  public function pageShouldContainLinkToRecordsSameCollectionGallimardPoche() {
    $this->assertXPathContentContains('//dd//a[contains(@href,"recherche/simple/id/345/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')
    Class_Profil::getCurrentProfil()
      ->setCfgModules(['recherche' => ['resultatsimple' => [
                                                            'liste_format' => $this->_liste_format ,
                                                            'liste_codes' => "TANC"]]]);

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


  /** @test */
  public function pageShouldContainslinkToRecordSameCollectionPetitsCahiers() {
    $this->assertXPathContentContains('//div//a[contains(@href,"recherche/simple/id/345/rech_collection/Les+petits+cahiers")]',
                                      'Les petits cahiers');
class RechercheControllerViewNoticeWithPreferencesTest extends RechercheControllerNoticeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_web_analytics_client;

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

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

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

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

    $this->fixture(Class_CodifAnnexe::class,
    $this->fixture(Class_Notice::class,
                   ['id' => 678,
                    'type' => Class_Notice::TYPE_AUTHORITY])
         ->addExemplaire($this->fixture(Class_Exemplaire::class,
                                        ['id' => 876,
                                         'type' => Class_Notice::TYPE_AUTHORITY,
                                         'id_bib' => 456,
                                         'id_int_bib' => 456,
                                         'id_origine' => 12]))
         ->assertSave();
  }


  /** @test */
  public function withRightIdsResponseShouldRedirectToViewNoticeId345() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/2');
    $this->assertRedirectTo('/recherche/viewnotice/id/345');
  }


  /** @test */
  public function withIdIntBib1ShouldRedirectToViewNoticeId345() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_int_bib/1');
    $this->assertRedirectTo('/recherche/viewnotice/id/345');
  }


  /** @test */
  public function withIdSIB12AndRecordTypeAuthorityShouldRedirectToViewNoticeId678() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/2/record_type/2');
    $this->assertRedirectTo('/recherche/viewnotice/id/678');
  }


  public function withIdSigbAndIdSiteWildcardShouldRedirectToViewNoticeId345() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/*');
    $this->assertRedirectTo('/recherche/viewnotice/id/345');
  }


  /** @test */
  public function withIdSIB12AndRecordTypeAuthorityIdSiteWildcardShouldRedirectToViewNoticeId678() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/*/record_type/2');
    $this->assertRedirectTo('/recherche/viewnotice/id/678');
  }


  /** @test */
  public function withIdIntBib456AndRecordTypeAuthorityIdSiteWildcardShouldRedirectToViewNoticeId678() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_int_bib/456/record_type/2');
    $this->assertRedirectTo('/recherche/viewnotice/id/678');
  }


  /**
   * @test
   * @expectedException Zend_Controller_Action_Exception
   */
  public function withUnknownIdSiteShouldThrow404() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/3');
  public function withUnknownIdSigbShouldThrow404() {
    $this->dispatch('/recherche/viewnotice/id_sigb/66/id_site/2', false);
  /**
   * @test
   * @expectedException Zend_Controller_Action_Exception
   */
  public function withNoIdSigbShouldThrow400() {
    $this->dispatch('/recherche/viewnotice/id_site/2');
  public function withNoIdSiteShouldThrow400() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12', false);
    $this->assertResponseCode(400);
  }


  /** @test */
  public function withIdIntBib1AndIdSite2ShouldThrow400() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/2/id_int_bib/1',
                    false);
class RechercheControllerViewNoticeByIdSigbFilteredTest extends AbstractControllerTestCase {
  protected $_storm_default_to_volatile = true;

  public function setUp() {
    parent::setUp();
    $this->fixture('Class_CodifAnnexe',
                   ['id' => 1,
                    'id_bib' => 456,
                    'id_origine' => 2]);
    Class_Notice::newInstanceWithId(15,
                                    ['annee' => 1990,
                                     'type_doc' => Class_TypeDoc::ARTEVOD,
                                     'clef_alpha' => 'TESTINGALPHAKEY---101',
                                     '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',
                                       ['id' => 5,
                                        'id_bib' => 456,
                                        'id_int_bib' => 0,
                                        'id_origine' => 12,
                                        'code_barres' => null,
                                       ])]);

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


    Class_Notice::newInstanceWithId(345,
                                    ['annee' => 2002,
                                     'isbn' => '1-234-56789-0',
                                     'type_doc' => Class_TypeDoc::LIVRE,
                                     'url_vignette' => 'NO',
                                     'url_image' => 'NO',
                                     'clef_alpha' => 'TESTINGALPHAKEY---101',
                                     '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',
                                       ['id' => 34,
                                        'id_bib' => 456,
                                        'id_int_bib' => 1,
                                        'id_origine' => 12,
                                        'code_barres' => '12256663233656',
                                        'sigb_exemplaire' => ($this->mock()
                                                              ->whenCalled('isReservable')
                                                              ->answers(true))
                                       ])]);
  }


  /** @test */
  public function withIdSigbAndIdSiteWildcardShouldRedirectToViewNoticeId345() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/*');
    $this->assertRedirectTo('/recherche/viewnotice/id/345');
  }


  /** @test */
  public function withIdSigbAndIdSite2ShouldRedirectToViewNoticeId345() {
    $this->dispatch('/recherche/viewnotice/id_sigb/12/id_site/2');
    $this->assertRedirectTo('/recherche/viewnotice/id/345');
  }
}


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

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

    $this->dispatch('recherche/viewnotice/id/345', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainTitleMeta() {
    $this->assertXPathContentContains('//meta[@property="og:title"]/@content', 'Cinéma d\'animation br/ 3D - Bernard Génin');
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainImageMeta() {
    $this->assertXPathContentContains('//meta[@property="og:image"]/@content', 'http://linux.org/cine_BIG.jpg');
Patrick Barroca's avatar
Patrick Barroca committed
  }
  /** @test */
  public function pageShouldContainOgTypeMeta() {
    $this->assertXPathContentContains('//meta[@property="og:type"]/@content', 'book');
Patrick Barroca's avatar
Patrick Barroca committed
  /** @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');
  }


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

class RechercheControllerThumbnailTest extends RechercheControllerNoticeTestCase {
  /** @test */
  public function rechercheVignetteActionShouldRedirectToRawThumbnailAction() {
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('recherche/vignette/id_notice/345', true);
    $this->assertRedirectTo(Class_Url::absolute('/recherche/raw-thumbnail/id/345'),
                            $this->getResponseLocation());
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function rawThumbnailForIdNoticeTwoShouldAnswerPngImage() {
    $this->dispatch('/recherche/raw-thumbnail/id/345', true);
    $this->assertContains('iVBORw0', base64_encode($this->_response->getBody()));
Patrick Barroca's avatar
Patrick Barroca committed
  }
}



class RechercheControllerVignetteEmptyTest extends AbstractControllerTestCase {
  protected $_storm_default_to_volatile = true;
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_Article::setFileWriter($this->mock()
                                 ->whenCalled('fileExists')
                                 ->with(Class_Url::baseUrl() . '/images/articles/img.png')
                                 ->answers(true)
                                 ->beStrict());

Patrick Barroca's avatar
Patrick Barroca committed
    $article = $this->fixture('Class_Article',
                              ['id' => 123,
                               'titre' => 'An article with img',
                               'contenu' => 'This article should contains an image like this <img src="/images/articles/img.png" />']);
Patrick Barroca's avatar
Patrick Barroca committed
    $article->index();
    $this->dispatch('recherche/vignette/id_notice/1', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
Laurent's avatar
Laurent committed
  public function responseShouldRedirectToRawThumbnailUrl() {
    $this->assertContains(Class_Url::absolute('/recherche/raw-thumbnail/id/1'),
Patrick Barroca's avatar
Patrick Barroca committed
                          $this->getResponseLocation());
  }