Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / File / UnmanagedSaveDataTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\File;
4
5 /**
6  * Tests the file_unmanaged_save_data() function.
7  *
8  * @group File
9  */
10 class UnmanagedSaveDataTest extends FileTestBase {
11   /**
12    * Test the file_unmanaged_save_data() function.
13    */
14   public function testFileSaveData() {
15     $contents = $this->randomMachineName(8);
16     $this->setSetting('file_chmod_file', 0777);
17
18     // No filename.
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.');
23
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);
30   }
31
32 }