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