MediaVideoTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests\Entity;
  4. use App\Entity\MediaVideo;
  5. use PHPUnit\Framework\TestCase;
  6. class MediaVideoTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider urlsForMedia
  10. */
  11. public function testByUrl(
  12. string $url,
  13. string $expectedUrl,
  14. string $expectedEmbedUrl,
  15. string $expectedType,
  16. string $expectedIdentif,
  17. bool $isPathImageExists
  18. ): void
  19. {
  20. $media = new MediaVideo();
  21. $media->setUrl($url);
  22. $this->assertEquals($expectedUrl, $media->getUrl());
  23. $this->assertEquals($expectedEmbedUrl, $media->embedUrl());
  24. $this->assertEquals($expectedType, $media->getType());
  25. $this->assertEquals($expectedIdentif, $media->getIdentif());
  26. $this->assertNull($media->getId());
  27. $this->assertEquals("<iframe src='".$expectedEmbedUrl."' allowfullscreen></iframe>", $media->video());
  28. if ($isPathImageExists) {
  29. $this->assertIsString($media->image());
  30. } else {
  31. $this->assertNull($media->image());
  32. }
  33. }
  34. /**
  35. * @dataProvider urlsForMedia
  36. */
  37. public function testFromTmdb(
  38. string $url,
  39. string $expectedUrl,
  40. string $expectedEmbedUrl,
  41. string $expectedType,
  42. string $expectedIdentif,
  43. bool $isPathImageExists
  44. ): void
  45. {
  46. $media2 = new MediaVideo();
  47. $media2->setFromTmdb($expectedType, $expectedIdentif);
  48. $this->assertEquals($expectedUrl, $media2->getUrl());
  49. $this->assertEquals($expectedEmbedUrl, $media2->embedUrl());
  50. $this->assertEquals($expectedType, $media2->getType());
  51. $this->assertEquals($expectedIdentif, $media2->getIdentif());
  52. $this->assertNull($media2->getId());
  53. $this->assertEquals("<iframe src='".$expectedEmbedUrl."' allowfullscreen></iframe>", $media2->video());
  54. if ($isPathImageExists) {
  55. $this->assertIsString($media2->image());
  56. } else {
  57. $this->assertNull($media2->image());
  58. }
  59. }
  60. public function urlsForMedia()
  61. {
  62. return [
  63. [
  64. 'https://www.youtube.com/watch?v=jZm8eSX7MTc',
  65. 'https://www.youtube.com/watch?v=jZm8eSX7MTc',
  66. 'https://www.youtube-nocookie.com/embed/jZm8eSX7MTc',
  67. 'youtube',
  68. 'jZm8eSX7MTc',
  69. true
  70. ],
  71. [
  72. 'https://www.dailymotion.com/video/x8efziw',
  73. 'https://www.dailymotion.com/video/x8efziw',
  74. 'https://www.dailymotion.com/embed/video/x8efziw',
  75. 'dailymotion',
  76. 'x8efziw',
  77. true
  78. ],
  79. [
  80. 'https://vimeo.com/48130434',
  81. 'https://vimeo.com/48130434',
  82. 'https://player.vimeo.com/video/48130434',
  83. 'vimeo',
  84. '48130434',
  85. true
  86. ],
  87. [
  88. 'https://video.fdlibre.eu/videos/watch/eb38ccf6-62ce-4b52-874c-beaacc896612',
  89. 'https://video.fdlibre.eu/videos/watch/eb38ccf6-62ce-4b52-874c-beaacc896612',
  90. 'https://video.fdlibre.eu/videos/embed/eb38ccf6-62ce-4b52-874c-beaacc896612',
  91. 'peertube',
  92. 'eb38ccf6-62ce-4b52-874c-beaacc896612',
  93. false
  94. ],
  95. [
  96. 'https://youtu.be/jZm8eSX7MTc',
  97. 'https://www.youtube.com/watch?v=jZm8eSX7MTc',
  98. 'https://www.youtube-nocookie.com/embed/jZm8eSX7MTc',
  99. 'youtube',
  100. 'jZm8eSX7MTc',
  101. true
  102. ],
  103. ];
  104. }
  105. }