You are here

function CountriesElementUnitTest::testFAPIElement in Countries 8

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

File

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

Class

CountriesElementUnitTest
Test the node_load_multiple() function.

Code

function testFAPIElement() {
  $this
    ->drupalGet('countries-example');
  if ($this
    ->assertResponse(200, t('Assert that the example page form loads.'))) {
    $this
      ->assertOptionPresent('edit-countries-example-default-country-4', 'AD');
    $this
      ->assertOptionPresent('edit-countries-example-default-country-4', 'AU');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-4', 'NZ');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-4', 'AF');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-7', 'AD');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-7', 'NZ');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-7', 'CN');
    $this
      ->assertOptionPresent('edit-countries-example-default-country-8', 'NZ');
    $this
      ->assertOptionPresent('edit-countries-example-default-country-8', 'AF');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-8', 'AU');
    $this
      ->assertNoOptionPresent('edit-countries-example-default-country-8', 'AD');
    $af = country_load('af');
    $af->enabled = 0;
    country_save($af);
    $nz = country_load('nz');
    $nz->enabled = 0;
    country_save($nz);
    countries_clear_caches();
    $edit = array(
      // Single select, enabled only
      'countries_example_default_country_4' => 'AU',
      // Multi-select select, enabled only
      'countries_example_default_country_5[]' => array(
        'AU',
        'IR',
      ),
      // Multi-select select, enabled European countries only.
      // @todo check that the enabled still works
      'countries_example_default_country_6[]' => array(
        'FR',
        'DE',
      ),
      // Multi-select select, enabled American countries only.
      // Cardinality 3, required.
      'countries_example_default_country_7[]' => array(
        'CA',
        'US',
        'MX',
      ),
      // Single select, disabled only.
      'countries_example_default_country_8' => 'NZ',
    );
    $this
      ->drupalPost('countries-example', $edit, t('Save'));
    $this
      ->assertText('The configuration options have been saved.', 'Country example saved ok.');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-4', 'AU');
    $this
      ->assertNoOptionSelected('edit-countries-example-default-country-4', 'AD');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-5', 'IR');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-5', 'AU');
    $this
      ->assertNoOptionSelected('edit-countries-example-default-country-5', 'AD');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-6', 'FR');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-6', 'DE');
    $this
      ->assertNoOptionSelected('edit-countries-example-default-country-6', 'AD');
    $this
      ->assertNoOptionSelected('edit-countries-example-default-country-5', 'HU');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-7', 'CA');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-7', 'US');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-7', 'MX');
    $this
      ->assertOptionSelected('edit-countries-example-default-country-8', 'NZ');
    $this
      ->assertNoOptionSelected('edit-countries-example-default-country-8', 'AF');
    $edit = array(
      'countries_example_default_country_7[]' => array(
        'CA',
        'US',
        'MX',
        'CH',
        'PE',
      ),
    );
    $this
      ->drupalPost('countries-example', $edit, t('Save'));
    $this
      ->assertRaw(t('%title field is restricted to %count countries.', array(
      '%title' => t('Select one to three countries in America (country element)'),
      '%count' => 3,
    )), 'Country example saved ok.');
  }
}