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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Unit\Translation\Loader;
use Piwik\Validators\UrlLike;
/**
* @group Validator
* @group UrlLike
* @group UrlLikeTest
*/
class UrlLikeTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider getValidUrls
*/
public function test_validate_successValueIsLikeUri($validUrl)
{
$this->validate($validUrl);
$this->assertTrue(true);
}
public function getValidUrls()
{
return [
array('http://piwik.org'),
array('http://www.piwik.org'),
array('https://piwik.org'),
array('https://piwik.org/dir/dir2/?oeajkgea7aega=&ge=a'),
array('ftp://www.pi-wik.org'),
array('news://www.pi-wik.org'),
array('https://www.tëteâ.org'),
array('http://汉语/漢語.cn'), //chinese
array('rtp://whatever.com'),
array('testhttp://test.com'),
array('cylon://3.hmn'),
array('://something.com'),
// valid network-path reference RFC3986
array('//piwik.org'),
array('//piwik/hello?world=test&test'),
array('//piwik.org/hello?world=test&test'),
];
}
/**
* @dataProvider getFailedUrls
*/
public function test_validate_failValueIsNotUrlLike($url)
{
$this->expectException(\Piwik\Validators\Exception::class);
$this->expectExceptionMessage('ValidatorErrorNotUrlLike');
$this->validate($url);
}
public function getFailedUrls()
{
return [
array('it doesnt look like url'),
array('/index?page=test'),
array('http:/index?page=test'),
array('http/index?page=test'),
array('test.html'),
array('/\/\/\/\/\/\\\http://test.com////'),
array('jmleslangues.php'),
array('http://'),
array(' http://'),
array('2fer://'),
];
}
private function validate($value)
{
$validator = new UrlLike();
$validator->validate($value);
}
}
|