You are here

function FileSaveUploadTest::setUp in SimpleTest 7

Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix. A temporary files directory is created with the same name as the database prefix.

Parameters

...: List of modules to enable for the duration of the test.

Overrides FileHookTestCase::setUp

File

tests/file.test, line 548
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Class

FileSaveUploadTest
Test the file_save_upload() function.

Code

function setUp() {
  parent::setUp();
  $account = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this->image = current($this
    ->drupalGetTestFiles('image'));
  $this
    ->assertTrue(is_file($this->image->uri), t("The file we're going to upload exists."));
  $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file}')
    ->fetchField();

  // Upload with replace to gurantee there's something there.
  $edit = array(
    'file_test_replace' => FILE_EXISTS_REPLACE,
    'files[file_test_upload]' => drupal_realpath($this->image->uri),
  );
  $this
    ->drupalPost('file-test/upload', $edit, t('Submit'));
  $this
    ->assertResponse(200, t('Received a 200 response for posted test file.'));
  $this
    ->assertRaw(t('You WIN!'), t('Found the success message.'));

  // Check that the correct hooks were called then clean out the hook
  // counters.
  $this
    ->assertFileHooksCalled(array(
    'validate',
    'insert',
  ));
  file_test_reset();
}