function FileSaveUploadTest::setUp
Same name in other branches
- 10 core/modules/file/tests/src/Kernel/FileSaveUploadTest.php \Drupal\Tests\file\Kernel\FileSaveUploadTest::setUp()
- 11.x core/modules/file/tests/src/Kernel/FileSaveUploadTest.php \Drupal\Tests\file\Kernel\FileSaveUploadTest::setUp()
Overrides FileHookTestCase::setUp
1 call to FileSaveUploadTest::setUp()
- RemoteFileSaveUploadTest::setUp in modules/
simpletest/ tests/ file.test - Sets up a Drupal site for running functional and integration tests.
1 method overrides FileSaveUploadTest::setUp()
- RemoteFileSaveUploadTest::setUp in modules/
simpletest/ tests/ file.test - Sets up a Drupal site for running functional and integration tests.
File
-
modules/
simpletest/ tests/ file.test, line 585
Class
- FileSaveUploadTest
- Test the file_save_upload() function.
Code
function setUp() {
parent::setUp();
$account = $this->drupalCreateUser(array(
'access content',
));
$this->drupalLogin($account);
$image_files = $this->drupalGetTestFiles('image');
$this->image = 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->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertTrue(is_file($this->phpfile->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]' => drupal_realpath($this->image->uri),
);
$this->drupalPost('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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.