1 file.test FileSaveUploadTest::setUp()

Sets up a Backdrop site for running functional and integration tests.

Generates a random database prefix and installs Backdrop with the specified installation profile in BackdropWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Return value

bool: TRUE if set up completes, FALSE if an error occurred.

Overrides FileHookTestCase::setUp

See also

BackdropWebTestCase::prepareDatabasePrefix()

BackdropWebTestCase::changeDatabasePrefix()

BackdropWebTestCase::prepareEnvironment()

File

core/modules/simpletest/tests/file.test, line 544
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();

  $image_files = $this->backdropGetTestFiles('image');
  $this->image = new File((array) current($image_files));

  list(, $this->image_extension) = explode('.', $this->image->filename);
  $this->assertTrue(is_file($this->image->uri), "The image file we're going to upload exists.");

  $this->php_file = current($this->backdropGetTestFiles('php'));
  $this->assertTrue(is_file($this->php_file->uri), "The PHP file we're going to upload exists.");

  $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();

  // Upload with replace to guarantee there's something there.
  $edit = array(
    'file_test_replace' => FILE_EXISTS_REPLACE,
    'files[file_test_upload]' => backdrop_realpath($this->image->uri),
  );
  $this->backdropPost('file-test/upload', $edit, t('Submit'));
  $this->assertResponse(200, 'Received a 200 response for posted test file.');
  $this->assertRaw(t('You WIN!'), '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();
}