diff --git a/tests/Service/Embed/EmbedServiceTest.php b/tests/Service/Embed/EmbedServiceTest.php new file mode 100644 index 0000000..35eb107 --- /dev/null +++ b/tests/Service/Embed/EmbedServiceTest.php @@ -0,0 +1,70 @@ +embedService = static::getContainer()->get(EmbedService::class); + } + + /** + * @dataProvider provideUrls + */ + public function testGetsEmbedData(string $url) + { + $data = $this->embedService->getData($url); + + $this->assertInstanceOf(EmbedData::class, $data); + $this->assertNotEmpty($data->videoUrl); + $this->assertStringStartsWith('http', $data->videoUrl); + $this->assertNotEmpty($data->thumbnailUrl); + $this->assertStringStartsWith('http', $data->thumbnailUrl); + } + + public function provideUrls(): array + { + return [ + ['vimeo.com/814460460'], + ['www.vimeo.com/943036493'], + ['https://vimeo.com/1006675057?share=copy#t=0'], + ['https://vimeo.com/1034003653'], + ['https://vimeo.com/1047182474/5a2a1cb70b?share=copy'], + ['youtube.com/watch?v=D14QGWH2CfY'], + ['www.youtube.com/watch?si=hbrQ4ZazrdwccLTk&v=pdfGwxa5Kwc&feature=youtu.be'], + ['https://www.youtube.com/watch?v=dQw4w9WgXcQ'], + ['https://www.youtube.com/watch?v=oyYOBXDYGmY&ab_channel=Fes%21Cultura'], + ['youtu.be/CLSXLA7jUsQ'], + ['https://youtu.be/_crFO_jZ95o'], + ['https://youtu.be/_URpSvDyod4?feature=shared'], + ]; + } + + /** + * @dataProvider provideNotUrls + */ + public function testThrowsExceptionOnUnrecognized(string $string) + { + $this->expectException(\Exception::class); + + $this->embedService->getData($string); + } + + public function provideNotUrls() + { + return [ + ['not a url'], + ['media'], + [''], + ]; + } +}