function CountriesBaseImportUnitTest::testCountriesCoreListingImport in Countries 7.2
Tests the import routines.
File
- tests/
countries.test, line 322 - Tests for countries.module.
Class
Code
function testCountriesCoreListingImport() {
// Parse and compare the default listings as returned by Drupal.
$unchanged_countries = $this
->getUnchangedCountries();
// Stale core countries
$changed_countries_originals = $this
->getNonStandardCountries();
// Updated core countries to the iso standards.
$changed_countries = $this
->getNonStandardCountriesCorrected();
// Visit update page and update the countries.
// Update Aland Islands to Åland Islands
$updated_countries = array(
'AX',
);
$edit = array(
"updates[AX-name]" => TRUE,
'updates[AN-enabled]' => FALSE,
);
foreach ($changed_countries as $iso2 => $name) {
if (in_array($iso2, $updated_countries)) {
continue;
}
$edit["updates[{$iso2}-name]"] = FALSE;
}
$this
->drupalPost('admin/config/regional/countries/import', $edit, t('Import'));
$this
->assertText(t('The updated countries were: ' . $changed_countries['AX']), 'Successful save message displayed.');
countries_clear_caches();
// Check the listings (it is on the first page).
$this
->drupalGet('admin/config/regional/countries');
$country = country_create(array(
'iso2' => 'AX',
'name' => 'Åland Islands',
));
$this
->assertListingLink($country, 'title');
// Now test that our updates are appearing.
countries_clear_caches();
$countries = country_get_list();
if ($this
->assertNotNull($countries['AX'], 'Testing updated Aland Islands exists')) {
$this
->assertEqual('Åland Islands', $countries['AX'], 'Testing updated Aland Islands renamed to Åland Islands');
}
// Test the only other standard property, AN disabled.
$this
->assertNotNull($countries['AN'], 'Testing soon to be disabled Netherlands Antilles is in the country_get_list()');
$edit = array(
"updates[AN-enabled]" => TRUE,
);
$updated_countries[] = 'AN';
foreach ($changed_countries as $iso2 => $name) {
if (in_array($iso2, $updated_countries)) {
continue;
}
$edit["updates[{$iso2}-name]"] = FALSE;
}
$this
->drupalPost('admin/config/regional/countries/import', $edit, t('Import'));
$this
->assertText(t('The updated countries were: Netherlands Antilles'), 'Successful save message displayed.');
// Check the listings (it is on the first page).
$this
->drupalGet('admin/config/regional/countries', array(
'query' => array(
'page' => '3',
),
));
$this
->assertRaw("<td id=\"AN-enabled\">Disabled</td>", 'Testing Netherlands Antilles is disabled');
// Now test that our updates are appearing.
countries_clear_caches();
$countries = country_get_list();
$this
->assertTrue(empty($countries['AN']), 'Testing disabled Netherlands Antilles not in country_get_list()');
// Import the rest.
unset($changed_countries['AX']);
$edit = array();
foreach ($changed_countries as $iso => $name) {
if (in_array($iso, $updated_countries)) {
continue;
}
$edit["updates[{$iso}-name]"] = TRUE;
}
$this
->drupalPost('admin/config/regional/countries/import', $edit, t('Import'));
countries_clear_caches();
$countries = country_get_list();
foreach ($this
->getNonStandardCountriesCorrected() as $iso2 => $name) {
if ($this
->assertNotNull($countries[$iso2], "Testing updated country {$name} exists")) {
$this
->assertEqual($name, $countries[$iso2], "Testing updated country name is changed {$name}");
}
}
// Check that there are no more countries to import.
$this
->drupalGet('admin/config/regional/countries/import');
$this
->assertNoText(t('Import'), 'Import completed');
}