80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Apoloz\VideoExtractor\Tests\Unit;
|
|
|
|
use Apoloz\VideoExtractor\Platform\Platform;
|
|
use Apoloz\VideoExtractor\Parsing\VkUrlParser;
|
|
use Apoloz\VideoExtractor\Tests\TestCase;
|
|
|
|
class VkUrlParserTest extends TestCase
|
|
{
|
|
private VkUrlParser $parser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->parser = new VkUrlParser();
|
|
}
|
|
|
|
public function test_parses_canonical_vkvideo_url(): void
|
|
{
|
|
$ref = $this->parser->parse('https://vkvideo.ru/video-18403220_456239696');
|
|
|
|
self::assertSame(Platform::VK, $ref->platform);
|
|
self::assertSame('-18403220_456239696', $ref->id);
|
|
self::assertSame('-18403220', $ref->oid);
|
|
self::assertSame('video', $ref->type);
|
|
}
|
|
|
|
public function test_parses_positive_owner_id(): void
|
|
{
|
|
$ref = $this->parser->parse('https://vkvideo.ru/video224967259_456239337');
|
|
|
|
self::assertSame('224967259_456239337', $ref->id);
|
|
self::assertSame('224967259', $ref->oid);
|
|
}
|
|
|
|
public function test_parses_clip_url(): void
|
|
{
|
|
$ref = $this->parser->parse('https://vk.com/clip-74006511_456247211');
|
|
|
|
self::assertSame('-74006511_456247211', $ref->id);
|
|
self::assertSame('clip', $ref->type);
|
|
}
|
|
|
|
public function test_parses_mobile_url(): void
|
|
{
|
|
$ref = $this->parser->parse('https://m.vk.com/video205387401_165548505');
|
|
|
|
self::assertSame('205387401_165548505', $ref->id);
|
|
self::assertSame('video', $ref->type);
|
|
}
|
|
|
|
public function test_parses_embed_url_with_hash(): void
|
|
{
|
|
$ref = $this->parser->parse('https://vk.com/video_ext.php?oid=-77521&id=162222515&hash=87b046504ccd8bfa');
|
|
|
|
self::assertSame('-77521_162222515', $ref->id);
|
|
self::assertSame('-77521', $ref->oid);
|
|
self::assertSame('87b046504ccd8bfa', $ref->hash);
|
|
self::assertSame('embed', $ref->type);
|
|
}
|
|
|
|
public function test_parses_embed_url_without_hash(): void
|
|
{
|
|
$ref = $this->parser->parse('https://vk.com/video_ext.php?oid=-18403220&id=456239696');
|
|
|
|
self::assertSame('-18403220_456239696', $ref->id);
|
|
self::assertNull($ref->hash);
|
|
}
|
|
|
|
public function test_cache_key_is_stable(): void
|
|
{
|
|
$ref = $this->parser->parse('https://vkvideo.ru/video-18403220_456239696');
|
|
|
|
self::assertSame('video:vk:-18403220_456239696:thumb', $ref->cacheKey('thumb'));
|
|
}
|
|
}
|