PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / tests / JSMinTest.php

JSMinTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/mrclay/minify/tests/JSMinTest.php

130 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Minify\Test;
4
5 use Exception;
6 use JSMin\JSMin;
7
8 class JSMinTest extends TestCase
9 {
10 public function test1()
11 {
12 $src = file_get_contents(self::$test_files . '/js/before.js');
13 $minExpected = file_get_contents(self::$test_files . '/js/before.min.js');
14 $minOutput = JSMin::minify($src);
15 $this->assertSame($minExpected, $minOutput, 'Overall');
16 }
17
18 public function test2()
19 {
20 $src = file_get_contents(self::$test_files . '/js/issue144.js');
21 $minExpected = file_get_contents(self::$test_files . '/js/issue144.min.js');
22 $minOutput = JSMin::minify($src);
23 $this->assertSame($minExpected, $minOutput, 'Handle "+ ++a" syntax (Issue 144)');
24 }
25
26 public function test3()
27 {
28 $src = file_get_contents(self::$test_files . '/js/issue256.js');
29 $minExpected = file_get_contents(self::$test_files . '/js/issue256.min.js');
30 $minOutput = JSMin::minify($src);
31 $this->assertSame($minExpected, $minOutput, 'Handle \n!function()... (Issue 256)');
32 }
33
34 public function test4()
35 {
36 $have_overload = function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2);
37 if (!$have_overload) {
38 $this->markTestSkipped();
39 }
40
41 $src = file_get_contents(self::$test_files . '/js/issue132.js');
42 $minExpected = file_get_contents(self::$test_files . '/js/issue132.min.js');
43 $minOutput = JSMin::minify($src);
44 $this->assertSame($minExpected, $minOutput, 'mbstring.func_overload shouldn\'t cause failure (Issue 132)');
45 }
46
47 public function test5()
48 {
49 $src = file_get_contents(self::$test_files . '/js/regexes.js');
50 $minExpected = file_get_contents(self::$test_files . '/js/regexes.min.js');
51 $minOutput = JSMin::minify($src);
52 $this->assertSame($minExpected, $minOutput, 'Identify RegExp literals');
53 }
54
55 /**
56 * @param string $js
57 * @param string $label
58 * @param string $expClass
59 * @param string $expMessage
60 *
61 * @dataProvider JSMinExceptionDataProvider
62 */
63 public function testJSMinException($js, $label, $expClass, $expMessage)
64 {
65 $eClass = $eMsg = '';
66 try {
67 JSMin::minify($js);
68 } catch (Exception $e) {
69 $eClass = get_class($e);
70 $eMsg = $e->getMessage();
71 }
72 $this->assertTrue($eClass === $expClass && $eMsg === $expMessage, 'Throw on ' . $label);
73 }
74
75 public function JSMinExceptionDataProvider()
76 {
77 // $js, $label, $expClass, $expMessage
78 return array(
79 array(
80 '"Hello',
81 'Unterminated String',
82 'JSMin\UnterminatedStringException',
83 "JSMin: Unterminated String at byte 5: \"Hello",
84 ),
85
86 array(
87 "return /regexp\n}",
88 'Unterminated RegExp',
89 'JSMin\UnterminatedRegExpException',
90 "JSMin: Unterminated RegExp at byte 14: /regexp\n",
91 ),
92
93 array(
94 "return/regexp\n}",
95 'Unterminated RegExp',
96 'JSMin\UnterminatedRegExpException',
97 "JSMin: Unterminated RegExp at byte 13: /regexp\n",
98 ),
99
100 array(
101 ";return/regexp\n}",
102 'Unterminated RegExp',
103 'JSMin\UnterminatedRegExpException',
104 "JSMin: Unterminated RegExp at byte 14: /regexp\n",
105 ),
106
107 array(
108 ";return /regexp\n}",
109 'Unterminated RegExp',
110 'JSMin\UnterminatedRegExpException',
111 "JSMin: Unterminated RegExp at byte 15: /regexp\n",
112 ),
113
114 array(
115 "typeof/regexp\n}",
116 'Unterminated RegExp',
117 'JSMin\UnterminatedRegExpException',
118 "JSMin: Unterminated RegExp at byte 13: /regexp\n",
119 ),
120
121 array(
122 "/* Comment ",
123 'Unterminated Comment',
124 'JSMin\UnterminatedCommentException',
125 "JSMin: Unterminated comment at byte 11: /* Comment ",
126 ),
127 );
128 }
129 }
130