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


abstract class RechercheControllerAlbumAudioRecordTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected
    $_notice,
    $_storm_default_to_volatile=true,
Patrick Barroca's avatar
Patrick Barroca committed
    $_codif_auteur_wrapper;


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

    $_http_client = Storm_Test_ObjectWrapper::mock()->whenCalled('open_url')->answers(null);
    Class_WebService_AllServices::setHttpClient($_http_client);

    Class_Notice::setTimeSource(new TimeSourceForTest('2014-01-19 09:00:00'));

    $this->_codif_auteur_wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur');

    Class_CosmoVar::newInstanceWithId('url_site', ['valeur' => 'http://mabib.net']);
    Class_CosmoVar::newInstanceWithId('black_list_856', ['valeur' => 'mabib']);
    Class_CosmoVar::newInstanceWithId('unimarc_zone_titre',
                                      ['valeur' => '200$a;200$e;200$d;200$i;327$a;464$a;461$t;464$t']);


    $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_CodifTypeDoc',
                   ['id' => Class_TypeDoc::AUDIO_RECORD,
                    'famille_id' => Class_CodifTypeDoc::SONORE]);
Patrick Barroca's avatar
Patrick Barroca committed
    $album = $this->fixture('Class_Album',
                            ['id' => 4,
                             'type_doc_id' => Class_TypeDoc::AUDIO_RECORD,
                             'titre' => 'Seventh Son of a Seventh Son',
                             'status' => Class_Album::STATUS_VALIDATED]);
    $this
      ->addAuthorToAlbum($album, 'Iron Maiden')
      ->addAuthorToAlbum($album, 'Bruce Dickinson', 'Chanteur')
      ->addAuthorToAlbum($album, 'Steve Harris', 'Bassiste')
      ->addAuthorToAlbum($album, 'Dave Murray', 'Gutariste')
      ->addAuthorToAlbum($album, 'Nicko McBrain', 'Batteur')
      ->addAuthorToAlbum($album, 'Adrian Smith', 'Guitariste');

    $album
      ->setDistributor('Geffen Records')
      ->addRessource($this->fixture('Class_AlbumRessource',
                                    ['id' => 1,
                                     'titre' => 'Moonchild',
                                     'fichier' => 'moonchild.mp3']))
      ->addRessource($this->fixture('Class_AlbumRessource',
                                    ['id' => 2,
                                     'titre' => 'Infinite Dreams',
                                     'fichier' => 'infinite_dreams.mp3']))
      ->addRessource($this->fixture('Class_AlbumRessource',
                                    ['id' => 3,
                                     'fichier' => 'unknown.mp3']))
      ->addRessource($this->fixture('Class_AlbumRessource',
                                    ['id' => 4,
                                     'fichier' => '502_05_the_prophecy.mp3']));
    $album->getMarc()
          ->addZone('856', ['a' => 'http://mabib.net/bib-numerique/notice/ido/1'])
          ->addZone('856', ['x' => 'external_uri']);

    $album->assertSave();

    $album->index();
    $this->_notice = Class_Exemplaire::findFirstBy(['id_origine' => 4])->getNotice();
  }


  public function addAuthorToAlbum($album, $name, $responsibility = '') {
    $album->addAuthor($name, $responsibility);

    $indexation = new Class_Indexation();
    $code_alpha = str_replace(' ', 'x', $indexation->alphaMaj($name.'|'));
    $author = Class_CodifAuteur::newInstance([ 'formes' => $code_alpha,
                                               'libelle' => $name]);
    $author->save();

    $this->_codif_auteur_wrapper
      ->whenCalled('findFirstBy')
      ->with(['where' => "MATCH(formes) AGAINST('" . $code_alpha . "' IN BOOLEAN MODE)"])
      ->answers($author);
    return $this;
  }
}




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

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

Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/recherche/viewnotice/id/'.$this->_notice->getId(), true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeShouldNotBeNull() {
    $this->assertNotNull($this->_notice);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function clefAlphaShouldBeSEVENTHSON_IRONMAIDEN() {
    $this->assertEquals('SEVENTHSONOFASEVENTHSON--IRONMAIDENBRUCEDICKINSONSTEVEHARRISDAVEMURRAYNICKOMCBRAINADRIANSMITH----109',
                        $this->_notice->getClefAlpha());
  }
Laurent's avatar
Laurent committed


Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeShouldHaveLocalUrlImageSet() {
    $this->assertNotEmpty($this->_notice->getUrlImage());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeShouldHaveLocalUrlVignetteSet() {
    $this->assertNotEmpty($this->_notice->getUrlVignette());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /**
   * @disabledtest
   * en attendant de bien gérer la nouveauté pour les albums bib num (update de notice et non nouvelle création
   */
  public function dateCreationShouldBe2014_01_19() {
    $this->assertEquals('2014-01-19', $this->_notice->getDateCreation());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeShouldNotBeNouveaute() {
    /** en attendant de bien gérer la nouveauté pour les albums bib num */
    $this->assertFalse($this->_notice->isNouveaute());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titrePrincipalShouldBeSeventhSonOfASeventhSon() {
    $this->assertXPathContentContains('//h1',
                                      'Seventh Son of a Seventh Son',
                                      $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeFirstMorceauTitleShouldBeMoonchild() {
    $this->assertEquals('Moonchild',
                        $this->_notice->getMorceaux()['morceaux'][1][1]['titre']);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeFirstMorceauUrlEcouteShouldBeMoonchildDotMP3() {
    $this->assertContains('/bib-numerique/play-ressource/id/1.mp3',
                          $this->_notice->getMorceaux()['morceaux'][1][1]['url_ecoute']);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeSecondMorceauTitleShouldBeInfiniteDreams() {
    $this->assertEquals('Infinite Dreams',
                        $this->_notice->getMorceaux()['morceaux'][1][2]['titre']);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noticeUnknownMorceauTitleShouldBeUnknown() {
    $this->assertEquals('Unknown',
                        $this->_notice->getMorceaux()['morceaux'][1][3]['titre']);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titresFulltextShouldContainsMOONCHILD() {
    $this->assertContains('MOONCHILD',
                          explode(' ', $this->_notice->getRawAttributes()['titres']));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titresFulltextShouldContainsUNKNOWN() {
    $this->assertContains('UNKNOWN',
                          explode(' ', $this->_notice->getRawAttributes()['titres']));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titresFulltextShouldContainsPROPHECY() {
    $this->assertContains('PROPHECY',
                          explode(' ', $this->_notice->getRawAttributes()['titres']));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titresFulltextShouldNotContains502() {
    $this->assertNotContains('502',
                             explode(' ', $this->_notice->getRawAttributes()['titres']));
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function field701a4ShouldContainsBruceDickinsonAsChanteur() {
    $bruce = $this->_notice->getAuteursUnimarc(false, true)[1];
    $this->assertEquals('Bruce Dickinson (Chanteur)', $bruce->getLabel());
    $this->assertEquals(['controller' => 'recherche',
                         'action' => 'simple',
                         'code_rebond' => 'A2'],
                        array_filter($bruce->getUrlParams()));
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function field701a4ShouldContainsIronMaiden() {
    $imaiden = $this->_notice->getAuteursUnimarc(false, true)[0];
    $this->assertEquals('Iron Maiden', $imaiden->getLabel());
    $this->assertEquals(['controller' => 'recherche',
                         'action' => 'simple',
                         'code_rebond' => 'A1'],
                        array_filter($imaiden->getUrlParams()));
Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function anneeShouldBeEmpty() {
    $this->assertEquals('', $this->_notice->getAnnee());
  }
}




class RechercheControllerAlbumAudioRecordViewMorceauxTest extends RechercheControllerAlbumAudioRecordTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/noticeajax/morceaux/id_notice/' . $this->_notice->getId(), true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function moonchildPlayerShouldBePresent() {
    $this->assertXPath('//audio/source[contains(@src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function moonchildTitleShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="notice_info_ligne"]',
                                      '1: Moonchild');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function infiniteDreamsTitleShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="notice_info_ligne"]',
                                      '2: Infinite Dreams');
  }



class RechercheControllerAlbumAudioRecordViewDetailsTest extends RechercheControllerAlbumAudioRecordTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/noticeajax/detail/id_notice/'.$this->_notice->getId(), true);
  }

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

  /** @test */
  public function titresShouldContainsIronMaidenAsCodeRebond() {
    $this->assertXPathContentContains('//dd//a[contains(@href, "code_rebond/A1")]',
                                      'Iron Maiden');
  }

  /** @test */
  public function noUrlShouldBePresent() {
    $this->assertNotXPath('//dt[contains(@class, "internet")]', $this->_response->getBody());
  }


  /** @test */
  public function distributorShouldBeGeffenRecords() {
    $this->assertXPathContentContains('//dl//dd',
                                      'Geffen Records',
                                      $this->_response->getBody());
  }


  /** @test */
  public function shouldNotContainEmptyLink() {
    $this->assertNotXPath('//a[@href="http://"]');
  }


  /** @test */
  public function aDDForAuthorsShouldContainsBruceDickinsonAsChanteur() {
    $this->assertXPathContentContains('//dl//dd//a',
                                      'Bruce Dickinson (Chanteur)',
                                      $this->_response->getBody());
  }
class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends RechercheControllerAlbumAudioRecordTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/noticeajax/resnumeriques/id_notice/'.$this->_notice->getId(), true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function albumPlayerShouldBePresent() {
    $this->assertXPath('//audio[@preload]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function nextTrackLinkShouldBePresent() {
    $this->assertXPath('//div[@class="audio_tracks_control"]/a[@class="next"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function previousTrackLinkShouldBePresent() {
    $this->assertXPath('//div[@class="audio_tracks_control"]/a[@class="previous"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function moonchildTrackShouldBePresent() {
    $this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titreShouldContainsMoonchild() {
    $this->assertXPathContentContains('//ol//li', 'Moonchild');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test **/
  public function liForUnknownShouldBeFileNameUnknownMp3() {
    $this->assertXPathContentContains('//ol//li', 'Unknown');
    $this->assertXPathContentContains('//ol//li', '[mp3]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  public function liShouldContainsFilenameNameTheProphecy() {
    $this->assertXPathContentContains('//ol//li', 'The prophecy');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsLinkToXSPFPlayList() {
    $this->assertXPath('//a[contains(@href,"/bib-numerique/album-xspf-playlist/id/4.xspf")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsLinkToRSSPodcast() {
    $this->assertXPath('//a[contains(@href,"/bib-numerique/album-rss-feed/id/4.xml")]');
  }
}


class RechercheControllerAlbumAudioRecordViewRessourceInTelephoneModeTest extends RechercheControllerAlbumAudioRecordTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setup() {
    parent::setup();
    Class_Profil::getCurrentProfil()->beTelephone();
    $this->dispatch('/opac/recherche/viewnotice/id/1', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageShouldContainsLinkToOpenRessourcesNumeriques() {
    $this->assertXPathContentContains('//a[contains(@href,"recherche/ressourcesnumeriques/id/1")]','Ecouter l\'album',$this->_response->getBody());
  }
}



class RechercheControllerAlbumAudioRecordAsTelephoneViewRessourcesNumeriquesTest extends RechercheControllerAlbumAudioRecordTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_Profil::getCurrentProfil()->beTelephone();
    $this->dispatch('/recherche/ressourcesnumeriques/id/1', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function moonchildPlayerShouldBePresent() {
    $this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titreShouldContainsMoonchild() {
    $this->assertXPathContentContains('//ol//li', 'Moonchild');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test **/
  public function liShouldContainsFileNameUnknown() {
    $this->assertXPathContentContains('//ol//li', 'Unknown');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  public function liShouldContainsFilenameNameTheProphecy() {
    $this->assertXPathContentContains('//ol//li', 'The prophecy');
  }




class RechercheControllerAlbumAudioRecordNotVisibleTest extends RechercheControllerAlbumAudioRecordTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noNoticeShouldBeCreated() {
    $album = Class_Album::find(4);
    $album->setVisible(false);
    $album->index();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->assertEmpty(Class_Notice::findAll());
  }