-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathUrlTest.php
More file actions
53 lines (45 loc) · 2.56 KB
/
UrlTest.php
File metadata and controls
53 lines (45 loc) · 2.56 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
53
<?php
namespace Rakit\Validation\Tests\Rules;
use Rakit\Validation\Rules\Url;
use PHPUnit\Framework\TestCase;
class UrlTest extends TestCase
{
public function setUp()
{
$this->rule = new Url;
}
public function testValids()
{
// Without specific schemes
$this->assertTrue($this->rule->check('ftp://foobar.com'));
$this->assertTrue($this->rule->check('any://foobar.com'));
$this->assertTrue($this->rule->check('http://foobar.com'));
$this->assertTrue($this->rule->check('https://foobar.com'));
$this->assertTrue($this->rule->check('https://foobar.com/path?a=123&b=blah'));
// Using specific schemes
$this->assertTrue($this->rule->fillParameters(['ftp'])->check('ftp://foobar.com'));
$this->assertTrue($this->rule->fillParameters(['any'])->check('any://foobar.com'));
$this->assertTrue($this->rule->fillParameters(['http'])->check('http://foobar.com'));
$this->assertTrue($this->rule->fillParameters(['https'])->check('https://foobar.com'));
$this->assertTrue($this->rule->fillParameters(['http', 'https'])->check('https://foobar.com'));
$this->assertTrue($this->rule->fillParameters(['foo', 'bar'])->check('bar://foobar.com'));
$this->assertTrue($this->rule->fillParameters(['mailto'])->check('mailto:johndoe@gmail.com'));
$this->assertTrue($this->rule->fillParameters(['jdbc'])->check('jdbc:mysql://localhost/dbname'));
// Using forScheme
$this->assertTrue($this->rule->forScheme('ftp')->check('ftp://foobar.com'));
$this->assertTrue($this->rule->forScheme('http')->check('http://foobar.com'));
$this->assertTrue($this->rule->forScheme('https')->check('https://foobar.com'));
$this->assertTrue($this->rule->forScheme(['http', 'https'])->check('https://foobar.com'));
$this->assertTrue($this->rule->forScheme('mailto')->check('mailto:johndoe@gmail.com'));
$this->assertTrue($this->rule->forScheme('jdbc')->check('jdbc:mysql://localhost/dbname'));
}
public function testInvalids()
{
$this->assertFalse($this->rule->check('foo:'));
$this->assertFalse($this->rule->check('mailto:johndoe@gmail.com'));
$this->assertFalse($this->rule->forScheme('mailto')->check('http://www.foobar.com'));
$this->assertFalse($this->rule->forScheme('ftp')->check('http://www.foobar.com'));
$this->assertFalse($this->rule->forScheme('jdbc')->check('http://www.foobar.com'));
$this->assertFalse($this->rule->forScheme(['http', 'https'])->check('any://www.foobar.com'));
}
}