1 file.test FileEditTestCase::testFileEdit()

Check file edit functionality.


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


Tests editing existing file entities.


function testFileEdit() {
  $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.
  $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.'));