PluginProbe ʕ •ᴥ•ʔ
10Web Booster – Website speed optimization, Cache & Page Speed optimizer / trunk
10Web Booster – Website speed optimization, Cache & Page Speed optimizer vtrunk
2.33.0 2.30.5 2.30.7 2.30.9 2.31.10 2.31.8 2.32.11 2.32.21 2.32.3 2.32.4 2.32.7 2.6.31 2.6.40 2.6.42 2.6.7 2.7.37 2.7.44 2.7.47 2.8.18 2.8.19 2.8.32 2.8.34 2.8.35 2.9.23 2.9.24 2.9.25 2.9.27 v2.27.4 trunk 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.17 2.0.18 2.0.21 2.0.22 2.0.25 2.0.26 2.0.27 2.0.3 2.0.7 2.0.9 2.10.46 2.10.65 2.10.66 2.10.68 2.11.41 2.11.42 2.11.43 2.12.15 2.12.21 2.12.22 2.12.23 2.12.26 2.13.37 2.13.40 2.13.41 2.13.42 2.13.44 2.13.45 2.13.47 2.14.49 2.14.50 2.15.18 2.17.21 2.17.23 2.18.17 2.19.44 2.19.45 2.19.46 2.19.49 2.2.12 2.2.15 2.2.16 2.2.18 2.2.8 2.20.31 2.20.32 2.20.33 2.21.11 2.21.12 2.21.16 2.21.25 2.22.32 2.23.13 2.23.15 2.23.16 2.23.18 2.24.12 2.24.14 2.24.18 2.25.14 2.26.6 2.28.10 2.28.13 2.28.14 2.28.7 2.29.1 2.29.2 2.29.3 2.3.0 2.3.1 2.3.2 2.3.3 2.30.18
tenweb-speed-optimizer / vendor / mrclay / jsmin-php / tests / JSMinTest.php
tenweb-speed-optimizer / vendor / mrclay / jsmin-php / tests Last commit date
Resources 3 years ago JSMinTest.php 3 years ago TestCase.php 3 years ago bootstrap.php 3 years ago
JSMinTest.php
168 lines
1 <?php
2
3 namespace JSMin\Test;
4
5 use JSMin\JSMin;
6
7 /**
8 * Copyright (c) 2009, Robert Hafner
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * Neither the name of the Stash Project nor the
19 * names of its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL Robert Hafner BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34 class JSMinTest extends TestCase {
35
36 /**
37 * @group minify
38 * @dataProvider minifyProvider
39 */
40 public function testMinify($testName, $input, $expected, $actualFile)
41 {
42 $actual = JSMin::minify($input);
43 if ($actual !== $expected && is_writable(dirname($actualFile))) {
44 file_put_contents($actualFile, $actual);
45 }
46 $this->assertEquals($expected, $actual, 'Running Minify Test: ' . $testName);
47 }
48
49 public function testWhitespace() {
50 $this->assertEquals("hello;", JSMin::minify("\r\n\r\n \t\v\fhello;\r\n"));
51 }
52
53 public function testBomRemoval() {
54 $this->assertEquals("hello;", JSMin::minify("\xEF\xBB\xBFhello;"));
55 }
56
57 public function testFuncOverload() {
58 if (!function_exists('mb_strlen') || !((int)ini_get('mbstring.func_overload') & 2)) {
59 $this->markTestIncomplete('Cannot be tested unless mbstring.func_overload is used');
60 }
61
62 $input = 'function(s) { return /^[£$€?.]/.test(s); }';
63 $expected = 'function(s){return/^[£$€?.]/.test(s);}';
64 $this->assertEquals($expected, JSMin::minify($input));
65 }
66
67 /**
68 * @dataProvider exceptionProvider
69 */
70 public function testExpections($input, $label, $expClass, $expMessage) {
71 $eClass = $eMsg = '';
72 try {
73 JSMin::minify($input);
74 } catch (\Exception $e) {
75 $eClass = get_class($e);
76 $eMsg = $e->getMessage();
77 }
78 $this->assertTrue(
79 $eClass === $expClass && $eMsg === $expMessage,
80 'JSMin : throw on ' . $label
81 );
82 }
83
84 public function exceptionProvider() {
85 return array(
86 array(
87 '"Hello'
88 ,'Unterminated String'
89 ,'JSMin\\UnterminatedStringException'
90 ,"JSMin: Unterminated String at byte 5: \"Hello"),
91 array(
92 "return /regexp\n}"
93 ,'Unterminated RegExp'
94 ,'JSMin\\UnterminatedRegExpException'
95 ,"JSMin: Unterminated RegExp at byte 14: /regexp\n"),
96 array(
97 "return/regexp\n}"
98 ,'Unterminated RegExp'
99 ,'JSMin\\UnterminatedRegExpException'
100 ,"JSMin: Unterminated RegExp at byte 13: /regexp\n"),
101 array(
102 ";return/regexp\n}"
103 ,'Unterminated RegExp'
104 ,'JSMin\\UnterminatedRegExpException'
105 ,"JSMin: Unterminated RegExp at byte 14: /regexp\n"),
106 array(
107 ";return /regexp\n}"
108 ,'Unterminated RegExp'
109 ,'JSMin\\UnterminatedRegExpException'
110 ,"JSMin: Unterminated RegExp at byte 15: /regexp\n"),
111 array(
112 "typeof/regexp\n}"
113 ,'Unterminated RegExp'
114 ,'JSMin\\UnterminatedRegExpException'
115 ,"JSMin: Unterminated RegExp at byte 13: /regexp\n"),
116 array(
117 "/* Comment "
118 ,'Unterminated Comment'
119 ,'JSMin\\UnterminatedCommentException'
120 ,"JSMin: Unterminated comment at byte 11: /* Comment "),
121 );
122 }
123
124 /**
125 * This function loads all of the test cases from the specified group.
126 * Groups are created simply by populating the appropriate directories:
127 *
128 * /tests/Resources/GROUPNAME/input/
129 * /tests/Resources/GROUPNAME/output/
130 *
131 * Each test case should have two identically named files, with the raw
132 * javascript going in the test folder and the expected results to be in
133 * the output folder.
134 *
135 * @param $group string
136 * @return array
137 */
138 public function getTestFiles($group)
139 {
140 $baseDir = __DIR__ . '/Resources/' . $group . '/';
141 $testDir = $baseDir . 'input/';
142 $expectDir = $baseDir . 'expected/';
143 $actualDir = $baseDir . 'actual/';
144
145 $returnData = array();
146
147 $testFiles = scandir($testDir);
148 foreach ($testFiles as $testFile) {
149 if (substr($testFile, -3) !== '.js' || !file_exists(($expectDir . $testFile))) {
150 continue;
151 }
152
153 $testInput = file_get_contents($testDir . $testFile);
154 $expectedOutput = file_get_contents($expectDir . $testFile);
155 $actualFile = $actualDir . $testFile;
156
157 $returnData[] = array($testFile, $testInput, $expectedOutput, $actualFile);
158 }
159
160 return $returnData;
161 }
162
163 public function minifyProvider()
164 {
165 return $this->getTestFiles('minify');
166 }
167 }
168