You are here

function ReferenceOptionLimitTaxonomyTestCase::testNodeEditForm in Reference field option limit 7

Test the node edit form.

File

tests/reference_option_limit.test, line 114
Contains tests for the Reference option limit module.

Class

ReferenceOptionLimitTaxonomyTestCase
Test use of the module with term reference fields.

Code

function testNodeEditForm() {

  // Get country and city terms.
  $terms = taxonomy_get_term_by_name('Italy', 'countries');
  $country_term = array_pop($terms);
  $terms = taxonomy_get_term_by_name('Firenze', 'cities');
  $city_term = array_pop($terms);

  // Create a node: Italy, Firenze.
  $edit = array(
    'uid' => $this->user->uid,
    'name' => $this->user->name,
    'type' => 'test_rol_node_taxo',
    'language' => LANGUAGE_NONE,
    'title' => $this
      ->randomName(),
  );
  $edit['test_rol_country'][LANGUAGE_NONE][0]['tid'] = $country_term->tid;
  $edit['test_rol_city'][LANGUAGE_NONE][0]['tid'] = $city_term->tid;
  $node = (object) $edit;
  node_save($node);

  // Edit the node.
  $this
    ->drupalGet("node/{$node->nid}/edit");
  foreach (reference_option_limit_test_taxonomy_cities() as $city_name => $country_name) {
    if ($country_name == 'Italy') {
      $this
        ->assertText($city_name, "The {$city_name} term was found in the form.");
    }
    else {
      $this
        ->assertNoText($city_name, "The {$city_name} term was not found in the form.");
    }
  }

  // Get a country term.
  $terms = taxonomy_get_term_by_name('France', 'countries');
  $country_term = array_pop($terms);
  $edit = array(
    'test_rol_country[und]' => $country_term->tid,
  );

  // Change the country we have selected in the form: France.
  $this
    ->drupalPostAJAX(NULL, $edit, 'test_rol_country[und]');
  foreach (reference_option_limit_test_taxonomy_cities() as $city_name => $country_name) {
    if ($country_name == 'France') {
      $this
        ->assertText($city_name, "The {$city_name} term was found in the form.");
    }
    else {
      $this
        ->assertNoText($city_name, "The {$city_name} term was not found in the form.");
    }
  }
  $terms = taxonomy_get_term_by_name('Paris', 'cities');
  $city_term = array_pop($terms);

  // Save the form with France, Paris.
  $edit = array(
    'test_rol_country[und]' => $country_term->tid,
    "test_rol_city[und][{$city_term->tid}]" => 1,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  entity_get_controller('node')
    ->resetCache();
  $node = node_load($node->nid);
  $this
    ->assertEqual($node->test_rol_country[LANGUAGE_NONE][0]['tid'], $country_term->tid, "The node's country was updated.");
  $this
    ->assertEqual($node->test_rol_city[LANGUAGE_NONE][0]['tid'], $city_term->tid, "The node's city was updated.");
}