1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Retour plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Retour allows you to intelligently redirect legacy URLs, so that you don't |
6
|
|
|
* lose SEO value when rebuilding & restructuring a website |
7
|
|
|
* |
8
|
|
|
* @link https://nystudio107.com/ |
9
|
|
|
* @copyright Copyright (c) 2018 nystudio107 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace nystudio107\retourtests\unit; |
13
|
|
|
|
14
|
|
|
use nystudio107\retour\Retour; |
15
|
|
|
use nystudio107\retour\helpers\UrlHelper; |
16
|
|
|
|
17
|
|
|
use Craft; |
18
|
|
|
|
19
|
|
|
use Codeception\Test\Unit; |
20
|
|
|
use UnitTester; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ExampleUnitTest |
24
|
|
|
* |
25
|
|
|
* @author nystudio107 |
26
|
|
|
* @package Retour |
27
|
|
|
* @since 3.1.40 |
28
|
|
|
*/ |
29
|
|
|
class RetourUnitTest extends Unit |
30
|
|
|
{ |
31
|
|
|
// Properties |
32
|
|
|
// ========================================================================= |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var UnitTester |
36
|
|
|
*/ |
37
|
|
|
protected $tester; |
38
|
|
|
|
39
|
|
|
// Public methods |
40
|
|
|
// ========================================================================= |
41
|
|
|
|
42
|
|
|
// Tests |
43
|
|
|
// ========================================================================= |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Test the sanitizeUrl() method to ensure it sanitizes URLs properly |
47
|
|
|
*/ |
48
|
|
|
public function testSanitizeUrl() |
49
|
|
|
{ |
50
|
|
|
// Strip line feeds |
51
|
|
|
$this->assertSame( |
52
|
|
|
'One fish, Two fish, Red fish, Blue fish.', |
53
|
|
|
UrlHelper::sanitizeUrl(implode( |
54
|
|
|
"", |
55
|
|
|
[ |
56
|
|
|
"One fish, ", |
57
|
|
|
PHP_EOL, |
58
|
|
|
"Two fish, ", |
59
|
|
|
"\r", |
60
|
|
|
"Red fish, ", |
61
|
|
|
"\n", |
62
|
|
|
"Blue fish.", |
63
|
|
|
] |
64
|
|
|
)) |
65
|
|
|
); |
66
|
|
|
// Strip Twig code |
67
|
|
|
$this->assertSame( |
68
|
|
|
'', |
69
|
|
|
UrlHelper::sanitizeUrl('{{ craft.app.config.general.actionTrigger }}') |
70
|
|
|
); |
71
|
|
|
// Strip object syntax Twig code |
72
|
|
|
$this->assertSame( |
73
|
|
|
'', |
74
|
|
|
UrlHelper::sanitizeUrl('{ craft.app.config.general.actionTrigger }') |
75
|
|
|
); |
76
|
|
|
// Strip URL-encoded Twig code |
77
|
|
|
$this->assertSame( |
78
|
|
|
'', |
79
|
|
|
UrlHelper::sanitizeUrl('%7B%7B%20craft.app.config.general.actionTrigger%20%7D%7D') |
80
|
|
|
); |
81
|
|
|
// Strip URL-encoded object syntax Twig code |
82
|
|
|
$this->assertSame( |
83
|
|
|
'', |
84
|
|
|
UrlHelper::sanitizeUrl('%7B%20craft.app.config.general.actionTrigger%20%7D') |
85
|
|
|
); |
86
|
|
|
// Strip HTML entity-encoded Twig code |
87
|
|
|
$this->assertSame( |
88
|
|
|
'', |
89
|
|
|
UrlHelper::sanitizeUrl('{{ craft.app.config.general.actionTrigger }}') |
90
|
|
|
); |
91
|
|
|
// Strip HTML entity-encoded object syntax Twig code |
92
|
|
|
$this->assertSame( |
93
|
|
|
'', |
94
|
|
|
UrlHelper::sanitizeUrl('{ craft.app.config.general.actionTrigger }') |
95
|
|
|
); |
96
|
|
|
// Strip HTML |
97
|
|
|
$this->assertSame( |
98
|
|
|
'/woof/hello', |
99
|
|
|
UrlHelper::sanitizeUrl('/woof/<blockquote>hello</blockquote>') |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|