2021-09-01 07:21:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Util\Lexer\Bearcap;
|
2022-12-21 21:21:07 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-09-01 07:21:47 +00:00
|
|
|
|
|
|
|
class BearcapTest extends TestCase
|
|
|
|
{
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function validTest()
|
|
|
|
{
|
|
|
|
$str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&u=https://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$expected = [
|
|
|
|
'token' => 'LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2',
|
|
|
|
'url' => 'https://pixelfed.test/stories/admin/337892163734081536',
|
|
|
|
];
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function invalidTokenParameterName()
|
|
|
|
{
|
|
|
|
$str = 'bear:?token=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&u=https://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function invalidUrlParameterName()
|
|
|
|
{
|
|
|
|
$str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&url=https://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function invalidScheme()
|
|
|
|
{
|
|
|
|
$str = 'bearcap:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&url=https://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function missingToken()
|
|
|
|
{
|
|
|
|
$str = 'bear:?u=https://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function missingUrl()
|
|
|
|
{
|
|
|
|
$str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function invalidHttpUrl()
|
|
|
|
{
|
|
|
|
$str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&u=http://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
|
2022-12-21 21:21:07 +00:00
|
|
|
/** @test */
|
|
|
|
public function invalidUrlSchema()
|
|
|
|
{
|
|
|
|
$str = 'bear:?t=LpVypnEUdHhwwgXE9tTqEwrtPvmLjqYaPexqyXnVo1flSfJy5AYMCdRPiFRmqld2&u=phar://pixelfed.test/stories/admin/337892163734081536';
|
|
|
|
$actual = Bearcap::decode($str);
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
2021-09-01 07:21:47 +00:00
|
|
|
}
|