FileSaveDataTest.php in Drupal 8
File
core/tests/Drupal/KernelTests/Core/File/FileSaveDataTest.php
View source
<?php
namespace Drupal\KernelTests\Core\File;
use Drupal\Core\File\FileSystemInterface;
class FileSaveDataTest extends FileTestBase {
public function testFileSaveData() {
$contents = $this
->randomMachineName(8);
$this
->setSetting('file_chmod_file', 0777);
$file_system = \Drupal::service('file_system');
$filepath = $file_system
->saveData($contents, 'public://asdf.txt', FileSystemInterface::EXISTS_REPLACE);
$this
->assertNotFalse($filepath, 'Unnamed file saved correctly.');
$this
->assertEqual('asdf.txt', \Drupal::service('file_system')
->basename($filepath), 'File was named correctly.');
$this
->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
$this
->assertFilePermissions($filepath, 0777);
}
}