report.php 4.9 KB
Newer Older
K
kaisy00 已提交
1 2 3 4 5 6 7 8 9
<?php
    error_reporting(E_ERROR|E_WARNING);
//经常碰到傲游和IE6同时完成的情况,如何处理比较合适?
//TODO add php info in xml
if (substr_count($_POST['config'], "browser") == 0) {
    echo "report only create if browser is set\n\r<br />";
    return;
}

Y
yancend 已提交
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

function match($fileName, $matcher )
{
    if ( $matcher == '*' )
        return true;
    $len = strlen( $matcher );

    /**
     * 处理多选分支,有一个成功则成功,filter后面参数使用|切割
     * @var unknown_type
     */
    $ms = explode( ',' , $matcher );
    if ( sizeof( $ms ) > 1 ) {
        //这里把或的逻辑改成与
        foreach ( $ms as $matcher1 ) {
            if ( !match($fileName, $matcher1 ) )
                return false;
        }
        return true;
    }

    /**
     * 处理反向选择分支
     */
    if ( substr( $matcher , 0 , 1 ) == '!' ) {
        $m = substr( $matcher , 1 );
        if ( substr( $fileName , 0 , strlen( $m ) ) == $m )
            return false;
        return true;
    }

    if ( $len > strlen( $fileName ) ) {
        return false;
    }
    return substr( $fileName , 0 , $len ) == $matcher;
}
K
kaisy00 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
function report()
{
    /**
     * for junit report
     */
    $dom = new DOMDocument('1.0', 'utf-8');
    $suite = $dom->appendChild($dom->createElement('testsuite'));
    $cfg = preg_split('/[&=]/', $_POST['config']);
    $config = array();
    for ($i = 0; $i < sizeof($cfg); $i += 2) {
        //	echo "{$cfg[$i]} {$cfg[$i+1]}\r\n<br />";
        $config[$cfg[$i]] = $cfg[$i + 1];
        $p = $suite->appendChild($dom->createElement("property"));

        $p->setAttribute('name', $cfg[$i]);
        $p->setAttribute('value', $cfg[$i + 1]);

    }
    $suite->setAttribute("name", $config['browser']);
    $errors = 0;
    $failures = 0;
    $tests = 0;
    $time = 0;
    $filter = $config['filter'];
    foreach ($_POST as $key => $value) {
        if ($key == 'config')
            continue;
Y
yancend 已提交
73
        echo $key.'        ';
K
kaisy00 已提交
74
        $info = explode(";", $value);
Y
yancend 已提交
75 76

        if ($filter!='' && (!match($key,$filter))){
K
kaisy00 已提交
77
            continue;
Y
yancend 已提交
78
        }
K
kaisy00 已提交
79 80 81 82 83 84
        //errornum + ',' + allnum + ','+ kissPerc || 0 + ',' + wb.kissstart + ','+ wb.kissend;
        $casetime = ($info[4] - $info[3]) / 1000;
        $time += $casetime;
        $tests++;
        $failure = (int)($info[0]);
        $case = $suite->appendChild($dom->createElement('testcase'));
Y
yancend 已提交
85
        $case->setAttribute("name", str_replace('_','.',$key));
K
kaisy00 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98
        $case->setAttribute("time", $casetime);
        $case->setAttribute("cov", $info[2]);
        $case->setAttribute('failNumber', $info[0]);
        $case->setAttribute('totalNumber', $info[1]);
        $case->setAttribute('recordCovForBrowser',$info[5]);
        $case->setAttribute('browserInfo', $config['browser']);
        $case->setAttribute('hostInfo', Config::$BROWSERS[$config['browser']][0]);
        //            covHtml( $config[ 'browser' ] . '/' . $key , $info[ 2 ] );
        if ($failure > 0) {
            $failures++;
            $failinfo = $case->appendChild($dom->createElement('failure'));
            $failinfo->setAttribute('type', 'junit.framework.AssertionFailedError');
            //FROM php.net, You cannot simply overwrite $textContent, to replace the text content of a DOMNode, as the missing readonly flag suggests.
Y
yancen 已提交
99
            $kiss = join(".", split("/", $key));
K
kaisy00 已提交
100 101 102 103 104 105 106 107 108 109
            //                $failinfo->appendChild( new DOMText( $value ) );
            $failinfo->appendChild(new DOMText("<a href=\"http://10.48.31.90:8089/ueditor_git/_test/tools/br/run.php?case=$kiss\">run</a>"));
        }
        //TODO add more case info in xml
    }

    $suite->setAttribute('time', $time);
    $suite->setAttribute('failures', $failures);
    $suite->setAttribute('tests', $tests);

Y
yancend 已提交
110 111 112 113 114
//    $dirName = "report_{$config['filter']}";
    $dirName = str_replace('/','_',"report_{$config['filter']}");
    if (!is_dir($dirName))
        mkdir($dirName);
    $dom->save($dirName."/{$config['browser']}.xml");
K
kaisy00 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
}
include 'config.php';
$config;
$configs = preg_split('/[&=]/', $_POST['config']);
for ($j = 0; $j < sizeof($configs); $j += 2) {
    //	echo "{$cfg[$i]} {$cfg[$i+1]}\r\n<br />";
//    if(strcmp($configs[$j],'browserSet')==0){
        $config[$configs[$j]] = $configs[$j + 1];
//    }

}
report();

$dom = new DOMDocument('1.0', 'utf-8');
$testsuites = $dom->appendChild($dom->createElement('testsuites'));
Y
yancend 已提交
130
$dirName = str_replace('/','_',"report_{$config['filter']}");
K
kaisy00 已提交
131
foreach (Config::getBrowserSet($configBrowserSet) as $key => $value) {
Y
yancend 已提交
132 133

    $file = $dirName."/$key.xml";
K
kaisy00 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    if (!file_exists($file)) {
        echo "wait for report : $file\r\n<br />";
        return;
    }
    $xmlDoc = new DOMDocument('1.0', 'utf-8');
    $xmlDoc->load($file);
    $xmlDom = $xmlDoc->documentElement;
    //echo $xmlDom->nodeName;
    $testsuites->appendChild($dom->importNode($xmlDom, true));
}
$dom->save("report.xml");
$browserNum = count(Config::getBrowserSet($configBrowserSet));
require_once 'record.php';
record();

Config::StopAll();
K
kaisy 已提交
150
?>