function SaveUploadTest::setUp

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

Generates a random database prefix and installs Drupal with the specified installation profile in Drupal\simpletest\WebTestBase::$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.

Overrides FileManagedTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

1 call to SaveUploadTest::setUp()
RemoteFileSaveUploadTest::setUp in drupal/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php
Sets up a Drupal site for running functional and integration tests.
1 method overrides SaveUploadTest::setUp()
RemoteFileSaveUploadTest::setUp in drupal/core/modules/file/lib/Drupal/file/Tests/RemoteFileSaveUploadTest.php
Sets up a Drupal site for running functional and integration tests.

File

drupal/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php, line 37
Definition of Drupal\file\Tests\SaveUploadTest.

Class

SaveUploadTest
Test the file_save_upload() function.

Namespace

Drupal\file\Tests

Code

function setUp() {
  parent::setUp();
  $account = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $image_files = $this
    ->drupalGetTestFiles('image');
  $this->image = entity_create('file', (array) current($image_files));
  list(, $this->image_extension) = explode('.', $this->image->filename);
  $this
    ->assertTrue(is_file($this->image->uri), t("The image file we're going to upload exists."));
  $this->phpfile = current($this
    ->drupalGetTestFiles('php'));
  $this
    ->assertTrue(is_file($this->phpfile->uri), t("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]' => 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();
}