Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / Tests / Component / PhpStorage / FileStorageTest.php
index a1a11ec38dba22af45ecfacb0b568b4e4b5f2ba2..52e1b83c032ed21c5add56482ad1d07635ba1eab 100644 (file)
@@ -3,6 +3,9 @@
 namespace Drupal\Tests\Component\PhpStorage;
 
 use Drupal\Component\PhpStorage\FileStorage;
+use Drupal\Component\Utility\Random;
+use org\bovigo\vfs\vfsStreamDirectory;
+use PHPUnit_Framework_Error_Warning;
 
 /**
  * @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
@@ -55,11 +58,13 @@ class FileStorageTest extends PhpStorageTestBase {
    * @covers ::deleteAll
    */
   public function testDeleteAll() {
+    // Random generator.
+    $random_generator = new Random();
 
     // Write out some files.
     $php = new FileStorage($this->standardSettings);
 
-    $name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
+    $name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
 
     // Find a global that doesn't exist.
     do {
@@ -84,4 +89,18 @@ class FileStorageTest extends PhpStorageTestBase {
     unset($GLOBALS[$random]);
   }
 
+  /**
+   * @covers ::createDirectory
+   */
+  public function testCreateDirectoryFailWarning() {
+    $directory = new vfsStreamDirectory('permissionDenied', 0200);
+    $storage = new FileStorage([
+      'directory' => $directory->url(),
+      'bin' => 'test',
+    ]);
+    $code = "<?php\n echo 'here';";
+    $this->setExpectedException(PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied');
+    $storage->save('subdirectory/foo.php', $code);
+  }
+
 }