mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
fix: revert rule alpha
This commit is contained in:
parent
1ca24da3d4
commit
cdec7d0b39
@ -29,10 +29,6 @@ class FormatRules
|
||||
*/
|
||||
public function alpha($str = null): bool
|
||||
{
|
||||
if (is_array($str)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! is_string($str)) {
|
||||
$str = (string) $str;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace CodeIgniter\Validation;
|
||||
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
use Config\Services;
|
||||
use ErrorException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use stdClass;
|
||||
@ -100,12 +101,6 @@ class RulesTest extends CIUnitTestCase
|
||||
['foo' => ''],
|
||||
false,
|
||||
],
|
||||
// Invalid array input
|
||||
[
|
||||
['foo' => 'if_exist|alpha'],
|
||||
['foo' => ['bar' => '12345']],
|
||||
false,
|
||||
],
|
||||
// Input data does not exist then the other rules will be ignored
|
||||
[
|
||||
['foo' => 'if_exist|required'],
|
||||
@ -132,6 +127,19 @@ class RulesTest extends CIUnitTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testIfExistArray(): void
|
||||
{
|
||||
$this->expectException(ErrorException::class);
|
||||
$this->expectExceptionMessage('Array to string conversion');
|
||||
|
||||
$rules = ['foo' => 'if_exist|alpha'];
|
||||
// Invalid array input
|
||||
$data = ['foo' => ['bar' => '12345']];
|
||||
|
||||
$this->validation->setRules($rules);
|
||||
$this->validation->run($data);
|
||||
}
|
||||
|
||||
#[DataProvider('providePermitEmpty')]
|
||||
public function testPermitEmpty(array $rules, array $data, bool $expected): void
|
||||
{
|
||||
|
@ -244,4 +244,14 @@ final class RulesTest extends TraditionalRulesTest
|
||||
'foo bar bool match' => [['foo' => true, 'bar' => true], false],
|
||||
];
|
||||
}
|
||||
|
||||
public function testIfExistArray(): void
|
||||
{
|
||||
$rules = ['foo' => 'if_exist|alpha'];
|
||||
// Invalid array input
|
||||
$data = ['foo' => ['bar' => '12345']];
|
||||
|
||||
$this->validation->setRules($rules);
|
||||
$this->assertFalse($this->validation->run($data));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user