예제 #1
0
<?php 
include 'browser.php';
$properties = array('browser', 'browser_version', 'engine', 'engine_version', 'platform', 'platform_version', 'platform_type');
foreach ($ua_tests as $title => $test) {
    if (!isset($test['ua'])) {
        $test['ua'] = '';
    }
    $uas = is_array($test['ua']) ? $test['ua'] : array($test['ua']);
    echo '<tr>';
    echo '<th rowspan="' . count($uas) . '" id="' . preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $title) . '"><a href="#' . preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $title) . '">' . $title . '</a></th>';
    foreach ($uas as $ua) {
        if ($ua != $uas[0]) {
            echo '<tr>';
        }
        $browser = new Browser($ua);
        $browser->parse();
        foreach ($properties as $property) {
            if (!isset($test['test'][$property]) || $test['test'][$property] == '') {
                if (empty($browser->{$property})) {
                    $message = 'Not tested, <b style="color:#FF0000">not found</b>';
                } else {
                    $message = 'Not tested, found <b>' . $browser->{$property} . '</b>';
                }
                echo '<td style="background:#EEEEEE">' . $message . '</td>';
            } elseif (strtolower($test['test'][$property]) == strtolower($browser->{$property})) {
                echo '<td style="background:#00FF00">Pass (' . $browser->{$property} . ')</td>';
            } else {
                echo '<td style="background:#FF0000">Fail (Expected <b>' . $test['test'][$property] . '</b>, found <b>' . $browser->{$property} . '</b>)</td>';
            }
        }
        echo '<td>' . $ua . '</td>';
 /**
  * Asserts all agents in the given array match the expected name, version, system, device, engine
  * and templated string.
  * @param array $agents is a map of user agents to their expected values.
  */
 private function assertParse($agents)
 {
     foreach ($agents as $agent => $values) {
         $browser = Browser::parse($agent);
         $this->assertEquals($values["name"], $browser->getName());
         $this->assertEquals($values["system"], $browser->getSystem());
         $this->assertEquals($values["device"], $browser->getDevice());
         $this->assertEquals($values["version"], $browser->getVersion());
         $this->assertEquals($values["engine"], $browser->getEngine());
         $this->assertEquals($values["template"], $browser->forTemplate());
     }
 }