You are here

class CountriesCRUDUnitTest in Countries 8

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

Test the node_load_multiple() function.

Hierarchy

Expanded class hierarchy of CountriesCRUDUnitTest

File

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

View source
class CountriesCRUDUnitTest extends CountriesBaseSetupTest {
  public static function getInfo() {
    return array(
      'name' => 'Country CRUD functions',
      'description' => 'Test the country creation, editting, deletion programmatically.',
      'group' => 'Countries',
    );
  }
  function setUp() {
    parent::setUp();
    $this
      ->drupalLogin($this->admin_user);
  }

  /**
   * This test that the country property lookup is working.
   */
  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.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CountriesBaseSetupTest::assertCountryListed function
CountriesBaseSetupTest::assertListingLink function
CountriesBaseSetupTest::assertNoOptionPresent function
CountriesBaseSetupTest::assertOptionPresent function
CountriesBaseSetupTest::getDisabledCountries function Provides a sample group of countries defined by core that match the ISO Standards.
CountriesBaseSetupTest::getNewCountries function These countries are not part of core.
CountriesBaseSetupTest::getNonStandardCountries function These are the invalid strings in core.
CountriesBaseSetupTest::getNonStandardCountriesCorrected function The valid list if ISO strings
CountriesBaseSetupTest::getUnchangedCountries function Provides a sample group of countries defined by core that match the ISO Standards.
CountriesCRUDUnitTest::getInfo public static function
CountriesCRUDUnitTest::setUp function Overrides CountriesBaseSetupTest::setUp
CountriesCRUDUnitTest::testCountriesCRUD function This test that the country property lookup is working.