function TokenProfileTestCase::testProfileTokens in Token 7
Test the profile tokens.
File
- ./
token.test, line 761 - Test integration for the token module.
Class
- TokenProfileTestCase
- Test the profile tokens.
Code
function testProfileTokens() {
$field_types = _profile_field_types();
foreach (array_keys($field_types) as $field_type) {
$field = array();
switch ($field_type) {
case 'checkbox':
$field['title'] = 'This is a checkbox';
break;
case 'selection':
$field['options'] = implode("\n", array(
'Red',
'Blue',
'Green',
));
break;
}
$this
->addProfileField($field_type, $field);
}
// Submit the profile fields for the user.
$edit = array(
'profile_textfield' => 'This is a text field',
'profile_textarea' => "First paragraph.\n\nSecond paragraph.",
'profile_checkbox' => TRUE,
'profile_selection' => 'Red',
'profile_list' => ' Drupal , Joomla ',
'profile_url' => 'http://www.example.com/',
'profile_date[month]' => 5,
'profile_date[day]' => 20,
'profile_date[year]' => 1984,
);
$this
->drupalPost("user/{$this->account->uid}/edit/SimpleTest", $edit, 'Save');
$account = user_load($this->account->uid, TRUE);
// Test the profile token values.
$tokens = array(
'profile-textfield' => 'This is a text field',
'profile-textarea' => "<p>First paragraph.</p>\n<p>Second paragraph.</p>\n",
'profile-checkbox' => 'This is a checkbox',
'profile-selection' => 'Red',
'profile-list' => 'Drupal, Joomla',
'profile-url' => 'http://www.example.com/',
'profile-date' => format_date(453859200, 'medium', '', NULL),
'profile-date:raw' => '453859200',
'profile-date:custom:Y' => '1984',
);
$this
->assertTokens('user', array(
'user' => $account,
), $tokens);
// 'Un-select' the checkbox and select profile fields.
$edit = array(
'profile_checkbox' => FALSE,
'profile_selection' => '0',
);
$this
->drupalPost("user/{$this->account->uid}/edit/SimpleTest", $edit, 'Save');
$account = user_load($this->account->uid, TRUE);
// The checkbox and select profile tokens should no longer return a value.
$tokens = array(
'profile-checkbox' => NULL,
'profile-selection' => NULL,
);
$this
->assertTokens('user', array(
'user' => $account,
), $tokens);
}