86 lines
2.9 KiB
PHP
86 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Apoloz\VideoExtractor\Tests\Unit;
|
|
|
|
use Apoloz\VideoExtractor\Exceptions\PlatformNotSupportedException;
|
|
use Apoloz\VideoExtractor\Platform\Platform;
|
|
use Apoloz\VideoExtractor\Platform\PlatformDetector;
|
|
use Apoloz\VideoExtractor\Tests\TestCase;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
class PlatformDetectorTest extends TestCase
|
|
{
|
|
private PlatformDetector $detector;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->detector = new PlatformDetector();
|
|
}
|
|
|
|
#[DataProvider('vkUrls')]
|
|
public function test_detects_vk(string $url): void
|
|
{
|
|
self::assertSame(Platform::VK, $this->detector->detect($url));
|
|
}
|
|
|
|
#[DataProvider('rutubeUrls')]
|
|
public function test_detects_rutube(string $url): void
|
|
{
|
|
self::assertSame(Platform::RUTUBE, $this->detector->detect($url));
|
|
}
|
|
|
|
#[DataProvider('okUrls')]
|
|
public function test_detects_ok(string $url): void
|
|
{
|
|
self::assertSame(Platform::OK, $this->detector->detect($url));
|
|
}
|
|
|
|
public function test_throws_for_unsupported_host(): void
|
|
{
|
|
$this->expectException(PlatformNotSupportedException::class);
|
|
$this->detector->detect('https://youtube.com/watch?v=abc');
|
|
}
|
|
|
|
public function test_normalises_scheme_less_urls(): void
|
|
{
|
|
self::assertSame(Platform::VK, $this->detector->detect('vkvideo.ru/video-1_2'));
|
|
}
|
|
|
|
public static function vkUrls(): array
|
|
{
|
|
return [
|
|
'vkvideo.ru' => ['https://vkvideo.ru/video-18403220_456239696'],
|
|
'vk.com' => ['https://vk.com/video-18403220_456239696'],
|
|
'm.vk.com' => ['https://m.vk.com/video205387401_165548505'],
|
|
'new.vk.com' => ['http://new.vk.com/video205387401_165548505'],
|
|
'vksport.vkvideo.ru' => ['https://vksport.vkvideo.ru/video-124096712_456240773'],
|
|
'vk.ru' => ['https://vk.ru/video-220754053_456242564'],
|
|
'daxab.com' => ['https://www.daxab.com/embed/abc'],
|
|
];
|
|
}
|
|
|
|
public static function rutubeUrls(): array
|
|
{
|
|
return [
|
|
'rutube.ru video' => ['https://rutube.ru/video/373ba417757981facf06c55ea5c46cb4/'],
|
|
'rutube.ru live' => ['https://rutube.ru/live/video/c58f502c7bb34a8fcdd976b221fca292/'],
|
|
'rutube.ru embed' => ['https://rutube.ru/play/embed/03a9cb54bac3376af4c5cb0f18444e01'],
|
|
];
|
|
}
|
|
|
|
public static function okUrls(): array
|
|
{
|
|
return [
|
|
'ok.ru video' => ['https://ok.ru/video/15019292494547'],
|
|
'ok.ru videoembed' => ['https://ok.ru/videoembed/2932705602075'],
|
|
'ok.ru live' => ['https://ok.ru/live/484531969818'],
|
|
'm.ok.ru' => ['https://m.ok.ru/video/2361249957145'],
|
|
'www.ok.ru' => ['https://www.ok.ru/video/20648036891'],
|
|
'odnoklassniki.ru' => ['https://odnoklassniki.ru/video/20079905452'],
|
|
];
|
|
}
|
|
}
|