You are here

function CountriesCRUDUnitTest::testCountriesCRUD in Countries 8

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

This test that the country property lookup is working.

File

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

Class

CountriesCRUDUnitTest
Test the node_load_multiple() function.

Code

function testCountriesCRUD() {

  // Try creating a new country that matches an existing one.
  $country = country_create(array(
    'iso2' => 'aF',
    'name' => 'A test (XA)',
  ));
  if (country_validate($country)) {
    $this
      ->fail('Validation missed overriding an existing country.');
  }
  $country->iso2 = 'Xa';
  if (country_validate($country)) {
    $type = country_save($country);
    if ($type != SAVED_NEW) {
      $this
        ->fail('Save failed.');
    }
  }
  else {
    $this
      ->fail('Validation failed on valid new country.');
  }
  $new = country_load('XA');
  if ($this
    ->assertTrue($new !== FALSE, 'Found and loaded new country')) {
    $this
      ->assertEqual($new->name, 'A test (XA)', 'Name saved correctly');
    $this
      ->assertEqual($new->official_name, '', 'Official name saved correctly');
    $this
      ->assertEqual($new->iso3, '', 'ISO alpha-3 saved correctly');
    $this
      ->assertEqual($new->numcode, 0, 'ISO numeric-3 saved correctly');
    $this
      ->assertEqual($new->continent, 'UN', 'Continent saved correctly');
    $this
      ->assertEqual($new->enabled, 1, 'Country is enabled');
  }
  if ($new) {
    $new->name = 'A test';
    $new->official_name = 'A test (XA)';
    if (country_validate($new)) {
      if (country_save($new) != SAVED_UPDATED) {
        $this
          ->fail('country_save() failed on valid country update.');
      }
      else {
        $new = country_load('XA');
        if ($new->official_name != 'A test (XA)' || $new->name != 'A test') {
          $this
            ->fail('Country update failed.');
        }
        else {
          $this
            ->pass('Country update successful.');
        }
      }
    }
    else {
      $this
        ->fail('Validation failed on valid country update.');
    }
  }
  if ($new = country_load('XA')) {
    if (country_delete('XA') === FALSE) {
      $this
        ->fail('Country deletion likely failed.');
    }
  }
  $deleted = country_load('XA');
  if ($deleted) {
    $this
      ->fail('Country deletion failed.');
  }
  else {
    $this
      ->pass('Country deletion successful.');
  }
}