function FileSaveDataTest::testWithoutFilename

Test the file_save_data() function when no filename is provided.

File

modules/simpletest/tests/file.test, line 2438

Class

FileSaveDataTest
Tests the file_save_data() function.

Code

function testWithoutFilename() {
    $contents = $this->randomName(8);
    $result = file_save_data($contents);
    $this->assertTrue($result, 'Unnamed file saved correctly.');
    $this->assertEqual(file_default_scheme(), file_uri_scheme($result->uri), "File was placed in Drupal's files directory.");
    $this->assertEqual($result->filename, drupal_basename($result->uri), "Filename was set to the file's basename.");
    $this->assertEqual($contents, file_get_contents($result->uri), 'Contents of the file are correct.');
    $this->assertEqual($result->filemime, 'application/octet-stream', 'A MIME type was set.');
    $this->assertEqual($result->status, FILE_STATUS_PERMANENT, "The file's status was set to permanent.");
    // Check that the correct hooks were called.
    $this->assertFileHooksCalled(array(
        'insert',
    ));
    // Verify that what was returned is what's in the database.
    $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.