View source
<?php
define('VALID_ISO2', 'US');
define('VALID_ISO3', 'USA');
define('INVALID_ISO2', 'xx');
define('INVALID_ISO3', 'xxx');
define('VALID_FORMAT', 'iso2');
define('INVALID_FORMAT', 'oh hai!');
class CountriesApiTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Countries API tests'),
'desc' => t('Tests countries api functions'),
'group' => t('countries_api tests'),
);
}
function test_countries_api_get_formats() {
$formats = countries_api_get_formats();
$this
->assertNotNull($formats, 'Checking countries API format results. %s');
}
function test_countries_api_get_list() {
$countries = countries_api_get_list();
$this
->assertTrue(is_array($countries), 'Checking countries api list. %s');
}
function test_count_countries_api_get_list() {
$countries = countries_api_get_list();
$this
->assertNotEqual(count($countries), 0, 'Checking size of countries api. %s');
}
function test_results_countries_api_iso_get_country() {
$value = VALID_ISO2;
$format = VALID_FORMAT;
$country = _countries_api_iso_get_country($value, $format);
$this
->assertTrue($country, 'Testing countries_api_iso_get_country return format. %s');
}
function test_invalidformat__countries_api_iso_get_country() {
$value = VALID_ISO2;
$format = INVALID_FORMAT;
$country = _countries_api_iso_get_country($value, $format);
$this
->assertFalse($country, 'Testing countries_api_iso_get_country format validation. %s');
}
function test_countries_api_iso3_get_iso2() {
$code = VALID_ISO3;
$iso2 = countries_api_iso3_get_iso2($code);
$this
->assertNotEqual($iso2, false, 'Test countries_api_iso3_get_iso2 results. %s');
}
function test_countries_api_iso2_get_iso3() {
$code = VALID_ISO2;
$iso3 = countries_api_iso2_get_iso3($code);
$this
->assertNotEqual($iso3, false, 'Test countries_api_iso2_get_iso3 results. %s');
}
function test_countries_api_iso3_get_name() {
$code = VALID_ISO3;
$country_name = countries_api_iso3_get_name($code);
$this
->assertNotNull($country_name, 'Test countries_api_iso3_get_name results. %s');
}
function test_nullcountries_api_iso3_get_name() {
$code = INVALID_ISO3;
$country_name = countries_api_iso3_get_name($code);
$this
->assertNull($country_name, 'Tests countries_api_iso3_get_name with an incorrect code. %s');
}
function test_countries_api_iso2_get_name() {
$code = VALID_ISO2;
$country_name = countries_api_iso2_get_name($code);
$this
->assertNotNull($country_name, 'Test countries_api_iso2_get_name results. %s');
}
function test_nullcountries_api_iso2_get_name() {
$code = INVALID_ISO3;
$country_name = countries_api_iso2_get_name($code);
$this
->assertNull($country_name, 'Tests countries_api_iso2_get_name with an incorrect code. %s');
}
function test_countries_api_get_name() {
$name = VALID_ISO2;
$country_name = countries_api_get_name($name);
$this
->assertNotNull($country_name, 'Test test_countries_api_get_name results. %s');
}
function test_invalid_countries_api_get_name() {
$name = INVALID_ISO2;
$country_name = countries_api_get_name($name);
$this
->assertNull($country_name, 'Test test_countries_api_get_name results. %s');
}
function test_countries_api_get_array() {
$countries = countries_api_get_array();
$this
->assertNotEqual($countries, false, 'Test results of countries_api_get_array.');
}
function test_countries_api_get_options_array() {
$countries = countries_api_get_options_array();
$this
->assertNotNull($countries, 'Test countries_api_get_options_array.');
}
}