|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace unit; |
|
4
|
|
|
|
|
5
|
|
|
use http\Client; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use seosazi\PathConverter\ConvertToAbsolutePath; |
|
8
|
|
|
|
|
9
|
|
|
class ConvertToAbsolutePathTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var ConvertToAbsolutePath */ |
|
12
|
|
|
private $address; |
|
13
|
|
|
|
|
14
|
|
|
public function setUp(): void |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
|
17
|
|
|
$this->setAddress( |
|
18
|
|
|
new ConvertToAbsolutePath() |
|
19
|
|
|
); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider dataForTestUpToLastDir |
|
24
|
|
|
* @param $path |
|
25
|
|
|
* @param $result |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testUpToLastDir($path, $result) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertSame($this->getAddress()->upToLastDir($path), $result); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function dataForTestUpToLastDir() |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
'page path with file name' => [ |
|
36
|
|
|
'http://example.com/some/fake/path/page.html', |
|
37
|
|
|
'http://example.com/some/fake/path/' |
|
38
|
|
|
], |
|
39
|
|
|
'page path with any file name type 1' => [ |
|
40
|
|
|
'http://example.com/some/fake/', |
|
41
|
|
|
'http://example.com/some/fake/' |
|
42
|
|
|
], |
|
43
|
|
|
'page path with any file name type 2' => [ |
|
44
|
|
|
'http://example.com/some/fake', |
|
45
|
|
|
'http://example.com/some/' |
|
46
|
|
|
], |
|
47
|
|
|
'home page' => [ |
|
48
|
|
|
'http://example.com', |
|
49
|
|
|
'http://example.com/' |
|
50
|
|
|
] |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @dataProvider dataForOnlySitePath |
|
56
|
|
|
* @param $path |
|
57
|
|
|
* @param $result |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testOnlySitePath($path, $result) |
|
60
|
|
|
{ |
|
61
|
|
|
$address = new ConvertToAbsolutePath('http://example.com/some/fake/path/'); |
|
|
|
|
|
|
62
|
|
|
$this->assertSame($this->getAddress()->onlySitePath($path), $result); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function dataForOnlySitePath() |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
'page path with file name' => [ |
|
69
|
|
|
'http://example.com/some/fake/path/page.html', |
|
70
|
|
|
'http://example.com' |
|
71
|
|
|
], |
|
72
|
|
|
'page path with any file name type 1' => [ |
|
73
|
|
|
'http://example.com/some/fake/', |
|
74
|
|
|
'http://example.com' |
|
75
|
|
|
], |
|
76
|
|
|
'page path with any file name type 2' => [ |
|
77
|
|
|
'http://example.com/some/fake', |
|
78
|
|
|
'http://example.com' |
|
79
|
|
|
], |
|
80
|
|
|
'home page 1' => [ |
|
81
|
|
|
'http://example.com', |
|
82
|
|
|
'http://example.com' |
|
83
|
|
|
], |
|
84
|
|
|
'home page 2' => [ |
|
85
|
|
|
'example.com/some/fake', |
|
86
|
|
|
'' |
|
87
|
|
|
] |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @dataProvider dataForConvert |
|
94
|
|
|
* @param $pagePath |
|
95
|
|
|
* @param $baseTag |
|
96
|
|
|
* @param $path |
|
97
|
|
|
* @param $result |
|
98
|
|
|
*/ |
|
99
|
|
|
public function testConvert($pagePath, $baseTag, $path, $result) |
|
100
|
|
|
{ |
|
101
|
|
|
if (isset($pagePath)) { |
|
102
|
|
|
$this->getAddress()->setPagePath($pagePath); |
|
103
|
|
|
} |
|
104
|
|
|
if (isset($baseTag)) { |
|
105
|
|
|
$this->getAddress()->setBaseTag($baseTag); |
|
106
|
|
|
} |
|
107
|
|
|
$this->assertSame($this->getAddress()->convert($path), $result); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function dataForConvert() |
|
111
|
|
|
{ |
|
112
|
|
|
return [ |
|
113
|
|
|
'normal page with base' => [ |
|
114
|
|
|
'https://www.php.net/manual/en/function.parse-url.php', |
|
115
|
|
|
'https://www.php.net/manual/en/function.parse-url.php', |
|
116
|
|
|
'/images/[email protected]', |
|
117
|
|
|
'https://www.php.net/images/[email protected]' |
|
118
|
|
|
], |
|
119
|
|
|
'normal page without base' => [ |
|
120
|
|
|
'https://kafshnice.ir/product-category/shoe/for-men/', |
|
121
|
|
|
null, |
|
122
|
|
|
'https://kafshnice.ir/wp-content/uploads/2020/01/2020-01-23_6-11-45-99x75.png', |
|
123
|
|
|
'https://kafshnice.ir/wp-content/uploads/2020/01/2020-01-23_6-11-45-99x75.png' |
|
124
|
|
|
], |
|
125
|
|
|
'normal page without base 2' => [ |
|
126
|
|
|
'https://roadmap.sh/backend', |
|
127
|
|
|
null, |
|
128
|
|
|
'/_next/static/hxwb-QfpHEYaFAmytdA9D/pages/%5Broadmap%5D.js', |
|
129
|
|
|
'https://roadmap.sh/_next/static/hxwb-QfpHEYaFAmytdA9D/pages/%5Broadmap%5D.js' |
|
130
|
|
|
], |
|
131
|
|
|
'normal page without base 3' => [ |
|
132
|
|
|
'https://bastam.bankmellat.ir/bastam/shahab_service', |
|
133
|
|
|
null, |
|
134
|
|
|
'/bastam/resources/images/browserSupport/war_icon.png', |
|
135
|
|
|
'https://bastam.bankmellat.ir/bastam/resources/images/browserSupport/war_icon.png' |
|
136
|
|
|
] |
|
137
|
|
|
]; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return ConvertToAbsolutePath |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getAddress(): ConvertToAbsolutePath |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->address; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param ConvertToAbsolutePath $address |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setAddress(ConvertToAbsolutePath $address): void |
|
152
|
|
|
{ |
|
153
|
|
|
$this->address = $address; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|