public function WeatherParserTestCase::testDifferentDaysOfForecasts in Weather 7.3
Same name and namespace in other branches
- 7.2 tests/parser.test \WeatherParserTestCase::testDifferentDaysOfForecasts()
Test the parser with different days of forecast data.
File
- tests/
parser.test, line 101 - Tests parsing of XML weather forecasts.
Class
- WeatherParserTestCase
- Test class for the parser.
Code
public function testDifferentDaysOfForecasts() {
// These are all days from the forecast.
$days = array(
'2013-10-07',
'2013-10-08',
'2013-10-09',
'2013-10-10',
'2013-10-11',
'2013-10-12',
'2013-10-13',
'2013-10-14',
'2013-10-15',
'2013-10-16',
'2013-10-17',
);
// Set a fixed time for testing to 2013-10-07 20:00:00 UTC.
variable_set('weather_time_for_testing', 1381176000);
// Fetch all weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 0, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), $days);
// Fetch all (= 11) weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 11, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), $days);
// Fetch more than available weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 12, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), $days);
// Fetch 6 weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 6, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), array_slice($days, 0, 6));
// Fetch 2 weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 2, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), array_slice($days, 0, 2));
// Fetch 1 weather forecast for Hamburg
// and check the correct day of forecasts.
$weather = weather_get_weather('geonames_2911298', 1, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), array_slice($days, 0, 1));
// Go a few days forward ...
// Set a fixed time for testing to 2013-10-12 10:00:00 UTC.
variable_set('weather_time_for_testing', 1381572000);
// Fetch all weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 0, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), array_slice($days, 5));
// Fetch all weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 12, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), array_slice($days, 5));
// Fetch 2 weather forecasts for Hamburg
// and check the correct days of forecasts.
$weather = weather_get_weather('geonames_2911298', 2, TRUE);
$this
->assertIdentical(array_keys($weather['forecasts']), array_slice($days, 5, 2));
}