FileUrlValidator example

#[Package('buyers-experience')] class FileFetcherTest extends TestCase
{
    final public const TEST_IMAGE = __DIR__ . '/../../../../../../src/Core/Content/Test/Media/fixtures/shopware-logo.png';

    private FileFetcher $fileFetcher;

    private bool $mediaDirCreated = false;

    protected function setUp(): void
    {
        $this->fileFetcher = new FileFetcher(new FileUrlValidator());

        $projectDir = (new TestBootstrapper())->getProjectDir();
        if (!\is_dir($projectDir . '/public/media')) {
            mkdir($projectDir . '/public/media');
            $this->mediaDirCreated = true;
        }

        \copy(self::TEST_IMAGE, $projectDir . '/public/media/shopware-logo.png');
    }

    protected function tearDown(): void
    {
/** * @internal */
class FileUrlValidatorTest extends TestCase
{
    /** * @dataProvider fileSourceProvider */
    public function testIsValid(string $source, bool $expectedResult): void
    {
        $validator = new FileUrlValidator();

        static::assertEquals($expectedResult$validator->isValid($source));
    }

    public static function fileSourceProvider(): array
    {
        return [
            'reserved IPv4' => ['https://127.0.0.1', false],
            'converted reserved IPv4' => ['https://0:0:0:0:0:FFFF:7F00:0001', false],
            'reserved IPv4 mapped to IPv6' => ['https://[0:0:0:0:0:FFFF:127.0.0.1]', false],
            'reserved IPv6' => ['https://FE80::', false],
            
Home | Imprint | This part of the site doesn't use cookies.