function CountriesFunctionsUnitTest::testCountriesPropertyLookup in Countries 8
Same name and namespace in other branches
- 7.2 tests/countries.test \CountriesFunctionsUnitTest::testCountriesPropertyLookup()
This test that the country property lookup is working.
File
- tests/
countries.test, line 445 - Tests for countries.module.
Class
- CountriesFunctionsUnitTest
- Test the general functions provided by the module.
Code
function testCountriesPropertyLookup() {
// Defaults, all empty.
$country = country_create();
$results = array(
'cid' => NULL,
'iso2' => '',
'iso3' => '',
'name' => '',
'official_name' => '',
'continent' => t('Unknown'),
'continent_code' => 'UN',
'enabled' => t('Enabled'),
'numcode' => '',
);
$passed_all = TRUE;
foreach ($results as $key => $expected_results) {
$results = country_property($country, $key, array(
'sanitize' => 0,
));
if ($results !== $expected_results) {
$this
->fail('Country property failed on ' . $key . '. Found ' . $results . ', expected ' . $expected_results);
$passed_all = FALSE;
}
}
if ($passed_all) {
$this
->pass('Country property lookup on default properties passed.');
}
// Defaults, all empty.
unset($country->continent);
unset($country->enabled);
$results = array(
'cid' => NULL,
'iso2' => 'xxx',
'iso3' => 'xxx',
'name' => 'xxx',
'official_name' => 'xxx',
'continent' => 'xxx',
'continent_code' => 'xxx',
'enabled' => t('Disabled'),
'numcode' => 'xxx',
);
$passed_all = TRUE;
foreach ($results as $key => $expected_results) {
$actual_results = country_property($country, $key, array(
'sanitize' => 0,
'default' => 'xxx',
));
if ($actual_results !== $expected_results) {
$this
->fail('Country property using default failed on ' . $key . '. Found ' . $actual_results . ', expected ' . $expected_results);
$passed_all = FALSE;
}
}
if ($passed_all) {
$this
->pass('Country property lookup on default properties using fallback default all passed.');
}
// A test with as many nasties as the system allows via the UI.
$country = country_create(array(
'cid' => 9999,
'iso2' => 'XZ',
'iso3' => 'AAA',
'name' => '<a>&Test</a>',
'official_name' => '<a>&Test official</a>',
'continent' => 'NA',
'enabled' => 0,
'numcode' => '1',
));
$results = array(
'cid' => '9999',
'iso2' => 'XZ',
'iso3' => 'AAA',
'name' => '<a>&Test</a>',
'official_name' => '<a>&Test official</a>',
'continent' => t('North America'),
'continent_code' => 'NA',
'enabled' => t('Disabled'),
'numcode' => '001',
);
$passed_all = TRUE;
foreach ($results as $key => $expected_results) {
$results = (string) country_property($country, $key, array(
'sanitize' => 1,
));
if ($results !== check_plain($expected_results)) {
$this
->fail('Country property failed on ' . $key . '. Found ' . $results . ', expected ' . $expected_results);
$passed_all = FALSE;
}
$results = (string) country_property($country, $key, array(
'sanitize' => 1,
'default' => 'xxx',
));
if ($results !== check_plain($expected_results)) {
$this
->fail('Country property using default failed on ' . $key . '. Found ' . $results . ', expected ' . $expected_results);
$passed_all = FALSE;
}
$results = (string) country_property($country, $key, array(
'sanitize' => 0,
));
if ($results !== $expected_results) {
$this
->fail('Country property failed on unsanitised results ' . $key . '. Found ' . check_plain($results) . ', expected ' . check_plain($expected_results));
$passed_all = FALSE;
}
$results = (string) country_property($country, $key, array(
'sanitize' => 0,
'default' => 'xxx',
));
if ($results !== $expected_results) {
$this
->fail('Country property failed on unsanitised results using default value ' . $key . '. Found ' . check_plain($results) . ', expected ' . check_plain($expected_results));
$passed_all = FALSE;
}
}
if ($passed_all) {
$this
->pass('Country property lookup on populated country passed.');
}
}