test for noauth status page without connection; add support for connection status...
authorChristian Weiske <cweiske@cweiske.de>
Fri, 17 Dec 2010 08:01:37 +0000 (09:01 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 17 Dec 2010 08:01:37 +0000 (09:01 +0100)
Wrt3g/HtmlParser.php
tests/status_noauth-aquiring.phpt [new file with mode: 0644]

index d420f4d..f369bd1 100644 (file)
@@ -19,6 +19,7 @@ class Wrt3g_HtmlParser
         'GPRS_MSG.ACQUIRING'   => 'aquiring',
         'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
+        'GPRS_MSG.None'        => null,
         'GPRS_MSG.GOOD'        => 'good',
         'GPRS_MSG.EXCELLENT'   => 'excellent',
         'GPRS_MSG.CTIME'       => 'connection time',
@@ -135,8 +136,6 @@ class Wrt3g_HtmlParser
      *               - card revision
      *               - card firmware
      *               - IMSI
-     *
-     * @todo FIXME implement "connection" value as index_wstatus2() does it
      */
     public function status_noauth($body)
     {
@@ -150,7 +149,8 @@ class Wrt3g_HtmlParser
         $doc->loadHtml($body);
                $xpath = new DOMXPath($doc);
                $trs   = $xpath->query('//table//table/tbody/tr');
-        $arRaw = array();
+        $arRaw = array('connection' => null);
+        $bAquiring = false;
         foreach ($trs as $tr) {
             $titleItems = $xpath->query('td[@width=125]/text()', $tr);
             $valueItems = $xpath->query('td[@width=296]/*[1]', $tr);
@@ -165,10 +165,22 @@ class Wrt3g_HtmlParser
             $value = trim(strip_tags($value));
             if (substr($value, 0, 8) == 'Capture(') {
                 $value = self::$arTranslations[substr($value, 8, -1)];
+                if ($value == 'aquiring') {
+                    $bAquiring = true;
+                    $value = null;
+                }
             }
         }
         unset($value);
 
+        if ($bAquiring) {
+            $arRaw['connection'] = 'connecting';
+        } else if ($arRaw['type'] != null) {
+            $arRaw['connection'] = 'connected';
+        } else {
+            $arRaw['connection'] = 'disconnected';
+        }
+
         if (isset($arRaw['connection time'])) {
             $arRaw['connection time'] = str_replace(
                 array(
@@ -188,10 +200,12 @@ class Wrt3g_HtmlParser
                 'TX = ',
                 str_replace('RX = ', '', $arRaw['session usage'])
             );
-            $arRaw['session usage'] = array(
-                'received' => $arS[0],
-                'sent'     => $arS[1]
-            );
+            if (count($arS) > 1) {
+                $arRaw['session usage'] = array(
+                    'received' => $arS[0],
+                    'sent'     => $arS[1]
+                );
+            }
         }
 
         return $arRaw;
diff --git a/tests/status_noauth-aquiring.phpt b/tests/status_noauth-aquiring.phpt
new file mode 100644 (file)
index 0000000..8c6c5d4
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+test Wrt3g_HtmlParser::status_noauth() when we have no conection
+--FILE--
+<?php
+chdir(dirname(__FILE__));
+require_once dirname(__FILE__) . '/../Wrt3g/HtmlParser.php';
+$p = new Wrt3g_HtmlParser();
+var_dump(
+    $p->status_noauth(
+        file_get_contents('status_noauth-aquiring.htm')
+    )
+);
+--EXPECT--
+array(10) {
+  ["connection"]=>
+  string(10) "connecting"
+  ["type"]=>
+  NULL
+  ["network"]=>
+  NULL
+  ["signal strength"]=>
+  NULL
+  ["connection time"]=>
+  NULL
+  ["session usage"]=>
+  NULL
+  ["card model"]=>
+  string(29) "GlobeTrotter Fusion Quad Lite"
+  ["card revision"]=>
+  string(3) "4.1"
+  ["card firmware"]=>
+  string(42) "1.5.5  (Date: May 17 2005, Time: 14:55:44)"
+  ["IMSI"]=>
+  string(15) "262032010984707"
+}
\ No newline at end of file