function WeatherParserTestCase::testNormalMETAR in Weather 6.5
Same name and namespace in other branches
- 7 tests/parser.test \WeatherParserTestCase::testNormalMETAR()
Test the parser with normal data.
File
- tests/
parser.test, line 48
Class
Code
function testNormalMETAR() {
// This user is allowed to access the weather pages
$user = $this
->drupalCreateUser(array(
'access content',
'access weather pages',
));
$this
->drupalLogin($user);
$data = array(
'EDDH' => array(
'raw' => "2008/12/07 12:50\nEDDH 071250Z 27005KT 9999 -SHRA BKN025 07/04 Q1021 NOSIG",
'expected' => array(
"Hamburg-Fuhlsbüttel",
"Broken clouds, light rain showers",
"Temperature: 7 °C",
"Wind: West, 9.3 km/h",
"Pressure: 1021 hPa",
"Rel. Humidity: 81 %",
"Visibility: 10 km",
),
),
'EDDH' => array(
'raw' => "2008/11/29 11:20\nEDDH 291120Z 15004KT 1200 R23/1600N R15/1500N SN VV/// 01/M00 Q0995 NOSIG",
'expected' => array(
"Hamburg-Fuhlsbüttel",
"Overcast, snow",
"Temperature: 1 °C",
"Wind: South-Southeast, 7.4 km/h",
"Pressure: 995 hPa",
"Rel. Humidity: 93 %",
"Visibility: 1.2 km",
),
),
'LICF' => array(
'raw' => "2008/12/04 02:55\nLICF 040255Z 02014G31KT 6000 RA BKN008 BKN080 OVC090 12/11 Q0994 RMK OVC QUK / QUL / VIS MAR 6 KM MON INVIS NC VIS MIN 6000",
'expected' => array(
"Messina",
"Overcast, rain",
"Temperature: 12 °C",
"Wind: North-Northeast, 25.9 km/h, gusts up to 57.4 km/h",
"Pressure: 994 hPa",
"Rel. Humidity: 94 %",
"Visibility: 6 km",
),
),
'CYYZ' => array(
'raw' => "2008/12/07 14:00\nCYYZ 071400Z 31026G33KT 15SM FEW030 FEW120 FEW210 M09/M15 A2984 RMK CU2AC1CI1 CI TR SLP114",
'expected' => array(
"Toronto Pearson Int'l. Ont.",
"Few clouds",
"Temperature: -9 °C",
"Wind: Northwest, 48.2 km/h, gusts up to 61.1 km/h",
"Pressure: 1010 hPa",
"Rel. Humidity: 62 %",
"Visibility: 24.1 km",
),
),
'FACT' => array(
'raw' => "2008/12/07 14:00\nFACT 071400Z 20016KT CAVOK 24/17 Q1013 NOSIG",
'expected' => array(
"Cape Town, Cape Town International Airport",
"Clear sky",
"Temperature: 24 °C",
"Wind: South-Southwest, 29.6 km/h",
"Pressure: 1013 hPa",
"Rel. Humidity: 65 %",
"Visibility: 10 km",
),
),
'ULLI' => array(
'raw' => "2008/12/22 19:30\nULLI 221930Z 14006MPS 9999 OVC006 DZ M03/M04 Q0997 10520545 NOSIG RMK OBST OBSC",
'expected' => array(
"St. Peterburg",
"Overcast, drizzle",
"Temperature: -3 °C",
"Wind: Southeast, 21.6 km/h",
"Pressure: 997 hPa",
"Rel. Humidity: 93 %",
"Visibility: 10 km",
),
),
'EGPL' => array(
'raw' => "2008/12/22 20:20\nEGPL 222020Z AUTO 21012KT 7000NDV FEW006/// SCT010/// BKN014/// 09/08 Q1026",
'expected' => array(
"Benbecula",
"Broken clouds",
"Temperature: 9 °C",
"Wind: South-Southwest, 22.2 km/h",
"Pressure: 1026 hPa",
"Rel. Humidity: 93 %",
"Visibility: 7 km",
),
),
'EGUB' => array(
'raw' => "2008/12/22 19:50\nEGUB 221950Z AUTO 18003KT 5000NDV BR OVC013/// 10/09 Q1035",
'expected' => array(
"Benson",
"Overcast, mist",
"Temperature: 10 °C",
"Wind: South, 5.6 km/h",
"Pressure: 1035 hPa",
"Rel. Humidity: 94 %",
"Visibility: 5 km",
),
),
'EPGD' => array(
'raw' => "2010/01/30 20:30\nEPGD 302030Z 27013KT 9999 -SHSN BKN013 M02/M04 Q0984 R11/490236",
'expected' => array(
"Gdańsk-Rębiechowo",
"Broken clouds, light snow showers",
"Temperature: -2 °C",
"Wind: West, 24.1 km/h",
"Pressure: 984 hPa",
"Rel. Humidity: 86 %",
"Visibility: 10 km",
),
),
);
// Disable updates by using five minutes in the future
$next_update_on = time() + 300;
foreach ($data as $icao => $metar) {
$res = db_query("DELETE FROM {weather} WHERE icao = '%s'", $icao);
$this
->assertTrue($res);
$res = db_query("INSERT INTO {weather} (icao, next_update_on, metar_raw)\n VALUES ('%s', %d, '%s')", $icao, $next_update_on, $metar['raw']);
$this
->assertTrue($res);
$this
->drupalGet('weather/' . $icao);
foreach ($metar['expected'] as $text) {
$this
->assertText($text);
}
$res = db_query("DELETE FROM {weather} WHERE icao = '%s'", $icao);
$this
->assertTrue($res);
}
$this
->drupalLogout();
}