From 85f7ff92a4c5ef908fe063d9e88028dc239ff0dd Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 17 Dec 2010 09:01:37 +0100 Subject: [PATCH] test for noauth status page without connection; add support for connection status in status_noauth --- Wrt3g/HtmlParser.php | 28 ++++++++++++++++++------- tests/status_noauth-aquiring.phpt | 35 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 tests/status_noauth-aquiring.phpt diff --git a/Wrt3g/HtmlParser.php b/Wrt3g/HtmlParser.php index d420f4d..f369bd1 100644 --- a/Wrt3g/HtmlParser.php +++ b/Wrt3g/HtmlParser.php @@ -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 index 0000000..8c6c5d4 --- /dev/null +++ b/tests/status_noauth-aquiring.phpt @@ -0,0 +1,35 @@ +--TEST-- +test Wrt3g_HtmlParser::status_noauth() when we have no conection +--FILE-- +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 -- 2.30.2