|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace unit; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use seosazi\PathConverter\ConvertToAbsolutePath; |
|
7
|
|
|
use seosazi\PathConverter\RemovePathWithPointPointSlash; |
|
8
|
|
|
|
|
9
|
|
|
class RemovePathWithPointPointSlashTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
private $removePathWithPointPointSlash; |
|
12
|
|
|
|
|
13
|
|
|
public function setUp(): void |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
|
16
|
|
|
$this->removePathWithPointPointSlash = new RemovePathWithPointPointSlash( |
|
17
|
|
|
new ConvertToAbsolutePath('https://www.jquery-az.com/html/demo.php'), |
|
18
|
|
|
'../strawberries.jpg' |
|
19
|
|
|
); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider dataForCompute |
|
24
|
|
|
* @param $pagePath |
|
25
|
|
|
* @param $baseTag |
|
26
|
|
|
* @param $path |
|
27
|
|
|
* @param $result |
|
28
|
|
|
* @throws \Exception |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testCompute($pagePath, $baseTag, $path, $result) |
|
31
|
|
|
{ |
|
32
|
|
|
$address = new ConvertToAbsolutePath($pagePath); |
|
33
|
|
|
if (isset($baseTag)) { |
|
34
|
|
|
$address->setBaseTag($baseTag); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$removeAdditional = new RemovePathWithPointPointSlash($address, $path); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertSame($removeAdditional->compute(), $result); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function dataForCompute() |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
'once ../' => [ |
|
46
|
|
|
'https://www.jquery-az.com/html/demo.php?ex=151.0_4', |
|
47
|
|
|
null, |
|
48
|
|
|
'../strawberries.jpg', |
|
49
|
|
|
'https://www.jquery-az.com/strawberries.jpg' |
|
50
|
|
|
], |
|
51
|
|
|
'without ../' => [ |
|
52
|
|
|
'https://www.jquery-az.com/html/demo.php?ex=151.0_5', |
|
53
|
|
|
null, |
|
54
|
|
|
'strawberries.jpg', |
|
55
|
|
|
'https://www.jquery-az.com/html/strawberries.jpg' |
|
56
|
|
|
], |
|
57
|
|
|
'twice ../../' => [ |
|
58
|
|
|
'https://www.jquery-az.com/html/test/demo.php?ex=151.0_5', |
|
59
|
|
|
null, |
|
60
|
|
|
'../../banana.jpg', |
|
61
|
|
|
'https://www.jquery-az.com/banana.jpg' |
|
62
|
|
|
], |
|
63
|
|
|
'twice ../../ with base tag' => [ |
|
64
|
|
|
'https://www.jquery-az.com/html/test/demo.php?ex=151.0_5', |
|
65
|
|
|
'https://www.jquery-az.com/html/test/demo.php', |
|
66
|
|
|
'../../banana.jpg', |
|
67
|
|
|
'https://www.jquery-az.com/banana.jpg' |
|
68
|
|
|
] |
|
69
|
|
|
|
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGetPath() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->removePathWithPointPointSlash->setPath('../strawberries.jpg'); |
|
76
|
|
|
$this->assertEquals($this->removePathWithPointPointSlash->getPath(), '../strawberries.jpg'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testGetScheme() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->removePathWithPointPointSlash->setScheme('https'); |
|
82
|
|
|
$this->assertEquals($this->removePathWithPointPointSlash->getScheme(), 'https'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testGetDomain() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->removePathWithPointPointSlash->setDomain('www.jquery-az.com'); |
|
88
|
|
|
$this->assertEquals($this->removePathWithPointPointSlash->getDomain(), 'www.jquery-az.com'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testGetStarterPath() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->removePathWithPointPointSlash->setStarterPath('https://www.jquery-az.com/'); |
|
94
|
|
|
$this->assertEquals($this->removePathWithPointPointSlash->getStarterPath(), 'https://www.jquery-az.com/'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|