summaryrefslogtreecommitdiff
path: root/plugins/Minify/extlib/minify/min_unit_tests/test_Minify_HTML.php
blob: 69aeff568b031b0460618e5ce3025966ecd5b3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require_once '_inc.php';

require_once 'Minify/HTML.php';
require_once 'Minify/CSS.php';
require_once 'JSMin.php';

function test_HTML()
{
    global $thisDir;
    
    $src = file_get_contents($thisDir . '/_test_files/html/before.html');
    $minExpected = file_get_contents($thisDir . '/_test_files/html/before.min.html');
    
    $time = microtime(true);
    $minOutput = Minify_HTML::minify($src, array(
        'cssMinifier' => array('Minify_CSS', 'minify')
        ,'jsMinifier' => array('JSMin', 'minify')
    ));
    $time = microtime(true) - $time;
    
    $passed = assertTrue($minExpected === $minOutput, 'Minify_HTML');
    
    if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
        if ($passed) {
            echo "\n---Source: ", strlen($src), " bytes\n"
               , "---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
        } else {
            echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
               , "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n"
               , "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n";
        }
    }
    
    $src = file_get_contents($thisDir . '/_test_files/html/before2.html');
    $minExpected = file_get_contents($thisDir . '/_test_files/html/before2.min.html');
    
    $time = microtime(true);
    $minOutput = Minify_HTML::minify($src, array(
        'cssMinifier' => array('Minify_CSS', 'minify')
        ,'jsMinifier' => array('JSMin', 'minify')
    ));
    $time = microtime(true) - $time;
    
    $passed = assertTrue($minExpected === $minOutput, 'Minify_HTML');
    
    if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
        if ($passed) {
            echo "\n---Source: ", strlen($src), " bytes\n"
               , "---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
        } else {
            echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
               , "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n"
               , "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n";
        }
    }
}

test_HTML();