1
|
|
|
<?php namespace GoetasWebservices\XML\XSDReader\Tests; |
2
|
|
|
|
3
|
|
|
use GoetasWebservices\XML\XSDReader\Utils\UrlUtils; |
4
|
|
|
|
5
|
|
|
class UrlUtilsTest extends BaseTest |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
public function testHttpWithout() |
9
|
|
|
{ |
10
|
|
|
$this->assertEquals('http://example.com/', UrlUtils::resolveRelativeUrl('http://example.com/', '')); |
11
|
|
|
$this->assertEquals('http://example.com', UrlUtils::resolveRelativeUrl('http://example.com', '')); |
12
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com/test', '')); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
View Code Duplication |
public function testHttpPaths() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com/', '/test')); |
18
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com', '/test')); |
19
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com//', '/test')); |
20
|
|
|
$this->assertEquals('http://example.com/test/', UrlUtils::resolveRelativeUrl('http://example.com', '/test/')); |
21
|
|
|
$this->assertEquals('http://example.com/test/test', UrlUtils::resolveRelativeUrl('http://example.com/', '/test/test')); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
View Code Duplication |
public function testHttpPathsParent() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com/parent/', '/test')); |
27
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com/parent', '/test')); |
28
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com//parent', '/test')); |
29
|
|
|
$this->assertEquals('http://example.com/test/', UrlUtils::resolveRelativeUrl('http://example.com/parent', '/test/')); |
30
|
|
|
$this->assertEquals('http://example.com/test/test', UrlUtils::resolveRelativeUrl('http://example.com/parent/', '/test/test')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testHttpPathsParentRelative() |
34
|
|
|
{ |
35
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com/parent/', '../test')); |
36
|
|
|
$this->assertEquals('http://example.com/test/', UrlUtils::resolveRelativeUrl('http://example.com/parent/', '../test/')); |
37
|
|
|
$this->assertEquals('http://example.com/test', UrlUtils::resolveRelativeUrl('http://example.com//parent/', '../test')); |
38
|
|
|
$this->assertEquals('http://example.com/test/test', UrlUtils::resolveRelativeUrl('http://example.com/parent/', '../test/test')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
View Code Duplication |
public function testHttpAnchors() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$this->assertEquals('http://example.com/#test', UrlUtils::resolveRelativeUrl('http://example.com/', '#test')); |
45
|
|
|
$this->assertEquals('http://example.com/test#test', UrlUtils::resolveRelativeUrl('http://example.com/', 'test#test')); |
46
|
|
|
$this->assertEquals('http://example.com/test#test', UrlUtils::resolveRelativeUrl('http://example.com', 'test#test')); |
47
|
|
|
$this->assertEquals('http://example.com/test/test#test', UrlUtils::resolveRelativeUrl('http://example.com/', 'test/test#test')); |
48
|
|
|
$this->assertEquals('http://example.com/test/test#test', UrlUtils::resolveRelativeUrl('http://example.com', 'test/test#test')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
View Code Duplication |
public function testHttpQS() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$this->assertEquals('http://example.com/?test=1', UrlUtils::resolveRelativeUrl('http://example.com/', '?test=1')); |
55
|
|
|
$this->assertEquals('http://example.com/test?test=1', UrlUtils::resolveRelativeUrl('http://example.com/', 'test?test=1')); |
56
|
|
|
$this->assertEquals('http://example.com/test?test=1', UrlUtils::resolveRelativeUrl('http://example.com', 'test?test=1')); |
57
|
|
|
$this->assertEquals('http://example.com/test/test?test=1', UrlUtils::resolveRelativeUrl('http://example.com/', 'test/test?test=1')); |
58
|
|
|
$this->assertEquals('http://example.com/test/test?test=1', UrlUtils::resolveRelativeUrl('http://example.com', 'test/test?test=1')); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testFilePaths() |
63
|
|
|
{ |
64
|
|
|
$this->assertEquals('file:///test', UrlUtils::resolveRelativeUrl('file:///', '/test')); |
65
|
|
|
$this->assertEquals('file:///test', UrlUtils::resolveRelativeUrl('file:///', 'test')); |
66
|
|
|
/* Assert that any filenames will be stripped from base */ |
67
|
|
|
$this->assertEquals('file:///bar.xsd', UrlUtils::resolveRelativeUrl('file:///foo.xsd', 'bar.xsd')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testRegularPaths() |
72
|
|
|
{ |
73
|
|
|
$this->assertEquals('/test', UrlUtils::resolveRelativeUrl('/', '/test')); |
74
|
|
|
$this->assertEquals('/test', UrlUtils::resolveRelativeUrl('/', 'test')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testRegularPathsParent() |
79
|
|
|
{ |
80
|
|
|
$this->assertEquals('/testing', UrlUtils::resolveRelativeUrl('/test/child', '../testing')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.