3 namespace Drupal\KernelTests\Core\File;
6 * Tests the file_unmanaged_save_data() function.
10 class UnmanagedSaveDataTest extends FileTestBase {
12 * Test the file_unmanaged_save_data() function.
14 public function testFileSaveData() {
15 $contents = $this->randomMachineName(8);
16 $this->setSetting('file_chmod_file', 0777);
19 $filepath = file_unmanaged_save_data($contents);
20 $this->assertTrue($filepath, 'Unnamed file saved correctly.');
21 $this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), "File was placed in Drupal's files directory.");
22 $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
24 // Provide a filename.
25 $filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
26 $this->assertTrue($filepath, 'Unnamed file saved correctly.');
27 $this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.');
28 $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
29 $this->assertFilePermissions($filepath, 0777);