|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2013 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | namespace Magento\Framework\Code\Test\Unit\Minifier\Adapter\Js;
|
7 | 7 |
|
|
10 | 10 |
|
11 | 11 | class JShrinkTest extends TestCase
|
12 | 12 | {
|
13 |
| - public function testMinify() |
| 13 | + /** |
| 14 | + * @param string $content |
| 15 | + * @param string $expected |
| 16 | + * @return void |
| 17 | + * @throws \Exception |
| 18 | + * @dataProvider minifyDataProvider |
| 19 | + */ |
| 20 | + public function testMinify(string $content, string $expected): void |
14 | 21 | {
|
15 |
| - $content = file_get_contents(__DIR__ . '/../../_files/js/original.js'); |
16 | 22 | $minifier = new JShrink();
|
17 | 23 | $actual = $minifier->minify($content);
|
18 |
| - $expected = "var one='one';var two='two';"; |
19 | 24 | $this->assertEquals($expected, $actual);
|
20 | 25 | }
|
| 26 | + |
| 27 | + public static function minifyDataProvider(): array |
| 28 | + { |
| 29 | + return [ |
| 30 | + 'line breaks' => [ |
| 31 | + 'content' => file_get_contents(__DIR__ . '/../../_files/js/original.js'), |
| 32 | + 'expected' => "var one='one';var two='two';" |
| 33 | + ], |
| 34 | + 'regex1' => [ |
| 35 | + 'content' => <<<JS |
| 36 | +function test (string) { |
| 37 | + return (string || '').replace( |
| 38 | + /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, |
| 39 | + '\\$1' |
| 40 | + ) |
| 41 | +} |
| 42 | +JS, |
| 43 | + 'expected' => <<<JS |
| 44 | +function test(string){return(string||'').replace(/([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g,'\\$1')} |
| 45 | +JS |
| 46 | + ], |
| 47 | + 'regex2' => [ |
| 48 | + 'content' => <<<JS |
| 49 | +function test(str) { |
| 50 | + return (/^[a-zA-Z\d\-_/:.[\]&@()! ]+$/i).test(str); |
| 51 | +} |
| 52 | +JS, |
| 53 | + 'expected' => <<<JS |
| 54 | +function test(str){return(/^[a-zA-Z\d\-_/:.[\]&@()! ]+$/i).test(str);} |
| 55 | +JS |
| 56 | + ], |
| 57 | + ]; |
| 58 | + } |
21 | 59 | }
|
0 commit comments