-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathMaxTest.php
More file actions
52 lines (42 loc) · 1.72 KB
/
MaxTest.php
File metadata and controls
52 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Rakit\Validation\Tests\Rules;
use Rakit\Validation\Rules\Max;
use PHPUnit\Framework\TestCase;
class MaxTest extends TestCase
{
public function setUp()
{
$this->rule = new Max;
}
public function testValids()
{
$this->assertTrue($this->rule->fillParameters([200])->check(123));
$this->assertTrue($this->rule->fillParameters([6])->check('foobar'));
$this->assertTrue($this->rule->fillParameters([3])->check([1,2,3]));
$this->assertTrue($this->rule->fillParameters([3])->check('мин'));
$this->assertTrue($this->rule->fillParameters([4])->check('كلمة'));
$this->assertTrue($this->rule->fillParameters([3])->check('ワード'));
$this->assertTrue($this->rule->fillParameters([1])->check('字'));
}
public function testInvalids()
{
$this->assertFalse($this->rule->fillParameters([5])->check('foobar'));
$this->assertFalse($this->rule->fillParameters([2])->check([1,2,3]));
$this->assertFalse($this->rule->fillParameters([100])->check(123));
}
public function testUploadedFileValue()
{
$twoMega = 1024 * 1024 * 2;
$sampleFile = [
'name' => pathinfo(__FILE__, PATHINFO_BASENAME),
'type' => 'text/plain',
'size' => $twoMega,
'tmp_name' => __FILE__,
'error' => 0
];
$this->assertTrue($this->rule->fillParameters([$twoMega])->check($sampleFile));
$this->assertTrue($this->rule->fillParameters(['2M'])->check($sampleFile));
$this->assertFalse($this->rule->fillParameters([$twoMega - 1])->check($sampleFile));
$this->assertFalse($this->rule->fillParameters(['1.9M'])->check($sampleFile));
}
}