function FileStorageReadOnlyTest::testDeleteAll

Same name and namespace 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 <a href="/api/drupal/core%21lib%21Drupal%21Component%21PhpStorage%21FileReadOnlyStorage.php/class/FileReadOnlyStorage/10" title="Reads code as regular PHP files, but won&#039;t write them." class="local">\Drupal\Component\PhpStorage\FileReadOnlyStorage</a>

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');
}

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