function ReferenceOptionLimitProfile2TestCase::testProfile2Form in Reference field option limit 7
Test the functionality of Profile2 fields on a user edit form.
File
- tests/
reference_option_limit.test, line 639 - Contains tests for the Reference option limit module.
Class
- ReferenceOptionLimitProfile2TestCase
- Test use of the module on a Profile2 entity.
Code
function testProfile2Form() {
$user_id = $this->user->uid;
$this
->drupalGet("user/{$user_id}/edit/test_rol");
// Get a country node.
$country_node = $this
->getNodeByTitle('France');
$edit = array(
'profile_test_rol[test_rol_er_country][und]' => $country_node->nid,
);
$this
->drupalPostAJAX(NULL, $edit, 'profile_test_rol[test_rol_er_country][und]');
// The AJAX post updates the content our assertions test against.
// Check each term: all the cities in France should be present; all the
// others should not.
foreach (reference_option_limit_test_entityreference_cities() as $city_name => $country_name) {
if ($country_name == 'France') {
$this
->assertText($city_name, "The {$city_name} node was found in the form.");
}
else {
$this
->assertNoText($city_name, "The {$city_name} node was not found in the form.");
}
}
// Get a country node.
$country_node = $this
->getNodeByTitle('Italy');
$edit = array(
'profile_test_rol[test_rol_er_country][und]' => $country_node->nid,
);
// Change the country we have selected.
$this
->drupalPostAJAX(NULL, $edit, 'profile_test_rol[test_rol_er_country][und]');
foreach (reference_option_limit_test_entityreference_cities() as $city_name => $country_name) {
if ($country_name == 'Italy') {
$this
->assertText($city_name, "The {$city_name} node was found in the form.");
}
else {
$this
->assertNoText($city_name, "The {$city_name} node was not found in the form.");
}
}
// Pick a city and save the entity.
$city_node = $this
->getNodeByTitle('Firenze');
$edit = array(
// Use the most recent country node.
'profile_test_rol[test_rol_er_country][und]' => $country_node->nid,
"profile_test_rol[test_rol_er_city][und][{$city_node->nid}]" => 1,
);
$this
->drupalPost(NULL, $edit, t('Save'));
// Load the profile.
$profile = profile2_load_by_user($this->user, 'test_rol');
$this
->assertEqual($profile->test_rol_er_country[LANGUAGE_NONE][0]['target_id'], $country_node->nid, "The node has its country field value set.");
$this
->assertEqual($profile->test_rol_er_city[LANGUAGE_NONE][0]['target_id'], $city_node->nid, "The node has its city field value set.");
}