Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* 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).
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
abstract class RechercheControllerAlbumAudioRecordTestCase extends AbstractControllerTestCase {
$_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]);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$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 {
$this->mock_sql = $this->mock()
->whenCalled('execute')->answers('')
->whenCalled('fetchOne')->answers(null)
->whenCalled('fetchAll')->answers([ [1, ''] ]);
Zend_Registry::set('sql', $this->mock_sql);
$this->dispatch('/recherche/viewnotice/id/'.$this->_notice->getId(), true);
}
/** @test */
public function noticeShouldNotBeNull() {
$this->assertNotNull($this->_notice);
}
/** @test */
public function clefAlphaShouldBeSEVENTHSON_IRONMAIDEN() {
$this->assertEquals('SEVENTHSONOFASEVENTHSON--IRONMAIDENBRUCEDICKINSONSTEVEHARRISDAVEMURRAYNICKOMCBRAINADRIANSMITH----109',
$this->_notice->getClefAlpha());
}
/** @test */
public function noticeShouldHaveLocalUrlImageSet() {
$this->assertNotEmpty($this->_notice->getUrlImage());
}
/** @test */
public function noticeShouldHaveLocalUrlVignetteSet() {
$this->assertNotEmpty($this->_notice->getUrlVignette());
}
/**
* @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());
}
/** @test */
public function noticeShouldNotBeNouveaute() {
/** en attendant de bien gérer la nouveauté pour les albums bib num */
$this->assertFalse($this->_notice->isNouveaute());
}
/** @test */
public function titrePrincipalShouldBeSeventhSonOfASeventhSon() {
$this->assertXPathContentContains('//h1',
'Seventh Son of a Seventh Son',
$this->_response->getBody());
}
/** @test */
public function noticeFirstMorceauTitleShouldBeMoonchild() {
$this->assertEquals('Moonchild',
$this->_notice->getMorceaux()['morceaux'][1][1]['titre']);
}
/** @test */
public function noticeFirstMorceauUrlEcouteShouldBeMoonchildDotMP3() {
$this->assertContains('/bib-numerique/play-ressource/id/1.mp3',
$this->_notice->getMorceaux()['morceaux'][1][1]['url_ecoute']);
}
/** @test */
public function noticeSecondMorceauTitleShouldBeInfiniteDreams() {
$this->assertEquals('Infinite Dreams',
$this->_notice->getMorceaux()['morceaux'][1][2]['titre']);
}
/** @test */
public function noticeUnknownMorceauTitleShouldBeUnknown() {
$this->assertEquals('Unknown',
$this->_notice->getMorceaux()['morceaux'][1][3]['titre']);
}
/** @test */
public function titresFulltextShouldContainsMOONCHILD() {
$this->assertContains('MOONCHILD',
explode(' ', $this->_notice->getRawAttributes()['titres']));
}
/** @test */
public function titresFulltextShouldContainsUNKNOWN() {
$this->assertContains('UNKNOWN',
explode(' ', $this->_notice->getRawAttributes()['titres']));
}
/** @test */
public function titresFulltextShouldContainsPROPHECY() {
$this->assertContains('PROPHECY',
explode(' ', $this->_notice->getRawAttributes()['titres']));
}
/** @test */
public function titresFulltextShouldNotContains502() {
$this->assertNotContains('502',
explode(' ', $this->_notice->getRawAttributes()['titres']));
}
/** @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()));
/** @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()));
/** @test */
public function anneeShouldBeEmpty() {
$this->assertEquals('', $this->_notice->getAnnee());
}
}
class RechercheControllerAlbumAudioRecordViewMorceauxTest extends RechercheControllerAlbumAudioRecordTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/noticeajax/morceaux/id_notice/' . $this->_notice->getId(), true);
}
/** @test */
public function moonchildPlayerShouldBePresent() {
$this->assertXPath('//audio/source[contains(@src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
}
/** @test */
public function moonchildTitleShouldBePresent() {
$this->assertXPathContentContains('//div[@class="notice_info_ligne"]',
'1: Moonchild');
}
/** @test */
public function infiniteDreamsTitleShouldBePresent() {
$this->assertXPathContentContains('//div[@class="notice_info_ligne"]',
'2: Infinite Dreams');
}
class RechercheControllerAlbumAudioRecordViewDetailsTest extends RechercheControllerAlbumAudioRecordTestCase {
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
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 {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/noticeajax/resnumeriques/id_notice/'.$this->_notice->getId(), true);
}
/** @test */
public function albumPlayerShouldBePresent() {
$this->assertXPath('//audio[@preload]');
}
/** @test */
public function nextTrackLinkShouldBePresent() {
$this->assertXPath('//div[@class="audio_tracks_control"]/a[@class="next"]');
}
/** @test */
public function previousTrackLinkShouldBePresent() {
$this->assertXPath('//div[@class="audio_tracks_control"]/a[@class="previous"]');
}
/** @test */
public function moonchildTrackShouldBePresent() {
$this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
}
/** @test */
public function titreShouldContainsMoonchild() {
$this->assertXPathContentContains('//ol//li', 'Moonchild');
}
/** @test **/
public function liForUnknownShouldBeFileNameUnknownMp3() {
$this->assertXPathContentContains('//ol//li', 'Unknown');
$this->assertXPathContentContains('//ol//li', '[mp3]');
}
/** @test **/
public function liShouldContainsFilenameNameTheProphecy() {
$this->assertXPathContentContains('//ol//li', 'The prophecy');
}
/** @test */
public function pageShouldContainsLinkToXSPFPlayList() {
$this->assertXPath('//a[contains(@href,"/bib-numerique/album-xspf-playlist/id/4.xspf")]');
}
/** @test */
public function pageShouldContainsLinkToRSSPodcast() {
$this->assertXPath('//a[contains(@href,"/bib-numerique/album-rss-feed/id/4.xml")]');
}
}
class RechercheControllerAlbumAudioRecordViewRessourceInTelephoneModeTest extends RechercheControllerAlbumAudioRecordTestCase {
public function setup() {
parent::setup();
Class_Profil::getCurrentProfil()->beTelephone();
$this->dispatch('/opac/recherche/viewnotice/id/1', true);
}
/** @test */
public function pageShouldContainsLinkToOpenRessourcesNumeriques() {
$this->assertXPathContentContains('//a[contains(@href,"recherche/ressourcesnumeriques/id/1")]','Ecouter l\'album',$this->_response->getBody());
}
}
class RechercheControllerAlbumAudioRecordAsTelephoneViewRessourcesNumeriquesTest extends RechercheControllerAlbumAudioRecordTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()->beTelephone();
$this->dispatch('/recherche/ressourcesnumeriques/id/1', true);
}
/** @test */
public function moonchildPlayerShouldBePresent() {
$this->assertXPath('//ol//li//a[contains(@data-src, "/bib-numerique/play-ressource/id/1.mp3")]', $this->_response->getBody());
}
/** @test */
public function titreShouldContainsMoonchild() {
$this->assertXPathContentContains('//ol//li', 'Moonchild');
}
/** @test **/
public function liShouldContainsFileNameUnknown() {
$this->assertXPathContentContains('//ol//li', 'Unknown');
}
/** @test **/
public function liShouldContainsFilenameNameTheProphecy() {
$this->assertXPathContentContains('//ol//li', 'The prophecy');
}
class RechercheControllerAlbumAudioRecordNotVisibleTest extends RechercheControllerAlbumAudioRecordTestCase {
/** @test */
public function noNoticeShouldBeCreated() {
$album = Class_Album::find(4);
$album->setVisible(false);
$album->index();