Browse Source

Evolution #382: Mise a jour des tests unitaire des factorys

Bastien Sevajol 12 years ago
parent
commit
45747d2eef

+ 1 - 1
src/Muzich/CoreBundle/Factory/Elements/Youtube.php View File

@@ -28,7 +28,7 @@ class Youtube extends Youtubecom
28 28
     // Données API
29 29
     if ($ref_id)
30 30
     {
31
-      
31
+      $this->proceedAPIDatas($ref_id);
32 32
     }
33 33
   }
34 34
   

+ 215 - 0
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php View File

@@ -285,4 +285,219 @@ class ElementFactoryTest extends UnitTest
285 285
     
286 286
   }
287 287
   
288
+  public function testDataApiengine()
289
+  {
290
+    $r = $this->getDoctrine();
291
+    $bux = $r->getRepository('MuzichCoreBundle:User')
292
+      ->findOneByUsername('bux')
293
+    ;
294
+    
295
+    /*
296
+     *   - youtube.com && youtu.be
297
+     */
298
+    
299
+    $this->assertEquals(array(
300
+      'data_ref_id' => 'Itfg7UpkcSs',
301
+      'data_title'  => 'DIDIER SUPER SUR FRANCE O : UN PETIT MALENTENDU ?'
302
+    ),$this->proceed_element_datas_api(
303
+      $bux, 
304
+      'http://www.youtube.com/watch?v=Itfg7UpkcSs&feature=g-vrec&context=G2e61726RVAAAAAAAAAg'
305
+    ));
306
+    
307
+    $this->assertEquals(array(
308
+      'data_ref_id' => 'Itfg7UpkcSs',
309
+      'data_title'  => 'DIDIER SUPER SUR FRANCE O : UN PETIT MALENTENDU ?'
310
+    ),$this->proceed_element_datas_api(
311
+      $bux, 
312
+      'http://www.youtube.com/watch?feature=player_detailpage&v=Itfg7UpkcSs#t=3s'
313
+    ));
314
+    
315
+    $this->assertEquals(array(
316
+      'data_ref_id' => 'Itfg7UpkcSs',
317
+      'data_title'  => 'DIDIER SUPER SUR FRANCE O : UN PETIT MALENTENDU ?'
318
+    ),$this->proceed_element_datas_api(
319
+      $bux, 
320
+      'http://youtu.be/Itfg7UpkcSs'
321
+    ));
322
+    
323
+    $this->assertEquals(array(
324
+      'data_ref_id' => 'Itfg7UpkcSs',
325
+      'data_title'  => 'DIDIER SUPER SUR FRANCE O : UN PETIT MALENTENDU ?'
326
+    ),$this->proceed_element_datas_api(
327
+      $bux, 
328
+      'http://www.youtube.com/watch?v=Itfg7UpkcSs'
329
+    ));
330
+    
331
+    
332
+    /*
333
+     *   - dailymotion.com
334
+     */
335
+    
336
+      // 'http://www.dailymotion.com/video/xafj1q_black-bomb-a-tales-from-the-old-sch_music', 
337
+    
338
+      // TODO: l'url est pas toujours la même pour le thumb :/
339
+//    $this->assertEquals(array(
340
+//      'data_ref_id' => 'xafj1q',
341
+//      'data_thumb_url'  => 'http://static2.dmcdn.net/static/video/686/025/17520686:jpeg_preview_medium.jpg?20110820212502'
342
+//    ),$this->proceed_element_datas_api(
343
+//      $bux, 
344
+//      'http://www.dailymotion.com/video/xafj1q_black-bomb-a-tales-from-the-old-sch_music'
345
+//    ));
346
+    
347
+    /*
348
+     * - soundcloud.com
349
+     */
350
+    
351
+    // 'http://soundcloud.com/matas/sets/library-project'
352
+    
353
+    $this->assertEquals(array(
354
+      'data_ref_id' => 3770,
355
+      'data_title' => 'Library Project',
356
+      'data_thumb_url' => 'http://i1.sndcdn.com/artworks-000000514203-fsvbcj-large.jpg?04ad178',
357
+      'data_type' => 'playlist',
358
+      'data_download' => null,
359
+      'data_download_url' => 'http://soundcloud.com/matas/sets/library-project/download',
360
+      'data_artist' => 'matas',
361
+    ),$this->proceed_element_datas_api(
362
+      $bux, 
363
+      'http://soundcloud.com/matas/sets/library-project'
364
+    ));
365
+    
366
+    // 'http://soundcloud.com/matas/above-hyperion-redux'
367
+    
368
+    $this->assertEquals(array(
369
+      'data_ref_id' => 3154252,
370
+      'data_title' => 'Above Hyperion (redux)',
371
+      'data_thumb_url' => 'http://i1.sndcdn.com/artworks-000001536693-gb1n5v-large.jpg?04ad178',
372
+      'data_type' => 'track',
373
+      'data_download' => false,
374
+      'data_download_url' => 'http://soundcloud.com/matas/above-hyperion-redux/download',
375
+      'data_artist' => 'matas',
376
+      'data_tags' => array(
377
+        0 => 'Spacestep'
378
+      )
379
+    ),$this->proceed_element_datas_api(
380
+      $bux, 
381
+      'http://soundcloud.com/matas/above-hyperion-redux'
382
+    ));
383
+    
384
+    // 'http://soundcloud.com/tracks/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D='
385
+    
386
+    $this->assertEquals(array(
387
+      
388
+    ),$this->proceed_element_datas_api(
389
+      $bux, 
390
+      'http://soundcloud.com/tracks/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D='
391
+    ));
392
+    
393
+    //'http://soundcloud.com/people/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D='
394
+    
395
+    $this->assertEquals(array(
396
+      
397
+    ),$this->proceed_element_datas_api(
398
+      $bux, 
399
+      'http://soundcloud.com/people/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D='
400
+    ));
401
+    
402
+    // 'http://soundcloud.com/groups/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D='
403
+    
404
+    $this->assertEquals(array(
405
+      
406
+    ),$this->proceed_element_datas_api(
407
+      $bux, 
408
+      'http://soundcloud.com/groups/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D='
409
+    ));
410
+     
411
+    /*
412
+     *   - jamendo.com
413
+     */
414
+    
415
+    // 'http://www.jamendo.com/fr/album/30661'
416
+    
417
+    $this->assertEquals(array(
418
+      'data_ref_id' => '30661',
419
+      'data_title' => 'ZwaNe 01',
420
+      'data_type' => 'album',
421
+      'data_thumb_url' => 'http://imgjam.com/albums/s30/30661/covers/1.100.jpg',
422
+      'data_artist' => 'Ptit lutin',
423
+      'data_tags' => array(
424
+        0 => 'Basse',
425
+        1 => 'Batterie',
426
+        2 => 'Hardtek',
427
+        3 => 'Tek',
428
+        4 => 'Hardtechno',
429
+      ),
430
+      'data_download' => true,
431
+    ),$this->proceed_element_datas_api(
432
+      $bux, 
433
+      'http://www.jamendo.com/fr/album/30661'
434
+    ));
435
+    
436
+    // 'http://www.jamendo.com/fr/track/207079'
437
+    
438
+    $this->assertEquals(array(
439
+      'data_ref_id' => '207079',
440
+      'data_title' => 'Insanity',
441
+      'data_type' => 'track',
442
+      'data_thumb_url' => 'http://imgjam.com/albums/s30/30661/covers/1.100.jpg',
443
+      'data_artist' => 'Ptit lutin',
444
+      'data_tags' => array(
445
+        0 => 'Techno',
446
+        1 => 'Hardtek'
447
+      ),
448
+      'data_download' => true,
449
+    ),$this->proceed_element_datas_api(
450
+      $bux, 
451
+      'http://www.jamendo.com/fr/track/207079'
452
+    ));
453
+    
454
+    // 'http://www.jamendo.com/fr/search/all/psytrance'
455
+    
456
+    $this->assertEquals(array(
457
+      'data_ref_id' => null,
458
+      'data_type' => null,
459
+      'data_download' => true,
460
+    ),$this->proceed_element_datas_api(
461
+      $bux, 
462
+      'http://www.jamendo.com/fr/search/all/psytrance'
463
+    ));
464
+    
465
+    // 'http://www.jamendo.com/fr/artist/DJ_BETO'
466
+    
467
+    $this->assertEquals(array(
468
+      'data_ref_id' => null,
469
+      'data_type' => null,
470
+      'data_download' => true,
471
+    ),$this->proceed_element_datas_api(
472
+      $bux, 
473
+      'http://www.jamendo.com/fr/artist/DJ_BETO'
474
+    ));
475
+    
476
+    /*/*
477
+     *   - deezer.com
478
+     */
479
+    
480
+    // 'http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398'
481
+    
482
+    $this->assertEquals(array(
483
+      'data_ref_id' => '80398',
484
+      'data_type' => 'album',
485
+      'data_thumb_url' => 'http://api.deezer.com/2.0/album/80398/image'
486
+    ),$this->proceed_element_datas_api(
487
+      $bux, 
488
+      'http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398'
489
+    ));
490
+    
491
+    // 'http://www.deezer.com/fr/music/playlist/18701350'
492
+    
493
+    $this->assertEquals(array(
494
+      'data_ref_id' => '18701350',
495
+      'data_type' => 'playlist',
496
+    ),$this->proceed_element_datas_api(
497
+      $bux, 
498
+      'http://www.deezer.com/fr/music/playlist/18701350'
499
+    ));
500
+    
501
+  }
502
+  
288 503
 }

+ 13 - 3
src/Muzich/CoreBundle/lib/UnitTest.php View File

@@ -39,9 +39,6 @@ class UnitTest extends \PHPUnit_Framework_TestCase
39 39
   
40 40
   protected function proceed_elementAndFill($user, $name, $url, $tag_ids, $final_embed)
41 41
   {
42
-    $youtube_width = '590';
43
-    $youtube_height = '300';
44
-        
45 42
     $element = new Element();
46 43
     $element->setName($name);
47 44
     $element->setTags(json_encode($tag_ids));
@@ -68,6 +65,19 @@ class UnitTest extends \PHPUnit_Framework_TestCase
68 65
     $this->assertEquals($element->getEmbed(), $final_embed);
69 66
   }
70 67
   
68
+  protected function proceed_element_datas_api($user, $url)
69
+  {
70
+    $element = new Element();
71
+    $element->setUrl($url);
72
+    
73
+    $factory = new ElementManager($element, 
74
+      $this->getDoctrine()->getEntityManager(), $this->_container);
75
+    $factory->proceedFill($user);
76
+    
77
+    return $element->getDatas();
78
+  }
79
+
80
+
71 81
   protected function getUser($username)
72 82
   {
73 83
     return $this->getDoctrine()->getRepository('MuzichCoreBundle:User')