Skip to content
Snippets Groups Projects
BibNumeriqueControllerTest.php 33.2 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
Laurent's avatar
Laurent committed
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
llaffont's avatar
llaffont committed
 */

class BibNumeriqueControllerViewAlbumActionTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutAlbumShouldRedirect() {
    $this->dispatch('/opac/bib-numerique/view-album');
    $this->assertRedirect();
  }


  /** @test */
  public function withNonExistisngAlbumShouldRedirect() {
    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Album')
      ->whenCalled('find')
      ->answers(null);

    $this->dispatch('/opac/bib-numerique/view-album/id/999');
    $this->assertRedirect();
  }
llaffont's avatar
llaffont committed
}


abstract class AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_album;

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

    $this->_album = $this->fixture('Class_Album',
                                   ['id' => 999,
                                    'titre' => 'Premier volume',
                                    'description' => "On ne peut que reconnaitre le talent de l'artiste !",
                                    'thumbnail_width' => 200,
                                    'thumbnail_left_page_crop_right' => 10,
                                    'thumbnail_right_page_crop_top' => 5,
                                    'op_hauteur_boite' =>  500,
                                    'id_origine' => 'DC23',
                                    'pdf' => 'volume1.pdf',
                                    'notice' => $this->fixture('Class_Notice', ['id' => 123])]);

    $this->_album
      ->beDiaporama()
      ->setCategorie($this->fixture('Class_AlbumCategorie',
                                    ['id' => 2,
                                     'libelle' => 'Les enluminures',
                                     'parent_categorie' => $this->fixture('Class_AlbumCategorie',
                                                                          ['id' => 3,
                                                                           'libelle' => 'La bible de souvigny'])]))
      ->save();

    $im = new Imagick();
    $im->newPseudoImage(50, 10, "gradient:red-black");
    $im->setImageFormat('jpg');

    $this->_album->setRessources(
      [$this->fixture('Class_AlbumRessource', ['id' => 1,
                                       'fichier' => '1.jpg',
                                       'image' => $im,
                                       'folio' => '1R3',
                                       'album' => $this->_album]),

       $this->fixture('Class_AlbumRessource', ['id' => 2,
                                               'fichier' => '2.jpg',
                                               'album' => $this->_album,
                                               'titre' => 'Procedure de numerisation',
                                               'link_to' => 'http://wikipedia.org/numerisation',
                                               'description' => 'Comment numériser avec joie'])])
      ->save();
  }
llaffont's avatar
llaffont committed
class BibNumeriqueControllerAlbumPremierVolumeTestToJSON extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/bib-numerique/album/id/999.json', true);
    $this->json = json_decode($this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function actionShouldBeJSON() {
    $this->assertAction('album');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function downloadUrlShouldBeBibNumeriquePdf999() {
    $this->assertEquals('/bib-numerique/download_album/id/999.pdf', $this->json->album->download_url);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function albumIdShouldBe999() {
    $this->assertEquals(999, $this->json->album->id);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function albumWidthShouldBe200() {
    $this->assertEquals(200, $this->json->album->width);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function albumHeightShouldBe40() {
    $this->assertEquals(40, $this->json->album->height);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function albumTitleShouldBePremierVolume() {
    $this->assertEquals('Premier volume', $this->json->album->titre);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function albumDescriptionShouldBeOnNePeutQueReconnatre() {
    $this->assertEquals("On ne peut que reconnaitre le talent de l'artiste !",
                        $this->json->album->description);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceIdShouldBeOne() {
    $this->assertEquals(1, $this->json->album->ressources[0]->id);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceFolioNoShouldBeOneRThree() {
    $this->assertEquals('1R3', $this->json->album->ressources[0]->foliono);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceThumbnailShouldPassResizeParamsOfRightPageCropTopFive() {
    $this->assertContains('/bib-numerique/thumbnail/width/200/crop_top/5/crop_right/0/crop_bottom/0/crop_left/0/id/1',
                          $this->json->album->ressources[0]->thumbnail);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceNavigatorThumbnailShouldPassResizeParamsOfRightPageCropTopFiveWidth50() {
    $this->assertContains(BASE_URL . '/userfiles/album/999/thumbs/media/1.jpg',
                          $this->json->album->ressources[0]->navigator_thumbnail);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceNavigatorDownloadShouldBeUrlToDownloadRessource() {
    $this->assertContains('/bib-numerique/download-resource/id/1',
                          $this->json->album->ressources[0]->download);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceOriginalShouldBeOneDotJpg() {
    $this->assertContains('userfiles/album/999/big/media/1.jpg',
                          $this->json->album->ressources[0]->original);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function secondRessourceTitreShouldBeProcedureDeNumerisation() {
    $this->assertEquals('Procedure de numerisation', $this->json->album->ressources[1]->titre);
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function secondRessourcesLinkToShouldBeWikipedia() {
    $this->assertEquals('http://wikipedia.org/numerisation', $this->json->album->ressources[1]->link_to);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function secondRessourceDescriptionShouldBeCommentNumeriser() {
    $this->assertEquals('Comment numériser avec joie', $this->json->album->ressources[1]->description);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function secondRessourceThumbnailShouldPassResizeParamsOfLeftPageCropRightTen() {
    $this->assertContains('/bib-numerique/thumbnail/width/200/crop_top/0/crop_right/10/crop_bottom/0/crop_left/0/id/2',
                          $this->json->album->ressources[1]->thumbnail);
  }

class BibNumeriqueControllerAlbumPremierVolumeDisplayMonopageTestToJSON extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    Class_Album::find(999)
      ->setThumbnailCropTop(12)
      ->setThumbnailCropLeft(5)
      ->beMonopage();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/opac/bib-numerique/album/id/999.json', true);
    $this->json = json_decode($this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function playerShouldBeBookMonoWidget() {
    $this->assertEquals('BookMonoWidget', $this->json->album->player);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function firstRessourceThumbnailShouldPassResizeParams() {
    $this->assertContains('/bib-numerique/thumbnail/width/200/crop_top/12/crop_right/0/crop_bottom/0/crop_left/5/id/1',
                          $this->json->album->ressources[0]->thumbnail);
  }
class BibNumeriqueControllerAlbumPremierVolumeWithPDFTestToJSON extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    Class_AlbumRessource::find(2)->setFichier('2.pdf');
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/opac/bib-numerique/album/id/999.json', true);
    $this->json = json_decode($this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function secondRessourceNavigatorThumbnailShouldBeEarthLogoDotJpg() {
        $this->assertContains(BASE_URL . '/public/opac/images/earth-logo.jpg',
                              $this->json->album->ressources[1]->navigator_thumbnail);
  }
llaffont's avatar
llaffont committed
class BibNumeriqueControllerPermalinkTest extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function permalinkNoticeWithIdOrigineShouldRdirectToRechercheNotice() {
    $this->dispatch('/opac/bib-numerique/notice/ido/DC23');
    $this->assertRedirectTo('/opac/recherche/viewnotice/id/123');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function permalinkNoticeWithIdShouldRdirectToRechercheNotice() {
    $this->dispatch('/opac/bib-numerique/notice/id/999');
    $this->assertRedirectTo('/opac/recherche/viewnotice/id/123');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function permalinkNoticeFolio1R3ShouldRedirectToRechercheNoticeHashPageTwo() {
    $this->dispatch('/opac/bib-numerique/notice/id/999/folio/1R3');
    $this->assertRedirectTo('/opac/recherche/viewnotice/id/123#/page/2');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function permalinkNoticeWithUnknowAlbumIdShouldRedirectToIndex() {
    $this->dispatch('/opac/bib-numerique/notice/id/xyz');
    $this->assertRedirectTo('/opac/index');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function permalinkAlbumWithoutNoticeShouldRedirectToIndex() {
    $this->_album->setNotice(null);
    $this->dispatch('/opac/bib-numerique/notice/id/999');
    $this->assertRedirectTo('/opac/index');
  }
llaffont's avatar
llaffont committed
}




class BibNumeriqueControllerAlbumPremierVolumeWithoutPDFTestToJSON extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_Album::getLoader()->find(999)->setPdf(null);
    $this->dispatch('/opac/bib-numerique/album/id/999.json');
    $this->json = json_decode($this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function downloadUrlShouldBeNotSet() {
    $this->assertEmpty($this->json->album->download_url);
  }
class BibNumeriqueControllerDownloadRessourcesTest extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function thumbnailIdOneShouldRenderThumbnail() {
    $this->dispatch('/opac/bib-numerique/thumbnail/id/1');
    $this->assertContains(substr(Class_AlbumRessource::getLoader()->find(1)->getImage()->getImageBlob(), 0, 100),
                          $this->_response->getBody());
  }
llaffont's avatar
llaffont committed
}



class BibNumeriqueControllerBookletTest extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/bib-numerique/booklet/id/999');
  }


  /** @test */
  function actionShouldBeBooklet() {
    $this->assertAction('booklet');
  }

  /** @test */
  function amberShouldBeLoaded() {
    $this->assertXPath('//script[contains(@src, "amber.js")]');
  }

  /** @test */
  function AFIAmberPackageShouldBeLoaded() {
    $this->assertXPathContentContains('//script', 'AFI.js', $this->_response->getBody());
  }

  /** @test */
  function AFITestsAmberPackageShouldBeLoaded() {
    $this->assertXPathContentContains('//script', 'AFI-Tests.js');
  }


  /** @test */
  function pageShouldContainsCodeToOpenBooklet() {
    $this->assertXPathContentContains('//script',
                                      "smalltalk.BibNumAlbum._load_in_scriptsRoot_('/bib-numerique/album/id/999.json', '#booklet_999', '" . BASE_URL . "/amber/afi/souvigny/')",
                                      $this->_response->getBody());
  }
llaffont's avatar
llaffont committed
class BibNumeriqueControllerViewAlbumActionPremierVolumeTest extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    Class_Profil::getCurrentProfil()->setSkin('original');
    $this->dispatch('/opac/bib-numerique/view-album/id/999', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titreShouldBePremierVolume() {
    $this->assertXPathContentContains('//div[@class="titre"]//h1', 'Premier volume');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function categorieAnchorShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="breadcrum"]//a', 'Les enluminures');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function ancestorCategorieAnchorShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="breadcrum"]//a', 'La bible de souvigny');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function cycleJSShouldBePresentInScriptfirstRessourceShouldBePresent() {
    $this->assertXPathContentContains('//script', "\$('div.slideshow-999 .medias').cycle");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function hauteurBoiteShouldBeSetTo500() {
    $this->assertXPathContentContains('//script', '"height":"500"');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function viewerScriptShouldBePresent() {
    $this->assertXPath('//script[contains(@src, "prettyPhoto.js")]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pageBibNumShouldBeHTML5Compliant() {
    $this->assertHTML5();
  }
llaffont's avatar
llaffont committed
class BibNumeriqueControllerViewCategorieActionTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function withoutAlbumShouldRedirect() {
    $this->dispatch('/opac/bib-numerique/view-categorie');
    $this->assertRedirect();
  }


  /** @test */
  public function withNonExistisngAlbumShouldRedirect() {
    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AlbumCategorie')
      ->whenCalled('find')
      ->answers(null);

    $this->dispatch('/opac/bib-numerique/view-categorie/id/999');
    $this->assertRedirect();
  }
llaffont's avatar
llaffont committed
}



class BibNumeriqueControllerViewCategorieActionLesEnluminuresTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
    Class_AlbumCategorie::getLoader()
      ->newInstanceWithId(2)
      ->setLibelle('Les enluminures')
      ->setParentCategorie(Class_AlbumCategorie::getLoader()
                           ->newInstanceWithId(3)
                           ->setLibelle('La bible de souvigny'))
      ->setAlbums(array(Class_Album::getLoader()
                        ->newInstanceWithId(999)
                        ->setTitre('Premier volume')
                        ->setFichier('999.jpg')
                        ->setDescription('On ne peut que reconnaitre le talent de l\'artiste !')));
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/opac/bib-numerique/view-categorie/id/2');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function parentAnchorShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="breadcrum"]//a', 'La bible de souvigny');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function albumPremierVolumeShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="bibnumerique-albums"]//a', 'Premier volume');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function thumbnailOfPremierVolumeShouldBePresent() {
    $this->assertXPath('//div[@class="bibnumerique-albums"]//img[contains(@src, "album/999/thumb_999.jpg")]', $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noSubcategoryShouldBePresent() {
    $this->assertNotXPath('//div[@class="bibnumerique-categories"]');
  }
llaffont's avatar
llaffont committed
}




abstract class BibNumeriqueControllerBibleDeSouvignyTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    Class_AlbumCategorie::getLoader()
      ->newInstanceWithId(3)
      ->setLibelle('La bible de souvigny')
      ->setAlbums(array())
      ->setSousCategories(array(Class_AlbumCategorie::getLoader()
                                ->newInstanceWithId(2)
                                ->setLibelle('Les enluminures')));
  }
llaffont's avatar
llaffont committed
class BibNumeriqueControllerViewCategorieActionLaBibleDeSouvignyTest extends BibNumeriqueControllerBibleDeSouvignyTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/opac/bib-numerique/view-categorie/id/3');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noParentAnchorShouldBePresent() {
    $this->assertNotXPath('//div[@class="breadcrum"]//a');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function noAlbumShouldBePresent() {
    $this->assertNotXPath('//div[@class="albums"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function subcategoryAnchorShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="bibnumerique-categories"]//a', 'Les enluminures');
  }

abstract class BibNumeriqueControllerAlbumMultiMediasTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_xpath;

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

    $this->_xpath = new Storm_Test_XPathXML();

    $album = Class_Album::newInstanceWithId(999)
      ->beDiaporama()
      ->setTitre('Plein de medias')
      ->setSousTitre('Pour tester')
      ->setAuteur('Suzanne Collins')
      ->setEditeur('Gallimard')
      ->setAnnee(2001)
      ->setNoticeId(500)
      ->setIdOrigine("A888")
      ->setCote('50')
      ->setDateMaj('2012-02-17 10:00:00')
      ->setDescription('<p>pour passer la soirée</p>')
      ->setNotes(['305$a' => 'XXe siècle',
                  '200$b' => 'Parchemin',
                  '316$a' => 'Reliure restaurée en 1980 par la BN.'])
      ->setIdLang('lat')
      ->setDroits('CC-BY-SA')


      ->setRessources([Class_AlbumRessource::newInstanceWithId(2)
                       ->setFichier('mimi_jolie.mp3')
                       ->setTitre('Emilie jolie')
                       ->setOrdre(1)
                       ->setPoster('mimi_jolie.png'),

                       Class_AlbumRessource::newInstanceWithId(4)
                       ->setFichier('dark_night.mp4')
                       ->setTitre('Batman Dark Knight')
                       ->setPoster('batman.jpg')
                       ->setOrdre(2)
                       ->setDescription('Une nouvelle aventure du justicier noir'),

                       Class_AlbumRessource::newInstanceWithId(5)
                       ->setUrl('http://progressive.totaleclips.com.edgesuite.net/107/e107950_227.mp4')
                       ->setTitre('Hunger Games')
                       ->setOrdre(3)
                       ->setPoster('hunger.jpg'),

                       Class_AlbumRessource::newInstanceWithId(6)
                       ->setFichier('Monsieur l\'escargot.mp3')
                       ->setTitre('Monsieur l\'escargot')
                       ->setOrdre(4)
                       ->setPoster('l\'escargot.jpg'),

                      Class_AlbumRessource::newInstanceWithId(7)
                       ->setUrl('https://vimeo.com/43395780')
                       ->setTitre('Vimeo')
                       ->setOrdre(5)
                       ->setPoster('vimeo.jpg'),

                      Class_AlbumRessource::newInstanceWithId(8)
                       ->setFichier('moonchild.mpeg')
                       ->setTitre('Iron Maiden: "Moonchild" live')
                       ->setOrdre(6)
                       ->setPoster('moonchild.jpg'),

                       Class_AlbumRessource::newInstanceWithId(9)
                       ->setFichier('the_prophecy.mp3')
                       ->setOrdre(7)]);

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AlbumCategorie')
    ->whenCalled('findAllBy')
    ->answers([])

    ->whenCalled('findAllBy')
    ->with(['parent_id' => 0])
    ->answers([ Class_AlbumCategorie::newInstanceWithId('33')
                ->setAlbums([$album])
                ->setLibelle('Comics')]);

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Album')
      ->whenCalled('findAll')
      ->answers([$album])
      ->whenCalled('findAllBy')
      ->with(['cat_id'=>'33'])
      ->answers([$album]);


  }
class BibNumeriqueControllerAlbumMultiMediasXSPFTest extends BibNumeriqueControllerAlbumMultiMediasTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->_xpath->registerNameSpace('xspf', 'http://xspf.org/ns/0/');
    $this->dispatch('/opac/bib-numerique/album-xspf-playlist/id/999.xspf', true);
  }
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function headerShouldContainsContentTypeXspf() {
    $this->assertHeaderContains('Content-Type', 'application/xspf+xml');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function headerShouldContainsContentDispositionAttachment() {
    $this->assertHeaderContains('Content-Disposition', 'attachment');
  }
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function xmlVersionShouldOneDotZero() {
    $this->_xpath->assertXmlVersion($this->_response->getBody(), "1.0");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function xmlEncodingShouldBeUtf8() {
    $this->_xpath->assertXmlEncoding($this->_response->getBody(), "UTF-8");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstTrackTitleShouldBeMimiJolie() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:title',
                                              'Emilie jolie');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstTrackImageShouldBeMimiJolieDotPng() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:image',
                                              'http://localhost' . BASE_URL . '/userfiles/album/999/thumbs/media/mimi_jolie.png');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstTrackLocationShouldBeMimiJolieDotMp3() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:location',
                                              'http://localhost' . BASE_URL . '/bib-numerique/play-ressource/id/6.mp3');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function secondTrackTitleShouldBeBatmanDarkKnight() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:title',
                                              'Batman Dark Knight');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function thirdTrackLocationShouldBeTotaleClipsDotCom() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:location',
                                              'http://localhost' . BASE_URL . '/bib-numerique/play-ressource/id/5.mp4');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function fourthTrackLocationShouldBeUrlEncoded() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:location',
                                              'play-ressource/id/2.mp3');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function seventhTrackTitleShouldBeTheProphecy() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:title',
                                              'The prophecy');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function vimeoTrackLocationShouldBeOriginalUrl() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//xspf:playlist/xspf:trackList/xspf:track/xspf:location',
                                              'https://vimeo.com/43395780');
  }
}




class BibNumeriqueControllerAlbumMultiMediasRSSTest extends BibNumeriqueControllerAlbumMultiMediasTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
Patrick Barroca's avatar
Patrick Barroca committed
    $this->_xpath->registerNameSpace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
Patrick Barroca's avatar
Patrick Barroca committed
    $this->dispatch('/opac/bib-numerique/album-rss-feed/id/999.xml', true);
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function xmlVersionShouldOneDotZero() {
    $this->_xpath->assertXmlVersion($this->_response->getBody(), "1.0");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function xmlEncodingShouldBeUtf8() {
    $this->_xpath->assertXmlEncoding($this->_response->getBody(), "utf-8");
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function headerShouldContainsContentTypeRss() {
    $this->assertHeaderContains('Content-Type', 'application/rss+xml');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function titleShouldBePleinDeMedias() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/title',
                                              'Plein de medias');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function itunesImageShouldBeNoticeThumbnail() {
    $this->_xpath->assertXPath($this->_response->getBody(),
                               '//channel/itunes:image[@href="http://localhost'.BASE_URL.'/bib-numerique/notice-thumbnail/ido/A888"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function descriptionShouldBePourPasserLaSoiree() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/description',
                                              '<p>pour passer la soirée</p>');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function itunesSummaryShouldBePourPasserLaSoiree() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/itunes:summary',
                                              '<p>pour passer la soirée</p>');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function linkShouldBeBibNumeriqueNoticeIdoA888() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/link',
                                              'http://localhost'.BASE_URL.'/bib-numerique/notice/ido/A888');
  }
Laurent's avatar
Laurent committed

Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function pubDateShouldBeFri17Feb2012() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/pubDate',
                                              'Fri, 17 Feb 2012');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstItemTitleShouldBeEmilieJolie() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[1]/title',
                                              'Emilie jolie');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstItemLinkShouldBeMediaMimiJolieMp3() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[1]/link',
                                              'http://localhost'.BASE_URL.'/bib-numerique/play-ressource/id/2.mp3');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstItemEnclosureShouldBeMediaMimiJolieMp3() {
    $this->_xpath->assertXPath($this->_response->getBody(),
                               '//channel/item[1]/enclosure[@url="http://localhost'.BASE_URL.'/bib-numerique/play-ressource/id/2.mp3"][@type="audio/mpeg"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstItemITunesOrderShouldBeOne() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[1]/itunes:order',
                                              '1');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstItemGUIDShouldBeMediaMimiJolieMp3() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[1]/guid',
                                              'http://localhost'.BASE_URL.'/bib-numerique/play-ressource/id/2.mp3');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function firstItemItunesImageShouldBeMimiJolie() {
    $this->_xpath->assertXPath($this->_response->getBody(),
                               '//channel/item[1]/itunes:image[@href="http://localhost'.BASE_URL.'/userfiles/album/999/thumbs/media/mimi_jolie.png"]');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function secondItemTitleShouldBeDarkKnight() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[2]/title',
                                              'Batman Dark Knight');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function secondItemDescriptionShouldBeAventureJusticierNoir() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[2]/description',
                                              'Une nouvelle aventure du justicier noir');
  }

  /** @test */
  public function firstItemITunesOrderShouldBeTwo() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[2]/itunes:order',
                                              '2');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  public function seventhItemTitleShouldBeTheProphecy() {
    $this->_xpath->assertXPathContentContains($this->_response->getBody(),
                                              '//channel/item[7]/title',
                                              'The prophecy');
  }
class BibNumeriqueControllerPlayRessourceTest extends BibNumeriqueControllerAlbumMultiMediasTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_web_analytics_client;

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

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


  /** @test */
  public function forRessourceFiveShouldRedirectToTotaleClipsDotCom() {
    $this->dispatch('/opac/bib-numerique/play-ressource/id/5.mp3', true);
    $this->assertRedirectTo('http://progressive.totaleclips.com.edgesuite.net/107/e107950_227.mp4');
    return $this->_web_analytics_client;
  }


  /**
   * @test
   * @depends forRessourceFiveShouldRedirectToTotaleClipsDotCom
   */
  public function forRessourceFiveAnalyticsTrackerShouldHaveReceivedPlayEvent($client) {
    $this->assertEquals(['bib-numerique',
                         'lecture', '"titre: Hunger Games","album: Plein de medias","auteur: Suzanne Collins","editeur: Gallimard","publication: 2001","piste: 3","droits: CC-BY-SA","source: http://localhost'.BASE_URL.'/bib-numerique/notice/id/5.mp3/ido/A888/folio/5"',
                         5],
                        $client->getAttributesForLastCallOn('trackEvent'));
  }


  /** @test */
  public function forRessourceSixShouldRedirectMonsieurEscargot() {
    $this->dispatch('/opac/bib-numerique/play-ressource/id/6.mp3', true);
    $this->assertRedirectTo('http://localhost'.BASE_URL.'/userfiles/album/999/big/media/Monsieur%20l%27escargot.mp3');
  }


  /**
   * @test
   */
  public function forRessourceMoonchildAnalyticsTrackerShouldEscapeQuotes() {
    $this->dispatch('/opac/bib-numerique/play-ressource/id/8.mp3', true);
    $this->assertEquals(['bib-numerique',
                         'lecture',
                         '"titre: Iron Maiden: \"Moonchild\" live","album: Plein de medias","auteur: Suzanne Collins","editeur: Gallimard","publication: 2001","piste: 6","droits: CC-BY-SA","source: http://localhost'.BASE_URL.'/bib-numerique/notice/id/8.mp3/ido/A888/folio/moonchild"',
                         8],
                        $this->_web_analytics_client->getAttributesForLastCallOn('trackEvent'));
  }
class BibNumeriqueControllerFullScreenEpubTest extends BibNumeriqueControllerAlbumMultiMediasTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected
    $_path_epub_temp;

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

    $fixtures_epub_path = realpath(dirname(__FILE__)).'/../../../../fixtures/lesson.epub';
    $album_epub_path = USERFILESPATH.'/album/999/big/media/lesson.epub';
    $epub_content = file_get_contents($fixtures_epub_path);
    $this->_path_epub_temp = PATH_TEMP.'epubimport'.md5($album_epub_path).'.epub';

    $file_writer = Storm_Test_ObjectWrapper::mock()
      ->whenCalled('fileExists')
      ->with($album_epub_path)
      ->answers(true)

      ->whenCalled('getContents')
      ->with($album_epub_path)
      ->answers($epub_content)

      ->whenCalled('putContents')
      ->with($this->_path_epub_temp,
             $epub_content)
      ->willDo(
        function($path, $content) use ($epub_content) {
          return file_put_contents($this->_path_epub_temp, $epub_content);
        })

      ->beStrict();

    ZendAfi_View_Helper_MonocleReaderServerSide::setFileWriter($file_writer);
    Class_EpubReader::setFileWriter($file_writer);

    Class_Album::newInstanceWithId(999)
      ->beEPUB()
      ->setTitre('Informatique')
      ->setRessources([Class_AlbumRessource::newInstanceWithId(4)
                       ->setFichier('lesson.epub')
                       ->setTitre('Pragmatic Programmers')
                       ->setVignette('pragprog.jpg')]);

    $this->dispatch('/opac/bib-numerique/full-screen/id/4', true);
  }


  public function tearDown() {
    unlink($this->_path_epub_temp);
    ZendAfi_View_Helper_MonocleReaderServerSide::setFileWriter(null);
    Class_EpubReader::setFileWriter(null);
    parent::tearDown();
  }


  /** @test */