function DirectoryTest::testFileCheckLocalDirectoryHandling in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/File/DirectoryTest.php \Drupal\system\Tests\File\DirectoryTest::testFileCheckLocalDirectoryHandling()
Test local directory handling functions.
File
- core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php, line 21 - Contains \Drupal\system\Tests\File\DirectoryTest.
Class
- DirectoryTest
- Tests operations dealing with directories.
Namespace
Drupal\system\Tests\FileCode
function testFileCheckLocalDirectoryHandling() {
$site_path = $this->container
->get('site.path');
$directory = $site_path . '/files';
// Check a new recursively created local directory for correct file system
// permissions.
$parent = $this
->randomMachineName();
$child = $this
->randomMachineName();
// Files directory already exists.
$this
->assertTrue(is_dir($directory), t('Files directory already exists.'), 'File');
// Make files directory writable only.
$old_mode = fileperms($directory);
// Create the directories.
$parent_path = $directory . DIRECTORY_SEPARATOR . $parent;
$child_path = $parent_path . DIRECTORY_SEPARATOR . $child;
$this
->assertTrue(drupal_mkdir($child_path, 0775, TRUE), t('No error reported when creating new local directories.'), 'File');
// Ensure new directories also exist.
$this
->assertTrue(is_dir($parent_path), t('New parent directory actually exists.'), 'File');
$this
->assertTrue(is_dir($child_path), t('New child directory actually exists.'), 'File');
// Check that new directory permissions were set properly.
$this
->assertDirectoryPermissions($parent_path, 0775);
$this
->assertDirectoryPermissions($child_path, 0775);
// Check that existing directory permissions were not modified.
$this
->assertDirectoryPermissions($directory, $old_mode);
// Check creating a directory using an absolute path.
$absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this
->randomMachineName() . DIRECTORY_SEPARATOR . $this
->randomMachineName();
$this
->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
$this
->assertDirectoryPermissions($absolute_path, 0775);
}