Completed
Pull Request — 5.3 (#2590)
by Jeroen
06:55
created

ValidExternalUrlValidatorTest::testInvalidUrls()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Kunstmaan\NodeBundle\Tests\unit\Validator\Constraint;
4
5
use Kunstmaan\NodeBundle\Validator\Constraint\ValidExternalUrl;
6
use Kunstmaan\NodeBundle\Validator\Constraint\ValidExternalUrlValidator;
7
use Symfony\Component\Validator\Constraints\Url;
8
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
9
10
class ValidExternalUrlValidatorTest extends ConstraintValidatorTestCase
11
{
12
    protected function createValidator()
13
    {
14
        return new ValidExternalUrlValidator();
15
    }
16
17
    /**
18
     * @dataProvider getValidUrls
19
     */
20
    public function testValidUrls($url)
21
    {
22
        $this->validator->validate($url, new ValidExternalUrl());
23
24
        $this->assertNoViolation();
25
    }
26
27
    /**
28
     * @dataProvider getInvalidUrls
29
     */
30
    public function testInvalidUrls($url)
31
    {
32
        $this->validator->validate($url, new ValidExternalUrl());
33
34
        $this->buildViolation('This value is not a valid URL.')
35
            ->setParameter('{{ value }}', '"'.$url.'"')
36
            ->setCode(Url::INVALID_URL_ERROR)
37
            ->assertRaised();
38
    }
39
40
    public function getValidUrls()
41
    {
42
        return [
43
            ['http://www.example.com'],
44
            ['https://example.com'],
45
            ['#'],
46
            ['#anchor-name'],
47
            ['#!'],
48
        ];
49
    }
50
51
    public function getInvalidUrls()
52
    {
53
        return [
54
            ['example.com'],
55
            ['www.example.com'],
56
            ['!#'],
57
            ['abc#anchor-name'],
58
        ];
59
    }
60
}
61