86ea0293158cd353d821f0c81c4a4fa86b79e11f
[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   /**
13    * Test the file_unmanaged_save_data() function.
14    */
15   public function testFileSaveData() {
16     $contents = $this->randomMachineName(8);
17     $this->setSetting('file_chmod_file', 0777);
18
19     // No filename.
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.');
24
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);
31   }
32
33 }