You are here

function CountriesFunctionsUnitTest::testCountriesLock in Countries 8

Same name and namespace in other branches
  1. 7.2 tests/countries.test \CountriesFunctionsUnitTest::testCountriesLock()

This test that core countries can not be deleted while user ones are.

File

tests/countries.test, line 384
Tests for countries.module.

Class

CountriesFunctionsUnitTest
Test the general functions provided by the module.

Code

function testCountriesLock() {

  // Already have tested the lock above on the listing page.
  $af = country_load('af');
  $this
    ->assertTrue(country_is_locked($af), 'Country is detected as locked');
  $this
    ->drupalGet('admin/config/regional/countries/af/delete');
  $this
    ->assertText(t('Core countries defined by the system can not be deleted.'), 'Checking that delete is disable for core country.');
  $new = country_create(array(
    'iso2' => 'XA',
    'name' => 'A test XA',
    'official_name' => 'A test XA official name',
  ));
  if (country_validate($new)) {
    country_save($new);
  }
  else {
    $this
      ->error('Error saving new country');
  }
  $new = country_load('xa');
  $this
    ->assertFALSE(country_is_locked($new), 'User country is not locked');

  // Will be listed on page 1
  $this
    ->drupalGet('admin/config/regional/countries');
  $this
    ->assertListingLink($new, 'delete', 1);

  // Check the delete page
  $this
    ->drupalGet('admin/config/regional/countries/XA/delete');
  $this
    ->assertRaw(t('Are you sure you want to delete the country %country?', array(
    '%country' => $new->name,
  )));
  $this
    ->drupalPost('admin/config/regional/countries/XA/delete', array(), t('Delete'));
  $this
    ->assertRaw(t('Deleted country %country.', array(
    '%country' => $new->name,
  )));
  $this
    ->assertNoText($new->official_name, 'Delete link appear for core countries.');
}