1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\StaticPublishQueue\Test; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\StaticPublishQueue\Service\URLSanitisationService; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class URLSanitisationServiceTest |
11
|
|
|
* |
12
|
|
|
* @package SilverStripe\StaticPublishQueue\Test |
13
|
|
|
*/ |
14
|
|
|
class URLSanitisationServiceTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
public function testFormattingOptions() |
17
|
|
|
{ |
18
|
|
|
// formatted output |
19
|
|
|
$urlsService = new URLSanitisationService(); |
20
|
|
|
$urlsService->addURLs(['http://some-locale/some-page/']); |
21
|
|
|
$urls = $urlsService->getURLs(); |
22
|
|
|
|
23
|
|
|
$this->assertEquals([ |
24
|
|
|
'http://some-locale/some-page/' => 0, |
25
|
|
|
], $urls); |
26
|
|
|
|
27
|
|
|
// not formatted output |
28
|
|
|
$urlsService = new URLSanitisationService(); |
29
|
|
|
$urlsService->addURLs(['http://some-locale/some-page/']); |
30
|
|
|
$urls = $urlsService->getURLs(false); |
31
|
|
|
|
32
|
|
|
$this->assertEquals([ |
33
|
|
|
'http://some-locale/some-page/', |
34
|
|
|
], $urls); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* If force SSL is disabled (disabled by default), URLs are passed without protocol modification |
39
|
|
|
*/ |
40
|
|
|
public function testUrlsWithoutSSL() |
41
|
|
|
{ |
42
|
|
|
// normal transformation (protocol change) |
43
|
|
|
$urlsService = new URLSanitisationService(); |
44
|
|
|
$urlsService->addURLs(['http://some-locale/some-page/']); |
45
|
|
|
$urls = $urlsService->getURLs(); |
46
|
|
|
|
47
|
|
|
$expected = [ |
48
|
|
|
'http://some-locale/some-page/' => 0, |
49
|
|
|
]; |
50
|
|
|
$this->assertEquals($expected, $urls); |
51
|
|
|
|
52
|
|
|
// redundant transformation (protocol change) |
53
|
|
|
$urlsService = new URLSanitisationService(); |
54
|
|
|
$urlsService->addURLs(array_keys($urls)); |
55
|
|
|
$this->assertEquals($expected, $urlsService->getURLs()); |
56
|
|
|
|
57
|
|
|
// normal transformation (removal of stage params) |
58
|
|
|
$urlsService = new URLSanitisationService(); |
59
|
|
|
$urlsService->addURLs([ |
60
|
|
|
'http://some-locale/some-page/?stage=Stage', |
61
|
|
|
'http://some-locale/some-page/?stage=Live', |
62
|
|
|
'https://some-locale/some-page/?stage=Live&deviceContext=mobile', |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$urls = $urlsService->getURLs(); |
66
|
|
|
$this->assertEquals([ |
67
|
|
|
'http://some-locale/some-page/' => 0, |
68
|
|
|
'https://some-locale/some-page/?deviceContext=mobile' => 1, |
69
|
|
|
], $urls); |
70
|
|
|
|
71
|
|
|
// redundant transformation (removal of stage params) |
72
|
|
|
$urlsService = new URLSanitisationService(); |
73
|
|
|
$urlsService->addURLs(array_keys($urls)); |
74
|
|
|
$this->assertEquals([ |
75
|
|
|
'http://some-locale/some-page/' => 0, |
76
|
|
|
'https://some-locale/some-page/?deviceContext=mobile' => 1, |
77
|
|
|
], $urlsService->getURLs()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* If force SSL is enabled, URLs are swtiched to https |
82
|
|
|
*/ |
83
|
|
|
public function testUrlsWithSSL() |
84
|
|
|
{ |
85
|
|
|
Config::modify()->set(URLSanitisationService::class, 'force_ssl', true); |
86
|
|
|
|
87
|
|
|
// normal transformation (protocol change) |
88
|
|
|
$urlsService = new URLSanitisationService(); |
89
|
|
|
$urlsService->addURLs(['http://some-locale/some-page/']); |
90
|
|
|
$urls = $urlsService->getURLs(); |
91
|
|
|
|
92
|
|
|
$expected = [ |
93
|
|
|
'https://some-locale/some-page/' => 0, |
94
|
|
|
]; |
95
|
|
|
$this->assertEquals($expected, $urls); |
96
|
|
|
|
97
|
|
|
// redundant transformation (protocol change) |
98
|
|
|
$urlsService = new URLSanitisationService(); |
99
|
|
|
$urlsService->addURLs(array_keys($urls)); |
100
|
|
|
$this->assertEquals($expected, $urlsService->getURLs()); |
101
|
|
|
|
102
|
|
|
// normal transformation (removal of stage params) |
103
|
|
|
$urlsService = new URLSanitisationService(); |
104
|
|
|
$urlsService->addURLs([ |
105
|
|
|
'http://some-locale/some-page/?stage=Stage', |
106
|
|
|
'http://some-locale/some-page/?stage=Live', |
107
|
|
|
'https://some-locale/some-page/?stage=Live&deviceContext=mobile', |
108
|
|
|
]); |
109
|
|
|
|
110
|
|
|
$urls = $urlsService->getURLs(); |
111
|
|
|
$this->assertEquals([ |
112
|
|
|
'https://some-locale/some-page/' => 0, |
113
|
|
|
'https://some-locale/some-page/?deviceContext=mobile' => 1, |
114
|
|
|
], $urls); |
115
|
|
|
|
116
|
|
|
// redundant transformation (removal of stage params) |
117
|
|
|
$urlsService = new URLSanitisationService(); |
118
|
|
|
$urlsService->addURLs(array_keys($urls)); |
119
|
|
|
$this->assertEquals([ |
120
|
|
|
'https://some-locale/some-page/' => 0, |
121
|
|
|
'https://some-locale/some-page/?deviceContext=mobile' => 1, |
122
|
|
|
], $urlsService->getURLs()); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|