You are here

functions.test in Weather 7.2

Same filename and directory in other branches
  1. 7.3 tests/functions.test

Tests functions of weather.module.

Copyright © 2006-2015 Dr. Tobias Quathamer <t.quathamer@mailbox.org>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

File

tests/functions.test
View source
<?php

/**
 * @file
 * Tests functions of weather.module.
 *
 * Copyright © 2006-2015 Dr. Tobias Quathamer <t.quathamer@mailbox.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * Test class for functions.
 */
class WeatherFunctionsTestCase extends DrupalWebTestCase {

  /**
   * General information.
   */
  public static function getInfo() {
    return array(
      'name' => 'Functions',
      'description' => 'Tests functions of weather.module.',
      'group' => 'Weather',
    );
  }

  /**
   * Set up testing environment.
   */
  public function setUp() {
    parent::setUp('weather');
    module_load_include('inc', 'weather', 'weather.common');
  }

  /**
   * Test _weather_get_link_for_geoid().
   */
  public function testFunction_weather_get_link_for_geoid() {

    // Test different numbers for system-wide displays.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'system-wide');
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla/1');
    $link = _weather_get_link_for_geoid('geonames_2596934', 'system-wide', 1);
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla/1');
    $link = _weather_get_link_for_geoid('geonames_2596934', 'system-wide', 7);
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla/7');

    // Test different numbers for default displays.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'default');
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla');
    $link = _weather_get_link_for_geoid('geonames_2596934', 'default', 5);
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla');

    // Test different numbers for user displays.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'user');
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla/u');
    $link = _weather_get_link_for_geoid('geonames_2596934', 'user', 3);
    $this
      ->assertEqual($link, 'weather/Côte_d’Ivoire/Worodougou/Séguéla/u');

    // Test different numbers for yr links.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'yr');
    $this
      ->assertEqual($link, 'http://www.yr.no/place/C%C3%B4te_d%E2%80%99Ivoire/Worodougou/S%C3%A9gu%C3%A9la/forecast.xml');
    $link = _weather_get_link_for_geoid('geonames_2596934', 'yr', 8);
    $this
      ->assertEqual($link, 'http://www.yr.no/place/C%C3%B4te_d%E2%80%99Ivoire/Worodougou/S%C3%A9gu%C3%A9la/forecast.xml');

    // Test different numbers for yr.no links.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'yr.no');
    $this
      ->assertEqual($link, 'http://www.yr.no/place/Côte_d’Ivoire/Worodougou/Séguéla/');
    $link = _weather_get_link_for_geoid('geonames_2596934', 'yr.no', 8);
    $this
      ->assertEqual($link, 'http://www.yr.no/place/Côte_d’Ivoire/Worodougou/Séguéla/');

    // Test autocomplete link.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'autocomplete');
    $this
      ->assertEqual($link, 'Côte_d’Ivoire/Worodougou/Séguéla');

    // Test undefined link keyword, should return the bare link.
    $link = _weather_get_link_for_geoid('geonames_2596934', 'no known keyword');
    $this
      ->assertEqual($link, 'Côte_d’Ivoire/Worodougou/Séguéla');

    // Test some special case geoids.
    $link = _weather_get_link_for_geoid('geonames_2979036', 'system-wide');
    $this
      ->assertEqual($link, 'weather/France/Limousin/Saint-Junien~2979036/1');
    $link = _weather_get_link_for_geoid('geonames_4795467', 'system-wide');
    $this
      ->assertEqual($link, 'weather/Virgin_Islands,_U.S_/Saint_Thomas_Island/Charlotte_Amalie/1');
  }

}

Classes

Namesort descending Description
WeatherFunctionsTestCase Test class for functions.