You are here

class CountriesBaseSetupTest in Countries 8

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

Test the node_load_multiple() function.

Hierarchy

Expanded class hierarchy of CountriesBaseSetupTest

File

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

View source
class CountriesBaseSetupTest extends DrupalWebTestCase {
  function setUp() {
    $modules = func_get_args();
    if (isset($modules[0]) && is_array($modules[0])) {
      $modules = $modules[0];
    }
    if (empty($modules)) {
      $modules = array(
        'countries',
      );
    }
    parent::setUp($modules);

    // Create admin user and log in admin user.
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer site configuration',
    ));
    include_once DRUPAL_ROOT . '/includes/locale.inc';
    include_once DRUPAL_ROOT . '/includes/iso.inc';
  }
  function assertOptionPresent($id, $option, $message = NULL) {
    $elements = $this
      ->xpath("//select[@id=:id]//option[@value=:option]", array(
      ':id' => $id,
      ':option' => $option,
    ));
    return $this
      ->assertTrue(isset($elements[0]), $message ? $message : t('Option @option for field @id is present.', array(
      '@option' => $option,
      '@id' => $id,
    )), t('Browser'));
  }
  function assertNoOptionPresent($id, $option, $message = NULL) {
    $elements = $this
      ->xpath("//select[@id=:id]//option[@value=:option]", array(
      ':id' => $id,
      ':option' => $option,
    ));
    return $this
      ->assertTrue(empty($elements), $message ? $message : t('Option @option for field @id is not present.', array(
      '@option' => $option,
      '@id' => $id,
    )), t('Browser'));
  }

  /**
   * Provides a sample group of countries defined by core that match the ISO
   * Standards.
   */
  function getUnchangedCountries() {
    return array(
      'AD' => t('Andorra'),
      'AF' => t('Afghanistan'),
      'ZW' => t('Zimbabwe'),
    );
  }

  /**
   * Provides a sample group of countries defined by core that match the ISO
   * Standards.
   */
  function getDisabledCountries() {
    return array(
      'AN' => t('Netherlands Antilles'),
    );
  }

  /**
   * These countries are not part of core.
   */
  function getNewCountries() {
    return array(
      'BQ' => t('Bonaire, Sint Eustatius and Saba'),
      'SS' => t('South Sudan'),
      'SX' => t('Sint Maarten (Dutch part)'),
    );
  }

  /**
   * These are the invalid strings in core.
   */
  function getNonStandardCountries() {
    return array(
      'AX' => t('Aland Islands'),
      'BN' => t('Brunei'),
      'BO' => t('Bolivia'),
      'CD' => t('Congo (Kinshasa)'),
      'CG' => t('Congo (Brazzaville)'),
      'CI' => t('Ivory Coast'),
      'FK' => t('Falkland Islands'),
      'FM' => t('Micronesia'),
      'IR' => t('Iran'),
      'KP' => t('North Korea'),
      'KR' => t('South Korea'),
      'LA' => t('Laos'),
      'MD' => t('Moldova'),
      'MK' => t('Macedonia'),
      'MO' => t('Macao S.A.R., China'),
      'PS' => t('Palestinian Territory'),
      'RE' => t('Reunion'),
      'RU' => t('Russia'),
      'SH' => t('Saint Helena'),
      'TW' => t('Taiwan'),
      'TZ' => t('Tanzania'),
      'VA' => t('Vatican'),
      'VE' => t('Venezuela'),
      'VG' => t('British Virgin Islands'),
      'VI' => t('U.S. Virgin Islands'),
      'VN' => t('Vietnam'),
    );
  }

  /**
   * The valid list if ISO strings
   */
  function getNonStandardCountriesCorrected() {
    return array(
      'AX' => t('Åland Islands'),
      'BN' => t('Brunei Darussalam'),
      'BO' => t('Bolivia, Plurinational State of'),
      'CD' => t('Congo, The Democratic Republic of the'),
      'CG' => t('Congo'),
      'CI' => t("Côte d'Ivoire"),
      'FK' => t('Falkland Islands (Malvinas)'),
      'FM' => t('Micronesia, Federated States of'),
      'HK' => t('Hong Kong'),
      'IR' => t('Iran, Islamic Republic of'),
      'KP' => t("Korea, Democratic People's Republic of"),
      'KR' => t('Korea, Republic of'),
      'LA' => t("Lao People's Democratic Republic"),
      'MD' => t('Moldova, Republic of'),
      'MK' => t('Macedonia, The Former Yugoslav Republic of'),
      'MO' => t('Macao'),
      'PS' => t('Palestine, State of'),
      'RE' => t('Réunion'),
      'RU' => t('Russian Federation'),
      'SH' => t('Saint Helena, Ascension and Tristan da Cunha'),
      'ST' => t('São Tomé and Príncipe'),
      'SY' => t('Syrian Arab Republic'),
      'TW' => t('Taiwan, Province of China'),
      'TZ' => t('Tanzania, United Republic of'),
      'VA' => t('Holy See (Vatican City State)'),
      'VE' => t('Venezuela, Bolivarian Republic of'),
      'VG' => t('Virgin Islands, British'),
      'VI' => t('Virgin Islands, U.S.'),
      'VN' => t('Viet Nam'),
    );
  }
  function assertListingLink($country, $type, $assertTrue = TRUE, $message = NULL, $query = array()) {
    if (!isset($message)) {
      $t_args = array(
        '@country' => $country->name,
        '@iso2' => $country->iso2,
        '!type' => $type,
      );
      $message = t('Testing that the country @country (@iso2) !type link was found', $t_args);
    }
    $destination = 'admin/config/regional/countries';
    if (!empty($query)) {
      $destination .= '?' . drupal_http_build_query($query);
    }
    $options = array(
      'query' => array(
        'destination' => $destination,
      ),
    );
    switch ($type) {
      case 'title':
        $link = l($country->name, 'admin/config/regional/countries/' . $country->iso2, $options);
        break;
      case 'edit':
        $link = l(t('edit'), 'admin/config/regional/countries/' . $country->iso2, $options);
        break;
      case 'delete':
        $link = l(t('delete'), 'admin/config/regional/countries/' . $country->iso2 . '/delete', $options);
        break;
    }
    if ($assertTrue) {
      $this
        ->assertRaw($link, $message);
    }
    else {
      $this
        ->assertNoRaw($link, $message);
    }
  }
  function assertCountryListed($country, $sort = 'name') {
    $country = (object) $country;

    // This will generate all defaults.
    $country = country_create((array) $country);
    $country->iso2 = strtoupper($country->iso2);
    $country->iso3 = strtoupper($country->iso3);
    $this
      ->assertListingLink($country, 'title', 1);
    foreach (array(
      'iso2',
      'official_name',
      'numcode',
      'enabled',
      'iso3',
    ) as $property) {
      $additional = $sort == $property ? 'class="active" ' : '';

      // Set a default to prevent fallbacks for translatable strings.
      $value = country_property($country, $property, array(
        'default' => '',
      ));
      $this
        ->assertRaw("<td {$additional}id=\"{$country->iso2}-{$property}\">{$value}</td>", "Testing {$property} for {$country->name} ({$country->iso2}): {$value}");
    }
    $this
      ->assertListingLink($country, 'edit', 1);
    if (country_is_locked($country)) {
      $this
        ->assertListingLink($country, 'delete', 0);
    }
    else {
      $this
        ->assertListingLink($country, 'delete', 1);
    }
  }

}

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.
CountriesBaseSetupTest::setUp function 7