You are here

public function ParserTest::testDifferentDaysOfForecasts in Weather 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/ParserTest.php \Drupal\Tests\weather\Functional\ParserTest::testDifferentDaysOfForecasts()

Test the parser with different days of forecast data.

File

tests/src/Functional/ParserTest.php, line 530

Class

ParserTest
Tests parsing of XML weather forecasts.

Namespace

Drupal\Tests\weather\Functional

Code

public function testDifferentDaysOfForecasts() {

  // These are all days from the forecast.
  $days = [
    '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.
  $config = \Drupal::configFactory()
    ->getEditable('weather.settings');
  $config
    ->set('weather_time_for_testing', 1381176000)
    ->save();

  // Fetch all weather forecasts for Hamburg
  // and check the correct days of forecasts.
  $weather = $this
    ->weatherGetWeather('geonames_2911298', 0, TRUE);
  $this
    ->assertSame(array_keys($weather['forecasts']), $days);

  // Go a few days forward ...
  // Set a fixed time for testing to 2013-10-12 10:00:00 UTC.
  $config = \Drupal::configFactory()
    ->getEditable('weather.settings');
  $config
    ->set('weather_time_for_testing', 1381572000)
    ->save();

  // Fetch all weather forecasts for Hamburg
  // and check the correct days of forecasts.
  $weather = $this
    ->weatherGetWeather('geonames_2911298', 0, TRUE);
  $this
    ->assertSame(array_keys($weather['forecasts']), array_slice($days, 5));
}