You are here

public function FileStorageReadOnlyTest::testDeleteAll in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php \Drupal\Tests\Component\PhpStorage\FileStorageReadOnlyTest::testDeleteAll()
  2. 9 core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php \Drupal\Tests\Component\PhpStorage\FileStorageReadOnlyTest::testDeleteAll()

@covers ::deleteAll

File

core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php, line 91

Class

FileStorageReadOnlyTest
@coversDefaultClass \Drupal\Component\PhpStorage\FileReadOnlyStorage

Namespace

Drupal\Tests\Component\PhpStorage

Code

public function testDeleteAll() {

  // Random generator.
  $random = new Random();
  $php = new FileStorage($this->standardSettings);
  $name = $random
    ->name(8, TRUE) . '/' . $random
    ->name(8, TRUE) . '.php';

  // Find a global that doesn't exist.
  do {
    $random = mt_rand(10000, 100000);
  } while (isset($GLOBALS[$random]));

  // Write our the file so we can test deleting.
  $code = "<?php\n\$GLOBALS[{$random}] = TRUE;";
  $this
    ->assertTrue($php
    ->save($name, $code));
  $php_read = new FileReadOnlyStorage($this->readonlyStorage);
  $this
    ->assertFalse($php_read
    ->deleteAll());

  // Make sure directory exists prior to removal.
  $this
    ->assertDirectoryExists($this->directory . '/test');
}