function FileStorageReadOnlyTest::testDeleteAll

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php \Drupal\Tests\Component\PhpStorage\FileStorageReadOnlyTest::testDeleteAll()
  2. 8.9.x core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php \Drupal\Tests\Component\PhpStorage\FileStorageReadOnlyTest::testDeleteAll()
  3. 11.x 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 98

Class

FileStorageReadOnlyTest
@coversDefaultClass \Drupal\Component\PhpStorage\FileReadOnlyStorage

Namespace

Drupal\Tests\Component\PhpStorage

Code

public function testDeleteAll() : void {
    // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.