1 file.test FileEditTestCase::testFileEdit()

Check file edit functionality.

File

core/modules/file/tests/file.test, line 2271
Tests for file.module.

Class

FileEditTestCase
Tests editing existing file entities.

Code

function testFileEdit() {
  $this->backdropLogin($this->web_user);
  $name_key = "filename";

  $file = $this->createFile(array('type' => 'image'));

  // Check that the file exists in the database.
  $file = $this->getFileByFilename($file->filename);
  $this->assertTrue($file, t('File found in database.'));

  // Check that "edit" link points to correct page.
  $this->backdropGet('admin/content/files');
  $this->clickLink(t('Manage'));
  $edit_url = url("file/$file->fid/manage", array('absolute' => TRUE));
  $actual_url = strtok($this->getURL(), '?');
  $this->assertEqual($edit_url, $actual_url, t('On edit page.'));

  // Check that the name field is displayed with the correct value.
  $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->backdropPost(NULL, $edit, t('Save'));

  // Check that the name field is displayed with the updated values.
  $this->assertText($edit[$name_key], t('Name displayed.'));
}