function FileEntityEditTestCase::testFileEntityEdit in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7.2 file_entity.test \FileEntityEditTestCase::testFileEntityEdit()
Check file edit functionality.
File
- ./
file_entity.test, line 328 - Test integration for the file_entity module.
Class
- FileEntityEditTestCase
- Tests editing existing file entities.
Code
function testFileEntityEdit() {
$this
->drupalLogin($this->web_user);
$test_file = $this
->getTestFile('text');
$name_key = "filename";
// Create file to edit.
$edit = array();
$edit['files[upload]'] = drupal_realpath($test_file->uri);
$this
->drupalPost('file/add', $edit, t('Next'));
if ($this
->xpath('//input[@name="scheme"]')) {
$this
->drupalPost(NULL, array(), t('Next'));
}
// Check that the file exists in the database.
$file = $this
->getFileByFilename($test_file->filename);
$this
->assertTrue($file, t('File found in database.'));
// Check that "edit" link points to correct page.
$this
->clickLink(t('Edit'));
$edit_url = url("file/{$file->fid}/edit", array(
'absolute' => TRUE,
));
$actual_url = $this
->getURL();
$this
->assertEqual($edit_url, $actual_url, t('On edit page.'));
// Check that the name field is displayed with the correct value.
$active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
$link_text = t('!local-task-title!active', array(
'!local-task-title' => t('Edit'),
'!active' => $active,
));
$this
->assertText(strip_tags($link_text), 0, t('Edit tab found and marked active.'));
$this
->assertFieldByName($name_key, $file->filename, t('Name field displayed.'));
// The user does not have "delete" permissions so no delete button should be found.
$this
->assertNoFieldByName('op', t('Delete'), 'Delete button not found.');
// Edit the content of the file.
$edit = array();
$edit[$name_key] = $this
->randomName(8);
// Stay on the current page, without reloading.
$this
->drupalPost(NULL, $edit, t('Save'));
// Check that the name field is displayed with the updated values.
$this
->assertText($edit[$name_key], t('Name displayed.'));
}