1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ogheounit\htmlcompress\unit; |
4
|
|
|
|
5
|
|
|
use ogheo\htmlcompress\View; |
6
|
|
|
|
7
|
|
|
class JsCommentRemovalTest extends \PHPUnit\Framework\TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
public function testUrlWithComment() |
11
|
|
|
{ |
12
|
|
|
$this->assertEquals(View::compress('<script>\'http://should.not.be.removed\' // hue</script>'), '<script>\'http://should.not.be.removed\' </script>'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function testUrlWithoutRemoveInsideQuotehttp() |
16
|
|
|
{ |
17
|
|
|
$this->assertEquals(View::compress('<script>"http://should.not.be.removed"</script>'), '<script>"http://should.not.be.removed"</script>'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testUrlWithoutRemoveInsideApostrofe() |
21
|
|
|
{ |
22
|
|
|
$this->assertEquals(View::compress('<script>\'https://should.not.be.removed\'</script>'), '<script>\'https://should.not.be.removed\'</script>'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testUrlWithoutRemoveInsideQuotehttps() |
26
|
|
|
{ |
27
|
|
|
$this->assertEquals(View::compress('<script>"https://should.not.be.removed"</script>'), '<script>"https://should.not.be.removed"</script>'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testUrlWithoutRemoveUrlWithoutHttpInsideQuote() |
31
|
|
|
{ |
32
|
|
|
$this->assertEquals(View::compress('<script>\'//should.not.be.removed\'</script>'), '<script>\'//should.not.be.removed\'</script>'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testUrlWithoutRemoveUrlWithoutHttpInsideApostrofe() |
36
|
|
|
{ |
37
|
|
|
$this->assertEquals(View::compress('<script>"//should.not.be.removed"</script>'), '<script>"//should.not.be.removed"</script>'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testUrlWithoutRemoveUrlObject() |
41
|
|
|
{ |
42
|
|
|
$this->assertEquals(View::compress('<script>{ |
43
|
|
|
foo://should.be.removed |
44
|
|
|
lala:"//should.not.be.removed" |
45
|
|
|
haja:"//should.not.be.removed"//should be removed but ok if not |
46
|
|
|
lalala:"//should.not.be.removed",//should be removed |
47
|
|
|
yolo:"https://should.not.be.removed";//should be removed |
48
|
|
|
yolo:"http://should.not.be.removed";//should be removed |
49
|
|
|
}</script>'), |
50
|
|
|
'<script>{ foo: lala:"//should.not.be.removed" haja:"//should.not.be.removed" lalala:"//should.not.be.removed", yolo:"https://should.not.be.removed"; yolo:"http://should.not.be.removed"; }</script>'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testUrlWithRemoveCommentInStartOfAPage() |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals(View::compress('<script>//should be removed</script>'), '<script></script>'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testUrlWithRemoveCommentWithSpace() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals(View::compress('<script>test// should be removed</script>'), '<script>test</script>'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testUrlWithRemoveCommentWithUrlSpace() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals(View::compress('<script>test// http://should be removed</script>'), '<script>test</script>'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testUrlWithRemoveCommentWithUrlWithoutSpace() |
70
|
|
|
{ |
71
|
|
|
$this->assertEquals(View::compress('<script>test//http://should.be.removed</script>'), '<script>test</script>'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testUrlWithRemoveCommentUrlCheck() |
75
|
|
|
{ |
76
|
|
|
$this->assertEquals(View::compress('<script>https://should.be.removed</script>'), '<script>https:</script>'); |
77
|
|
|
} |
78
|
|
|
public function testUrlWithoutRemoveCommentUrlCheckInsideString() |
79
|
|
|
{ |
80
|
|
|
$this->assertEquals(View::compress('<script>"yolo yolo yolo https://should.not.be.removed.but.ok.if.removed yolo yolo yolo"</script>'), '<script>"yolo yolo yolo https://should.not.be.removed.but.ok.if.removed yolo yolo yolo"</script>'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testUrlWithoutRemoveCommentDoubleUrlCheckInsideString() |
84
|
|
|
{ |
85
|
|
|
$this->assertEquals(View::compress('<script>"https://should.not.be.removed", "https://should.not.be.removed"</script>'), '<script>"https://should.not.be.removed", "https://should.not.be.removed"</script>'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testUrlWithRemoveCommentAfterString() |
89
|
|
|
{ |
90
|
|
|
$this->assertEquals(View::compress('<script>"https://should.not.be.removed", "//should.not.be.removed" //shoud be removed</script>'), '<script>"https://should.not.be.removed", "//should.not.be.removed" </script>'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testUrlWithoutRemoveCommentTwoSeparateUrlStrings() |
94
|
|
|
{ |
95
|
|
|
$this->assertEquals(View::compress('<script>"https://should.not.be.removed", "//should.not.be.removed"</script>'), '<script>"https://should.not.be.removed", "//should.not.be.removed"</script>'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testUrlWithRemoveCommentRandomString() |
99
|
|
|
{ |
100
|
|
|
$this->assertEquals(View::compress('<script>ahaha: "//trolololo.com"//should be removed</script>'), '<script>ahaha: "//trolololo.com"</script>'); |
101
|
|
|
} |
102
|
|
|
} |