function FileEntityEditTestCase::testFileEntityAssociatedUser in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7.2 file_entity.test \FileEntityEditTestCase::testFileEntityAssociatedUser()
Check changing file associated user fields.
File
- ./
file_entity.test, line 374 - Test integration for the file_entity module.
Class
- FileEntityEditTestCase
- Tests editing existing file entities.
Code
function testFileEntityAssociatedUser() {
$this
->drupalLogin($this->admin_user);
// Create file to edit.
$test_file = $this
->getTestFile('text');
$name_key = "filename";
$edit = array();
$edit['files[upload]'] = drupal_realpath($test_file->uri);
$this
->drupalPost('file/add', $edit, t('Next'));
// Check that the file was associated with the currently logged in user.
$file = $this
->getFileByFilename($test_file->filename);
$this
->assertIdentical($file->uid, $this->admin_user->uid, 'File associated with admin user.');
// Try to change the 'associated user' field to an invalid user name.
$edit = array(
'name' => 'invalid-name',
);
$this
->drupalPost('file/' . $file->fid . '/edit', $edit, t('Save'));
$this
->assertText('The username invalid-name does not exist.');
// Change the associated user field to an empty string, which should assign
// association to the anonymous user (uid 0).
$edit['name'] = '';
$this
->drupalPost('file/' . $file->fid . '/edit', $edit, t('Save'));
$file = file_load($file->fid);
$this
->assertIdentical($file->uid, '0', 'File associated with anonymous user.');
// Change the associated user field to another user's name (that is not
// logged in).
$edit['name'] = $this->web_user->name;
$this
->drupalPost('file/' . $file->fid . '/edit', $edit, t('Save'));
$file = file_load($file->fid);
$this
->assertIdentical($file->uid, $this->web_user->uid, 'File associated with normal user.');
// Check that normal users cannot change the associated user information.
$this
->drupalLogin($this->web_user);
$this
->drupalGet('file/' . $file->fid . '/edit');
$this
->assertNoFieldByName('name');
}