1.20.x token.test | TokenUserTestCase::testUserTokens() |
File
- modules/
simpletest/ tests/ token.test, line 745 - Test integration for the token module.
Class
Code
function testUserTokens() {
// Add a user picture to the account.
$image = current($this->backdropGetTestFiles('image'));
$edit = array('files[picture_upload]' => backdrop_realpath($image->uri));
$this->backdropPost('user/' . $this->account->uid . '/edit', $edit, t('Save'));
// Load actual user data from database.
$this->account = user_load($this->account->uid, TRUE);
$this->assertTrue(!empty($this->account->picture->fid), 'User picture uploaded.');
$user_tokens = array(
'picture' => theme('user_picture', array('account' => $this->account)),
'picture:fid' => $this->account->picture->fid,
'picture:size-raw' => 125,
'ip-address' => NULL,
'roles' => implode(', ', array_intersect_key(user_roles(), backdrop_map_assoc($this->account->roles))),
'roles:keys' => implode(', ', $this->account->roles),
);
$this->assertTokens('user', array('user' => $this->account), $user_tokens);
$edit = array('user_pictures' => FALSE);
$this->backdropPost('admin/config/people/settings', $edit, 'Save configuration');
$this->assertText('The configuration options have been saved.');
// Remove the simpletest-created user role.
user_role_delete(end($this->account->roles));
$this->account = user_load($this->account->uid, TRUE);
$user_tokens = array(
'picture' => NULL,
'picture:fid' => NULL,
'ip-address' => NULL,
'roles' => 'Authenticated',
'roles:keys' => BACKDROP_AUTHENTICATED_ROLE,
);
$this->assertTokens('user', array('user' => $this->account), $user_tokens);
// The ip address token should work for the current user token type.
$tokens = array(
'ip-address' => ip_address(),
);
$this->assertTokens('current-user', array(), $tokens);
$anonymous = backdrop_anonymous_user();
$tokens = array(
'roles' => 'Anonymous',
'roles:keys' => BACKDROP_ANONYMOUS_ROLE,
);
$this->assertTokens('user', array('user' => $anonymous), $tokens);
}