You are here

class CountriesCacheUnitTest in Countries 8

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

Test the cache is not breaking core functionality.

Hierarchy

Expanded class hierarchy of CountriesCacheUnitTest

File

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

View source
class CountriesCacheUnitTest extends CountriesBaseSetupTest {
  public static function getInfo() {
    return array(
      'name' => 'Country cache',
      'description' => 'Test the cache is behaving.',
      'group' => 'Countries',
    );
  }
  function setUp() {
    parent::setUp();
    $this
      ->drupalLogin($this->admin_user);
  }
  function testCache() {

    // Test the CSV import data.
    $countries = countries_get_countries('all', array(), array(
      'sanitize' => FALSE,
    ));
    $this
      ->assertEqual($countries['US']->name, 'United States');

    // A direct database query should show after caches are reset.
    db_update('countries_country')
      ->fields(array(
      'name' => 'United States America',
    ))
      ->condition('iso2', 'US')
      ->execute();
    countries_clear_caches();
    $countries = countries_get_countries('all', array(), array(
      'sanitize' => FALSE,
    ));
    $this
      ->assertEqual($countries['US']->name, 'United States America');

    // Test a save via the UI.
    $this
      ->drupalPost('admin/config/regional/countries/us', array(
      'name' => 'United States',
    ), t('Save'));

    // Clear the SimpleTest caches too.
    countries_clear_caches();
    $countries = countries_get_countries('all', array(), array(
      'sanitize' => FALSE,
    ));
    $this
      ->assertEqual($countries['US']->name, 'United States');

    // Tests the internal CRUD save action.
    $us = country_load('us');
    $this
      ->assertEqual($us->name, 'United States');
    $us->name = 'United States America';
    country_save($us);
    $countries = countries_get_countries('all', array(), array(
      'sanitize' => FALSE,
    ));
    $this
      ->assertEqual($countries['US']->name, 'United States America');

    // Test a missing country to ensure the import doesn't include it.
    if (isset($countries['XA'])) {
      $this
        ->fail('Test non-existent country XA exists.');
      return;
    }

    // Create, save and delete tests should all result in cache updates.
    $xa = country_create(array(
      'iso2' => 'xa',
      'name' => 'Test',
    ));
    if (country_validate($xa)) {
      country_save($xa);
    }
    else {
      $this
        ->error('Error saving new country');
    }
    $countries = countries_get_countries('all', array(), array(
      'sanitize' => FALSE,
    ));
    $this
      ->assertEqual($countries['XA']->name, 'Test');
    country_delete('xa');
    $countries = countries_get_countries('all', array(), array(
      'sanitize' => FALSE,
    ));
    if (isset($countries['XA'])) {
      $this
        ->fail('Test deletion failed.');
    }
  }

}

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.
CountriesCacheUnitTest::getInfo public static function
CountriesCacheUnitTest::setUp function Overrides CountriesBaseSetupTest::setUp
CountriesCacheUnitTest::testCache function