summaryrefslogtreecommitdiff
path: root/plugins/Minify/extlib/minify/min_unit_tests/test_Minify_CSS.php
blob: 96e18752529468ecc2daa761408733127527f7be (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
<?php
require_once '_inc.php';

require_once 'Minify/CSS.php';

function test_CSS()
{
    global $thisDir;
    
    $cssPath = dirname(__FILE__) . '/_test_files/css';
    
    // build test file list
    $d = dir($cssPath);
    while (false !== ($entry = $d->read())) {
        if (preg_match('/^([\w\\-]+)\.css$/', $entry, $m)) {
            $list[] = $m[1];
        }
    }
    $d->close();
    
    foreach ($list as $item) {
    
        $options = array();
        if ($item === 'paths_prepend') {
            $options = array('prependRelativePath' => '../');
        } elseif ($item === 'paths_rewrite') {
            $options = array('currentDir' => $thisDir . '/_test_files/css');
            $tempDocRoot = $_SERVER['DOCUMENT_ROOT'];
            $_SERVER['DOCUMENT_ROOT'] = $thisDir;
        }
        
        $src = file_get_contents($cssPath . "/{$item}.css");
        $minExpected = file_get_contents($cssPath . "/{$item}.min.css");
        $minOutput = Minify_CSS::minify($src, $options);
        
        // reset doc root as configured
        if ($item === 'paths_rewrite') {
            $_SERVER['DOCUMENT_ROOT'] = $tempDocRoot;
        }
        
        $passed = assertTrue($minExpected === $minOutput, 'Minify_CSS : ' . $item);
        
        if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
            echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
            if (!$passed) {
                echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
                echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";    
            }
        }
    }    
}

test_CSS();