Example #1
0
File: xml.php Project: Trree/code
function get_remote()
{
    $REMOTE_XML = "remote.xml";
    global $REMOTE_XML;
    $remote = array();
    if (!($doc = xmldocfile($REMOTE_XML))) {
        echo __FUNCTION__ . ":打开文件" . $REMOTE_XML . "失败";
        exit;
    }
    $xpath = $doc->xpath_new_context();
    $output = $xpath->xpath_eval("/KOAL_SSL/UI/WEBUI/Allows");
    $remote_node = $output->nodeset[0];
    foreach ($remote_node->children() as $value_node) {
        if ($value_node->tagname == "Allow") {
            $remote["Allow"] = $value_node->get_content();
        }
    }
    print_r($remote);
    return $remote;
}
Example #2
0
function fetch_sorted_testsuites($file, $type_key, $status_key)
{
    $doc = xmldocfile($file);
    $root = $doc->root();
    $testsuites = $root->get_elements_by_tagname("testsuite");
    $sorted_testsuites = array();
    $testsuite_count = 0;
    foreach ($testsuites as $testsuite) {
        if ($testsuite->get_attribute("type") != $type_key) {
            continue;
        }
        $sorted_testsuites[$testsuite_count]["name"] = $testsuite->get_attribute("name");
        $sorted_testsuites[$testsuite_count]["pass"] = $testsuite->get_attribute("pass");
        $sorted_testsuites[$testsuite_count]["fail"] = $testsuite->get_attribute("fail");
        $sorted_testsuites[$testsuite_count]["notrun"] = $testsuite->get_attribute("notrun");
        $sorted_testsuites[$testsuite_count]["exectime"] = $testsuite->get_attribute("exectime");
        $sorted_testsuites[$testsuite_count]["date"] = $testsuite->get_attribute("date");
        $sorted_testsuites[$testsuite_count]["type"] = $testsuite->get_attribute("type");
        $testcases = array();
        $testcases = $testsuite->get_elements_by_tagname("testcase");
        $testcase_count = 0;
        foreach ($testcases as $testcase) {
            if ($testcase->get_attribute("status") == $status_key) {
                $sorted_testsuites[$testsuite_count]["testcases"][$testcase_count] = $testcase->get_attribute("name");
                $testcase_count++;
            }
        }
        $testsuite_count++;
    }
    if (count($sorted_testsuites) != 0) {
        foreach ($sorted_testsuites as $key => $row) {
            //Order by testsuite name
            $name[$key] = $row["name"];
        }
        array_multisort($name, SORT_ASC, $sorted_testsuites);
    }
    return $sorted_testsuites;
}
Example #3
0
function fetch_regressed_testcases($testsuite_name, $file_1, $file_2)
{
    $doc_1 = xmldocfile($file_1);
    $doc_2 = xmldocfile($file_2);
    $root_1 = $doc_1->root();
    $root_2 = $doc_2->root();
    $testsuites_1 = $root_1->get_elements_by_tagname("testsuite");
    $testsuites_2 = $root_2->get_elements_by_tagname("testsuite");
    $testcases_1 = array();
    $testcases_2 = array();
    $regressed_testcases = array();
    $testflag = 0;
    $testcases_1_count = 0;
    foreach ($testsuites_1 as $testsuite_1) {
        if ($testsuite_1->get_attribute("name") == $testsuite_name) {
            $testcases = array();
            $testcases = $testsuite_1->get_elements_by_tagname("testcase");
            #Store those testcases that failed in the recent run
            foreach ($testcases as $testcase) {
                if ($testcase->get_attribute("status") == "1") {
                    $testcases_1[$testcases_1_count]["name"] = $testcase->get_attribute("name");
                    $message = $testcase->get_elements_by_tagname("message");
                    if (count($message) > 0) {
                        $message_content = preg_replace('"<"', '&lt;', $message[0]->get_content());
                        $testcases_1[$testcases_1_count]["message"] = $message_content;
                    }
                    $stacktrace = $testcase->get_elements_by_tagname("stacktrace");
                    if (count($stacktrace) > 0) {
                        $testcases_1[$testcases_1_count]["stacktrace"] = $stacktrace[0]->get_content();
                    }
                    $testcases_1_count++;
                }
            }
            $testflag = 1;
            break;
        }
    }
    if ($testflag == 0) {
        return $regressed_testcases;
    }
    #return empty array if no entry is present for the recent run
    $testflag = 0;
    $testcases_2_count = 0;
    foreach ($testsuites_2 as $testsuite_2) {
        if ($testsuite_2->get_attribute("name") == $testsuite_name) {
            $testcases = array();
            $testcases = $testsuite_2->get_elements_by_tagname("testcase");
            #Store those testcases that passed in the previous run
            foreach ($testcases as $testcase) {
                if ($testcase->get_attribute("status") == "0") {
                    $testcases_2[$testcases_2_count]["name"] = $testcase->get_attribute("name");
                    $testcases_2_count++;
                }
            }
            $testflag = 1;
            break;
        }
    }
    if ($testflag == 0) {
        return $regressed_testcases;
    }
    #return empty array if no entry is present for the previous run
    if (count($testcases_1) == 0 || count($testcases_2) == 0) {
        return $regresses_testcases;
    }
    #return empty array
    sort($testcases_1);
    sort($testcases_2);
    $testcases_1_count = 0;
    $testcases_2_count = 0;
    $regression_count = 0;
    #Checking for regression
    while ($testcases_1_count < count($testcases_1) && $testcases_2_count < count($testcases_2)) {
        if ($testcases_1[$testcases_1_count]["name"] == $testcases_2[$testcases_2_count]["name"]) {
            $regressed_testcases[$regression_count]["name"] = $testcases_1[$testcases_1_count]["name"];
            $regressed_testcases[$regression_count]["message"] = $testcases_1[$testcases_1_count]["message"];
            $regressed_testcases[$regression_count]["stacktrace"] = $testcases_1[$testcases_1_count]["stacktrace"];
            $regression_count++;
            $testcases_1_count++;
            $testcases_2_count++;
        } else {
            if ($testcases_1[$testcases_1_count]["name"] < $testcases_2[$testcases_2_count]["name"]) {
                $testcases_1_count++;
            } else {
                if ($testcases_1[$testcases_1_count]["name"] > $testcases_2[$testcases_2_count]["name"]) {
                    $testcases_2_count++;
                }
            }
        }
    }
    sort($regressed_testcases);
    return $regressed_testcases;
}
Example #4
0
 function load($xml)
 {
     if (strncmp($xml, "<?xml", 5) == 0) {
         $n0 = xmldoc($xml);
     } else {
         $n0 = xmldocfile($xml);
     }
     $n1 = $n0->children();
     foreach ($n1 as $j) {
         $n2 = $j->children();
         foreach ($n2 as $i) {
             if ($i->type == XML_ELEMENT_NODE and $i->tagname == "t") {
                 $ia = $i->attributes();
                 if ($ia[0]->name == "name" or $ia[0]->name == "form") {
                     $this->template[$ia[0]->value] = $i;
                 }
             }
         }
     }
 }
Example #5
0
 function _parse_for($expr)
 {
     $result = '';
     $tokens = explode(" ", $expr);
     $name = $tokens[1];
     if (strtoupper($tokens[2]) != "IN") {
         trigger_error("Invalid FOR expresion {$expr} <br/>", E_USER_WARNING);
         return false;
     }
     $path = $tokens[3];
     // while the beginning of path is not $ or document then
     // queues the function and repeat
     $functions = array();
     $cosa = substr($path, 0, 6);
     while (substr($path, 0, 1) != '$' && substr($path, 0, 8) != "document" && substr($path, 0, 6) != "xmlmem") {
         preg_match("/([^(]*)\\((.*)\\)/", $path, $regs);
         $path = $regs[2];
         $path = substr($path, 0, strlen($path));
         array_unshift($functions, $regs[1]);
     }
     $parts = explode("/", $path, 2);
     $xml_source = $parts[0];
     $path = '/' . $parts[1];
     // Source maybe xmldoc($path)
     //           or xmlmem($xml)
     //           or $x
     if (substr($xml_source, 0, 8) == 'document') {
         /* PROCESSING FROM A FILE */
         ereg("document\\((.*)\\)", $xml_source, $regs);
         $source = $regs[1];
         $name_doc = str_replace('"', '', $source);
         if (!file_exists($name_doc)) {
             trigger_error("{$name_doc} file not found", E_USER_WARNING);
         }
         $doc = xmldocfile($name_doc);
         //$rootname=_get_root_name($doc->document_element());
         //$path='/'.$rootname.$path;
         if (!$doc) {
             trigger_error("XML source document {$name_doc} was not well formed", E_USER_WARNING);
         }
         $xpath = $doc->xpath_init();
         $ctx = $doc->xpath_new_context();
         $result = $ctx->xpath_eval($path);
         $nodes = $result->nodeset;
         foreach ($functions as $f) {
             if ($f == "distinct-values") {
                 $f = "distinct";
             }
             $nodes = $this->{$f}($nodes);
         }
         $nodeset = array();
         foreach ($nodes as $node) {
             if ($node->node_type() == XML_ATTRIBUTE_NODE) {
                 $nodeset[] = $node->value;
             } else {
                 $nodeset[] = $node->dump_node($node);
             }
         }
         unset($xpath);
         unset($doc);
         unset($cts);
         unset($result);
     } elseif (substr($xml_source, 0, 6) == 'xmlmem') {
         /* PROCESSING FROM MEM */
         ereg("xmlmem\\((.*)\\)", $xml_source, $regs);
         $source = $regs[1];
         $source = str_replace('"', '', $source);
         $name_var = substr($source, 1);
         // NOTE THAT THE XML STRING MUST BE GLOBAL
         if (!isset($GLOBALS[$name_var])) {
             trigger_error("{$name_var} is not visible from here plase use a global string for XML data", E_USER_WARNING);
             return false;
         }
         $data = $GLOBALS[$name_var];
         if (strlen($data) > 0) {
             $doc = xmldoc($data);
             $rootname = $this->_get_root_name($doc->document_element());
             //$path='/'.$rootname.$path;
             if (!$doc) {
                 trigger_error("XML source was not well formed", E_USER_WARNING);
             }
             $xpath = $doc->xpath_init();
             $ctx = $doc->xpath_new_context();
             $result = $ctx->xpath_eval($path);
             $nodes = $result->nodeset;
             foreach ($functions as $f) {
                 if ($f == "distinct-values") {
                     $f = "distinct";
                 }
                 $nodes = $this->{$f}($nodes);
             }
             $nodeset = array();
             foreach ($nodes as $node) {
                 if ($node->node_type() == XML_ATTRIBUTE_NODE) {
                     $nodeset[] = $node->value;
                 } else {
                     $nodeset[] = $node->dump_node($node);
                 }
             }
         }
         unset($xpath);
         unset($doc);
         unset($cts);
         unset($result);
     } elseif (substr($xml_source, 0, 1) == '$') {
         /* PROCESS FROM A VARIABLE */
         //ereg("xmlmem\((.*)\)",$xml_source,$regs);
         $source = $xml_source;
         $var_name = substr($source, 1);
         $data = $this->bindings[$var_name];
         if (strlen($data) > 0) {
             $doc = xmldoc($data);
             $rootname = $this->_get_root_name($doc->document_element());
             $path = '/' . $rootname . $path;
             if (!$doc) {
                 trigger_error("XML source variable {$name_var} was not well formed", E_USER_WARNING);
             }
             $xpath = $doc->xpath_init();
             $ctx = $doc->xpath_new_context();
             $result = $ctx->xpath_eval($path);
             $nodes = $result->nodeset;
             foreach ($functions as $f) {
                 if ($f == "distinct-values") {
                     $f = "distinct";
                 }
                 $nodes = $this->{$f}($nodes);
             }
             $nodeset = array();
             foreach ($nodes as $node) {
                 if ($node->node_type() == XML_ATTRIBUTE_NODE) {
                     $nodeset = $node->value;
                 } else {
                     $nodeset[] = $node->dump_node($node);
                 }
             }
         }
         unset($xpath);
         unset($doc);
         unset($cts);
         unset($result);
     } else {
         trigger_error("Invalid xml source {$xml_source} <br/>", E_USER_WARNING);
         return false;
     }
     $name_of_name = substr($name, 1);
     // Here's where the node_set is set but (but!) we may need to apply a function
     $this->result_sets[$name_of_name] = $nodeset;
     return $name_of_name;
 }