|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yiisoft\Validator\Tests\Rule; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Yiisoft\Validator\Rule\Required; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @group validators |
|
10
|
|
|
*/ |
|
11
|
|
|
class RequiredTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testValidateWithDefaults() |
|
14
|
|
|
{ |
|
15
|
|
|
$val = new Required(); |
|
16
|
|
|
$this->assertFalse($val->validate(null)->isValid()); |
|
17
|
|
|
$this->assertFalse($val->validate([])->isValid()); |
|
18
|
|
|
$this->assertTrue($val->validate('not empty')->isValid()); |
|
19
|
|
|
$this->assertTrue($val->validate(['with', 'elements'])->isValid()); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
// public function testValidateAttribute() |
|
23
|
|
|
// { |
|
24
|
|
|
// // empty req-value |
|
25
|
|
|
// $val = new Required(); |
|
26
|
|
|
// $m = FakedValidationModel::createWithAttributes(['attr_val' => null]); |
|
27
|
|
|
// $val->validateAttribute($m, 'attr_val'); |
|
28
|
|
|
// $this->assertTrue($m->hasErrors('attr_val')); |
|
29
|
|
|
// $this->assertNotFalse(stripos(current($m->getErrors('attr_val')), 'blank')); |
|
30
|
|
|
// $val = new Required(['requiredValue' => 55]); |
|
31
|
|
|
// $m = FakedValidationModel::createWithAttributes(['attr_val' => 56]); |
|
32
|
|
|
// $val->validateAttribute($m, 'attr_val'); |
|
33
|
|
|
// $this->assertTrue($m->hasErrors('attr_val')); |
|
34
|
|
|
// $this->assertNotFalse(stripos(current($m->getErrors('attr_val')), 'must be')); |
|
35
|
|
|
// $val = new Required(['requiredValue' => 55]); |
|
36
|
|
|
// $m = FakedValidationModel::createWithAttributes(['attr_val' => 55]); |
|
37
|
|
|
// $val->validateAttribute($m, 'attr_val'); |
|
38
|
|
|
// $this->assertFalse($m->hasErrors('attr_val')); |
|
39
|
|
|
// } |
|
40
|
|
|
} |
|
41
|
|
|
|