schneespur/vendor/league/uri-interfaces/EncoderTest.php
Michael 2c63440ed8 Revert: move code back to project root from schneespur/ subdirectory
- Reverts the schneespur/ subdirectory restructure (b8e426b)
- Restores package.json and vite.config.js (needed for npm build, were
  removed in an earlier cleanup before the restructure)
- Updates public/build/ assets with current Vite output (new content hashes)
2026-05-17 18:24:26 +00:00

170 lines
4.8 KiB
PHP

<?php
/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Uri;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Stringable;
final class EncoderTest extends TestCase
{
#[Test]
#[DataProvider('provideEncodedPath')]
public function it_can_tell_whether_the_path_is_encoded_or_not(Stringable|string|null $encoded, bool $expected): void
{
self::assertSame($expected, Encoder::isPathEncoded($encoded));
}
public static function provideEncodedPath(): iterable
{
yield 'the path is null' => [
'encoded' => null,
'expected' => true,
];
yield 'the path is empty' => [
'encoded' => '',
'expected' => true,
];
yield 'the path contains only valid encoded characters' => [
'encoded' => 'toto%2f%23le$20heros',
'expected' => true,
];
yield 'the path contains invalid encoded characters' => [
'encoded' => 'toto%2%23le$20heros',
'expected' => false,
];
}
#[Test]
#[DataProvider('provideEncodedQuery')]
public function it_can_tell_whether_the_query_is_encoded_or_not(Stringable|string|null $encoded, bool $expected): void
{
self::assertSame($expected, Encoder::isQueryEncoded($encoded));
}
public static function provideEncodedQuery(): iterable
{
yield 'the query is null' => [
'encoded' => null,
'expected' => true,
];
yield 'the query is empty' => [
'encoded' => '',
'expected' => true,
];
yield 'the query contains only valid encoded characters' => [
'encoded' => 'toto%2f%23le%20heros=?++',
'expected' => true,
];
yield 'the query contains invalid encoded characters' => [
'encoded' => 'toto%2%23le%20heros#',
'expected' => false,
];
}
#[Test]
#[DataProvider('provideEncodedFragment')]
public function it_can_tell_whether_the_fragment_is_encoded_or_not(Stringable|string|null $encoded, bool $expected): void
{
self::assertSame($expected, Encoder::isFragmentEncoded($encoded));
}
public static function provideEncodedFragment(): iterable
{
yield 'the fragment is null' => [
'encoded' => null,
'expected' => true,
];
yield 'the fragment is empty' => [
'encoded' => '',
'expected' => true,
];
yield 'the fragment contains only valid encoded characters' => [
'encoded' => 'toto%2f%23le%20heros=?++',
'expected' => true,
];
yield 'the query contains invalid encoded characters' => [
'encoded' => 'toto%2%23le%20herosé',
'expected' => false,
];
}
#[Test]
#[DataProvider('provideEncodedUser')]
public function it_can_tell_whether_the_user_is_encoded_or_not(Stringable|string|null $encoded, bool $expected): void
{
self::assertSame($expected, Encoder::isUserEncoded($encoded));
}
public static function provideEncodedUser(): iterable
{
yield 'the user is null' => [
'encoded' => null,
'expected' => true,
];
yield 'the user is empty' => [
'encoded' => '',
'expected' => true,
];
yield 'the user contains only valid encoded characters' => [
'encoded' => 'toto%2f%23le%20heros',
'expected' => true,
];
yield 'the query contains invalid encoded characters' => [
'encoded' => 'toto%2%23le%20heros?@',
'expected' => false,
];
}
#[Test]
#[DataProvider('provideEncodedUser')]
public function it_can_tell_whether_the_password_is_encoded_or_not(Stringable|string|null $encoded, bool $expected): void
{
self::assertSame($expected, Encoder::isPasswordEncoded($encoded));
}
public static function provideEncodedPassword(): iterable
{
yield 'the password is null' => [
'encoded' => null,
'expected' => true,
];
yield 'the password is empty' => [
'encoded' => '',
'expected' => true,
];
yield 'the password contains only valid encoded characters' => [
'encoded' => 'toto%2f%23le%20heros',
'expected' => true,
];
yield 'the password contains invalid encoded characters' => [
'encoded' => 'toto%2%23le%20heros?@',
'expected' => false,
];
}
}