More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Component / PhpStorage / FileStorageTest.php
index a1a11ec38dba22af45ecfacb0b568b4e4b5f2ba2..168d1603e3ceb2bdcc9ec9311d11dbb3adceef8a 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,24 @@ 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';";
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(Warning::class);
+      $this->expectExceptionMessage('mkdir(): Permission Denied');
+    }
+    else {
+      $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied');
+    }
+    $storage->save('subdirectory/foo.php', $code);
+  }
+
 }