Newer
Older
* Copyright (c) 2022, 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
require_once 'ArteVodFixtures.php';
abstract class ArteVodHarverstingTestCase extends ModelTestCase {
protected $_web_client,
$_service;
$this->fixture('Class_CosmoVar',
['id' => 'types_docs',
'liste' => "1:cd\r\n200:non identifié\r\n201:livres\r\n202:bd\r\nArteVod:Arte VOD"]);
Class_AdminVar::set('ArteVod_LOGIN', 'user');
Class_AdminVar::set('ArteVod_SSO_KEY', 'pass');
$codif_type_doc = $this->fixture('Class_CodifTypeDoc',
['id' => 'ArteVod',
'famille_id' => Class_CodifTypeDoc::INCONNU,
'bibliotheques' => '1;8',
'annexes' => '10;12',
'sections' => '18;19']);
$this->fixture('Class_TypeDoc', ['id' => '11',
'codif_type_doc' => $codif_type_doc,
'label'=> 'Type doc']);
ArteVod_Service::setDefaultHttpClient($this->_web_client);
$command = $this->mock()->whenCalled('execTimedScript')->answers('');
Class_WebService_BibNumerique_RessourceNumerique::setCommand($command);
$config = ArteVod_Config::getInstance();
$config->setTimeSource(new TimeSourceForTest('2023-02-06 10:00:00'));
$this->_service = new ArteVod_Service($config);
ArteVod_Service::setDefaultHttpClient(null);
class ArteVodHarverstingFourFilmsInTwoPagesTest extends ArteVodHarverstingTestCase {
foreach(['1' => ArteVodFixtures::firstPage(),
'2' => ArteVodFixtures::secondPage(),
'3' => ArteVodFixtures::emptyPage()]
$this->_web_client
->whenCalled('open_url')
->with('https://mednumv3-backapi.lab.arte.tv/api/v1/films?page_nb=' . $page . '&q_country=FR')
$this->_web_client
->whenCalled('setConfig')->with(['timeout' => 10])->answers($this->_web_client)
->beStrict();

Patrick Barroca
committed
// should delete nothing after harvest
$this->onLoaderOfModel('Class_Album')
->whenCalled('deleteBy')
->answers(true);
$this->_service->harvest();

Patrick Barroca
committed
$this->edouard = Class_Album::findFirstBy(['order' => 'id']);
$this->squadra = Class_Album::findFirstBy(['titre'=> 'Squadra Criminale']);
public function shouldHaveCreatedFourAlbums() {
$this->assertEquals(4, count(Class_Album::findAll()));
/** @test */
public function firstAlbumTitleShouldBeEdouardPoteDroite() {
$this->assertEquals('Edouard, mon pote de droite',
$this->edouard->getTitre());
}
public function firstAlbumExternalUriShouldEdouardPoteDroite() {
$this->assertEquals('https://vod.mediatheque-numerique.com/films/edouard-mon-pote-de-droite',
$this->edouard->getExternalUri());
}
/** @test */
public function descriptionShouldContainsCopaindeLycee() {
$this->assertContains('Edouard est un copain de lycée et a 45 ans',
$this->edouard->getDescription());
public function yearShouldBe2017() {
$this->assertEquals('2017', $this->edouard->getAnnee());
}
/** @test */
public function firstAuthorShouldBeTheDirector() {
$this->assertEquals('Cibien Laurent', $this->edouard->getAuthors()[0]->getName());
$this->assertEquals('300', $this->edouard->getAuthors()[0]->getResponsibility());
public function firstActorShouldBePhilippe() {
$this->assertEquals('Philippe Edouard', $this->edouard->getAuthors()[1]->getName());
$this->assertEquals('005', $this->edouard->getAuthors()[1]->getResponsibility());
}
/** @test */
public function shouldHavePosterUrl() {
$this->assertEquals('https://vod.mediatheque-numerique.com/media/59/3e/593e9af9b7428.jpeg',
$this->edouard->getPoster());
}
/** @test */
public function fourthAlbumshouldHaveTrailerUrl() {
$this->assertEquals('https://media.universcine.com/cd/b5/cdb57adc-2a49-11e7-b234-bdefb096dc40.mp4',
array_first($this->squadra->getTrailers())->getUrl());
}
/** @test */
public function firstAlbumZone215ShouldBe82Min() {
$this->assertEquals('82 mn', $this->edouard->getDuration());

efalcy
committed
/** @test */
public function vignetteShouldHaveBeenUploaded() {
$this->assertTrue(Class_WebService_BibNumerique_RessourceNumerique::getCommand()
->methodHasBeenCalled('execTimedScript'));
public function edouardActorsShouldContainsCibienLaurent() {
$this->assertContains('Philippe Edouard', $this->edouard->getAuthorsNames());
}
/** @test */
public function edouardTagsShouldContainsPolitique() {
$expected = 'Politique';
$this->assertEquals($expected, $this->edouard->getTags());

efalcy
committed
/** @test */
public function firstAlbumMatiereShouldContainsDocumentaireAndPolitique() {
$this->assertEquals('1;2', $this->edouard->getMatiere());
$this->assertEquals('Documentaire', Class_CodifMatiere::find(1)->getLibelle());
$this->assertEquals('Politique', Class_CodifMatiere::find(2)->getLibelle());
/** @test */
public function bibliothequeShouldBeImportedInByeByeBlondie() {
$this->assertEquals('1;8', $this->edouard->getBibliotheques());

efalcy
committed
/** @test */
public function annexesShouldBeImportedInByeByeBlondie() {
$this->assertEquals('10;12', $this->edouard->getAnnexes());
/** @test */
public function sectionsShouldBeImportedInByeByeBlondie() {
$this->assertEquals('18;19', $this->edouard->getSections());
public function addingAlreadyExistingAuthorShouldNotCrashAddAuthor() {
$this->assertNotEquals(null, $this->edouard->addAuthor('Cibien, Laurent', '005'));
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
class ArteVodHarverstingNewApiUpdateTest extends ArteVodHarverstingTestCase {
protected $_heroines;
public function setUp() {
parent::setUp();
$this->fixture(Class_CodifMatiere::class,
['id'=>1,
'libelle' =>'My added subject',
'code_apha' =>'ADDED_SUBJECT'] );
$this->_album = $this->fixture(Class_Album::class,
['id' => 20,
'type_doc_id' => 'ArteVod',
'titre' => 'Héros',
'id_origine' => '7040',
'matiere' => '1',
'url_origine' =>'https://mednumv3-backapi.lab.arte.tv/api/v1/',
'fichier' =>'596525_b88c86285df723b8e5c0f819b132f39f.jpeg',
'external_uri' => 'https://vod.mediatheque-numerique.com/films/heroines']);
foreach(['1' => ArteVodFixtures::newapiPage(),
'2' => ArteVodFixtures::emptyPage()]
as $page => $answer) {
$this->_web_client
->whenCalled('open_url')
->with('https://mednumv3-backapi.lab.arte.tv/api/v1/films?page_nb=' . $page . '&q_country=FR')
->answers($answer);
}
$this->_web_client
->whenCalled('setConfig')->with(['timeout' => 10])->answers($this->_web_client)
->beStrict();
// should delete nothing after harvest
$this->onLoaderOfModel('Class_Album')
->whenCalled('deleteBy')
->answers(true);
Class_AdminVar::set('ArteVod_BATCH_UPDATE_NOTICE','1');
$this->_service->harvest();
$this->_heroines = Class_Album::find(20);
}
/** @test */
public function shouldHaveUpdatedOneAlbum() {
$this->assertEquals(1, count(Class_Album::findAll()));
}
/** @test */
public function albumTitleShouldBeHeroines() {
$this->assertEquals('Héroïnes',
$this->_heroines->getTitre());
}
/** @test */
public function yearShouldBeProductionYear() {
$this->assertEquals('2016',
$this->_heroines->getAnnee());
}
/** @test */
public function matieresShouldBeHeroines() {
$this->assertEquals('1;2;3',
$this->_heroines->getMatiere());
}
/** @test */
public function externalUriShouldBeSet() {
$this->assertEquals('https://vod.mediatheque-numerique.com/films/heroines',
$this->_heroines->getExternalUri());
}
/**
* @test
*/
public function updateShoulBeDeactivated(){
$this->assertEquals('0', Class_AdminVar::get( 'ArteVod_BATCH_UPDATE_NOTICE'));
}
/** @test */
public function posterShouldBeOnMediasArte() {
$this->assertEquals('https://mediasarte.mednum.lab.arte.tv/mednum/preprod/medias/thumbs/59/3e/593e6450d4e4e.jpeg',
$this->_heroines->getPoster());
}
}
class ArteVodHarvestingWithoutPasswordTest extends ArteVodHarverstingTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('ArteVod_KEY', '');
$this->_web_client
->whenCalled('open_url')
->with('https://mednumv3-backapi.lab.arte.tv/api/v1/films?page_nb=1&q_country=FR')
->answers(ArteVodFixtures::emptyPage());
$this->_web_client
->whenCalled('setConfig')->with(['timeout' => 10])->answers($this->_web_client)
->beStrict();
(ArteVod_Service::getInstance())->harvest();
}
/** @test */
public function shouldHaveHarvestedWithoutAuth() {
$this->assertTrue($this->_web_client->methodHasBeenCalled('open_url'));
}
}
class ArteVodHarvestingWithoutCountryTest extends ArteVodHarverstingTestCase {
public function setUp() {
parent::setUp();
Class_AdminVar::set('ArteVod_KEY', '');
Class_AdminVar::set('ArteVod_COUNTRY', ArteVod_Config::COUNTRY_ALL);
$this->_web_client
->whenCalled('open_url')
->with('https://mednumv3-backapi.lab.arte.tv/api/v1/films?page_nb=1')
->answers(ArteVodFixtures::emptyPage());
$this->_web_client
->whenCalled('setConfig')->with(['timeout' => 10])->answers($this->_web_client)
->beStrict();
(ArteVod_Service::getInstance())->harvest();
}
/** @test */
public function shouldHaveHarvestedWithoutCountry() {
$this->assertTrue($this->_web_client->methodHasBeenCalled('open_url'));
}
}
class ArteVodHarverstingEnablingTest extends ArteVodHarverstingTestCase {
/** @test */
public function withAllShouldBeEnabled() {
Class_AdminVar::set('ArteVod_LOGIN', 'user');
Class_AdminVar::set('ArteVod_SSO_KEY', 'key');
$this->assertTrue((ArteVod_Config::getInstance())->isEnabled());
}
/** @test */
public function withoutLoginShouldNotBeEnabled() {
Class_AdminVar::set('ArteVod_LOGIN', '');
Class_AdminVar::set('ArteVod_SSO_KEY', 'key');
$this->assertFalse((ArteVod_Config::getInstance())->isEnabled());
}
/** @test */
public function withoutHarvestKeyShouldBeEnabled() {
Class_AdminVar::set('ArteVod_LOGIN', 'user');
Class_AdminVar::set('ArteVod_SSO_KEY', 'key');
Class_AdminVar::set('ArteVod_KEY', '');
$this->assertTrue((ArteVod_Config::getInstance())->isEnabled());
}
/** @test */
public function withoutSSOKeyShouldNotBeEnabled() {
Class_AdminVar::set('ArteVod_LOGIN', 'user');
Class_AdminVar::set('ArteVod_SSO_KEY', '');
$this->assertFalse((ArteVod_Config::getInstance())->isEnabled());
}
class ArteVodWebClientTest extends ModelTestCase {
/** @test */
public function webClientShouldBeWaitingSimpleWebClient() {
$this->assertTrue(is_a(ArteVod_Service::getWebClient(),
Class_WebService_WaitingSimpleWebClient::class));
}
}
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
class ArteVodHarverstingNullContentPageTest extends ArteVodHarverstingTestCase {
public function setUp() {
parent::setUp();
foreach(['1' => ArteVodFixtures::nullContentPage(),
'2' => ArteVodFixtures::brokenJsonPage(),
'3' => ArteVodFixtures::emptyPage()]
as $page => $answer) {
$this->_web_client
->whenCalled('open_url')
->with('https://mednumv3-backapi.lab.arte.tv/api/v1/films?page_nb=' . $page . '&q_country=FR')
->answers($answer);
}
$this->_web_client
->whenCalled('setConfig')->with(['timeout' => 10])->answers($this->_web_client)
->beStrict();
$this->_service->harvest();
}
/** @test */
public function shouldHaveDeletedAllAlbum() {
$this->assertEquals(0, count(Class_Album::findAll()));
}
}