2015-01-06 23:14:08 +01:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-01-06 23:14:08 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2019-04-05 20:11:13 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2019-04-05 20:11:13 +02:00
|
|
|
use function setlocale;
|
2019-03-20 23:44:02 +01:00
|
|
|
use function sprintf;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2019-04-05 20:11:13 +02:00
|
|
|
use const LC_ALL;
|
2017-11-04 11:21:40 +01:00
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
|
|
|
* @group rule
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Exceptions\NoException
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\No
|
2018-11-25 17:56:04 +01:00
|
|
|
*
|
|
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2019-04-05 20:11:13 +02:00
|
|
|
final class NoTest extends RuleTestCase
|
2015-01-06 23:14:08 +01:00
|
|
|
{
|
|
|
|
/**
|
2019-04-05 20:11:13 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $locale;
|
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
2023-04-02 16:00:37 +02:00
|
|
|
* @test
|
|
|
|
*
|
|
|
|
* @dataProvider providerForValidInputWithLocale
|
2019-02-07 21:22:10 +01:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public function itShouldValidateInputAccordingToTheLocale(string $locale, string $input): void
|
2015-01-06 23:14:08 +01:00
|
|
|
{
|
2023-04-02 16:00:37 +02:00
|
|
|
setlocale(LC_ALL, $locale);
|
2019-04-05 20:11:13 +02:00
|
|
|
|
2023-04-02 16:00:37 +02:00
|
|
|
if ($locale !== setlocale(LC_ALL, '0')) {
|
|
|
|
$this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale));
|
|
|
|
}
|
|
|
|
|
|
|
|
self::assertValidInput(new No(true), $input);
|
2015-01-06 23:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-02 16:00:37 +02:00
|
|
|
* @test
|
|
|
|
*
|
|
|
|
* @dataProvider providerForInvalidInputWithLocale
|
2015-01-06 23:14:08 +01:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public function itShouldInvalidateInputAccordingToTheLocale(string $locale, string $input): void
|
2015-01-06 23:14:08 +01:00
|
|
|
{
|
2023-04-02 16:00:37 +02:00
|
|
|
setlocale(LC_ALL, $locale);
|
2015-01-06 23:14:08 +01:00
|
|
|
|
2023-04-02 16:00:37 +02:00
|
|
|
if ($locale !== setlocale(LC_ALL, '0')) {
|
|
|
|
$this->markTestSkipped(sprintf('Could not set locale information to "%s"', $locale));
|
|
|
|
}
|
|
|
|
|
|
|
|
self::assertInvalidInput(new No(true), $input);
|
2015-01-06 23:14:08 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
|
|
|
* @return string[][]
|
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInputWithLocale(): array
|
2015-01-06 23:14:08 +01:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2019-04-05 20:11:13 +02:00
|
|
|
'nl' => ['nl_NL.UTF-8', 'Nee'],
|
|
|
|
'pt' => ['pt_BR.UTF-8', 'Não'],
|
|
|
|
'ru' => ['ru_RU.UTF-8', 'нет'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2015-01-06 23:14:08 +01:00
|
|
|
}
|
2019-04-05 20:11:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[][]
|
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInputWithLocale(): array
|
2019-04-05 20:11:13 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'nl' => ['nl_NL.UTF-8', 'Ez'],
|
|
|
|
'pt' => ['pt_BR.UTF-8', 'нет'],
|
|
|
|
'ru' => ['pt_BR.UTF-8', 'Οχι'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-02 16:00:37 +02:00
|
|
|
* {@inheritDoc}
|
2019-04-05 20:11:13 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2019-04-05 20:11:13 +02:00
|
|
|
{
|
2023-04-02 16:00:37 +02:00
|
|
|
$sut = new No();
|
2019-03-20 23:44:02 +01:00
|
|
|
|
2023-04-02 16:00:37 +02:00
|
|
|
return [
|
|
|
|
[$sut, 'N'],
|
|
|
|
[$sut, 'Nay'],
|
|
|
|
[$sut, 'Nix'],
|
|
|
|
[$sut, 'No'],
|
|
|
|
[$sut, 'Nope'],
|
|
|
|
[$sut, 'Not'],
|
|
|
|
];
|
2019-04-05 20:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-02 16:00:37 +02:00
|
|
|
* {@inheritDoc}
|
2019-04-05 20:11:13 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2019-04-05 20:11:13 +02:00
|
|
|
{
|
2023-04-02 16:00:37 +02:00
|
|
|
$sut = new No();
|
2019-03-20 23:44:02 +01:00
|
|
|
|
2023-04-02 16:00:37 +02:00
|
|
|
return [
|
|
|
|
[$sut, 'Donnot'],
|
|
|
|
[$sut, 'Never'],
|
|
|
|
[$sut, 'Niet'],
|
|
|
|
[$sut, 'Noooooooo'],
|
|
|
|
[$sut, 'Não'],
|
|
|
|
];
|
2019-04-05 20:11:13 +02:00
|
|
|
}
|
2020-08-27 15:29:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->locale = (string) setlocale(LC_ALL, '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
setlocale(LC_ALL, $this->locale);
|
|
|
|
}
|
2015-01-06 23:14:08 +01:00
|
|
|
}
|