2015-06-16 05:41:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-16 05:41:49 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-06-16 05:41:49 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-09-20 04:07:43 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2015-06-16 05:41:49 +02:00
|
|
|
use SplFileInfo;
|
|
|
|
|
|
|
|
/**
|
2018-09-20 04:07:43 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\Extension
|
2018-09-20 04:07:43 +02:00
|
|
|
*
|
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2015-06-16 05:41:49 +02:00
|
|
|
*/
|
2018-09-20 04:07:43 +02:00
|
|
|
final class ExtensionTest extends RuleTestCase
|
2015-06-16 05:41:49 +02:00
|
|
|
{
|
2018-07-23 20:35:14 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-07-23 20:35:14 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2015-06-16 05:41:49 +02:00
|
|
|
{
|
2018-09-20 04:07:43 +02:00
|
|
|
return [
|
|
|
|
'txt' => [new Extension('txt'), 'filename.txt'],
|
|
|
|
'jpg' => [new Extension('jpg'), 'filename.jpg'],
|
|
|
|
'inc' => [new Extension('inc'), 'filename.inc'],
|
|
|
|
'bz2' => [new Extension('bz2'), 'filename.foo.bar.bz2'],
|
|
|
|
'php' => [new Extension('php'), new SplFileInfo(__FILE__)],
|
2023-04-02 14:33:29 +02:00
|
|
|
'png' => [new Extension('png'), self::fixture('valid-image.png')],
|
|
|
|
'gif' => [new Extension('gif'), self::fixture('valid-image.gif')],
|
|
|
|
'file-invalid' => [new Extension('png'), self::fixture('invalid-image.png')],
|
2018-09-20 04:07:43 +02:00
|
|
|
];
|
2015-06-16 05:41:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2015-06-16 05:41:49 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2015-06-16 05:41:49 +02:00
|
|
|
{
|
2018-09-20 04:07:43 +02:00
|
|
|
return [
|
|
|
|
'jpg' => [new Extension('jpg'), 'filename.txt'],
|
|
|
|
'txt' => [new Extension('txt'), 'filename.jpg'],
|
|
|
|
'bz2' => [new Extension('bz2'), 'filename.inc.php'],
|
|
|
|
'js' => [new Extension('js'), 'filename.foo.bar.bz2'],
|
|
|
|
'php' => [new Extension('php'), [__FILE__]],
|
|
|
|
'mp3' => [new Extension('mp3'), 999],
|
|
|
|
'gif' => [new Extension('gif'), ''],
|
|
|
|
'doc' => [new Extension('doc'), null],
|
|
|
|
];
|
2015-06-16 05:41:49 +02:00
|
|
|
}
|
|
|
|
}
|