2010-10-18 06:26:02 +02: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);
|
|
|
|
|
2010-10-18 06:26:02 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
use stdClass;
|
2017-11-04 11:21:40 +01:00
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-09-24 21:48:41 +02:00
|
|
|
* @covers \Respect\Validation\Rules\AbstractFilterRule
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\Alpha
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
*
|
2023-02-13 05:59:06 +01:00
|
|
|
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
* @author Nick Lombard <github@jigsoft.co.za>
|
|
|
|
* @author Pascal Borreli <pascal@borreli.com>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
final class AlphaTest extends RuleTestCase
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
'alphabetic' => [new Alpha(), 'alganet'],
|
|
|
|
'alphabetic with one exception' => [new Alpha('.'), 'google.com'],
|
|
|
|
'alphabetic with multiple exceptions' => [new Alpha('0-9'), '0alg-anet9'],
|
|
|
|
'non-alphabetic with only exceptions' => [new Alpha('!@#$%^&*(){}'), '!@#$%^&*(){}'],
|
2018-09-24 21:48:41 +02:00
|
|
|
'multiple characters to ignore' => [new Alpha('-', ' '), 'a-b c'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
|
|
|
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2010-10-18 06:26:02 +02:00
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
Do not accept whitespace by default in "Alpha" rule
The intent of the "Alpha" rule is to validate alphabetic values.
However, it also considers any whitespace character (by default). That
causes some confusion, and unless you check its code or tests, you would
never expect that behavior.
Because of that confusion, I decided to make "Alpha" to not consider
whitespace characters as valid, and since in the constructor of this
rule it's possible to add extra characters to the validation it makes
sense to let the user decide whether they want whitespaces, tabs, new
lines, etc. or not.
This rule, as the same as "Alnum" previously, extends
"AbstractCtypeRule" pretty much to only make it easier to consider any
whitespaces as valid, therefore I saw no reason to keep extending it.
Now "Alpha" extends the "AbstractFilterRule" which is the parent of
"AbstractCtypeRule".
I also took the opportunity to apply our contribution guidelines to
"Alpha" since we want to apply that to all the rules.
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-03 23:18:10 +02:00
|
|
|
'empty string' => [new Alpha(), ''],
|
|
|
|
'symbols' => [new Alpha(), '@#$'],
|
|
|
|
'underscore' => [new Alpha(), '_'],
|
|
|
|
'non ASCII chars' => [new Alpha(), 'dgç'],
|
|
|
|
'alphanumeric' => [new Alpha(), '122al'],
|
|
|
|
'digits as string' => [new Alpha(), '122'],
|
|
|
|
'integers' => [new Alpha(), 11123],
|
|
|
|
'zero' => [new Alpha(), 0],
|
|
|
|
'null' => [new Alpha(), null],
|
|
|
|
'object' => [new Alpha(), new stdClass()],
|
|
|
|
'array' => [new Alpha(), []],
|
|
|
|
'newline' => [new Alpha(), "\nabc"],
|
|
|
|
'tab' => [new Alpha(), "\tdef"],
|
|
|
|
'alphabetic with spaces' => [new Alpha(), 'alganet alganet'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-10-18 06:26:02 +02:00
|
|
|
}
|
2011-02-10 21:49:48 +01:00
|
|
|
}
|