FileStorageReadOnlyTest.php in Drupal 8
File
core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
View source
<?php
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\FileStorage;
use Drupal\Component\PhpStorage\FileReadOnlyStorage;
use Drupal\Component\Utility\Random;
class FileStorageReadOnlyTest extends PhpStorageTestBase {
protected $standardSettings;
protected $readonlyStorage;
protected function setUp() {
parent::setUp();
$this->standardSettings = [
'directory' => $this->directory,
'bin' => 'test',
];
$this->readonlyStorage = [
'directory' => $this->directory,
'bin' => 'test',
];
}
public function testReadOnly() {
$random = new Random();
$php = new FileStorage($this->standardSettings);
$name = $random
->name(8, TRUE) . '/' . $random
->name(8, TRUE) . '.php';
do {
$random = mt_rand(10000, 100000);
} while (isset($GLOBALS[$random]));
$code = "<?php\n\$GLOBALS[{$random}] = TRUE;";
$success = $php
->save($name, $code);
$this
->assertSame(TRUE, $success);
$php_read = new FileReadOnlyStorage($this->readonlyStorage);
$php_read
->load($name);
$this
->assertTrue($GLOBALS[$random]);
$this
->assertSame(TRUE, $php_read
->exists($name));
$this
->assertFalse($php_read
->save($name, $code));
$this
->assertFalse($php_read
->delete($name));
unset($GLOBALS[$random]);
}
public function testWriteable() {
$php_read = new FileReadOnlyStorage($this->readonlyStorage);
$this
->assertFalse($php_read
->writeable());
}
public function testDeleteAll() {
$random = new Random();
$php = new FileStorage($this->standardSettings);
$name = $random
->name(8, TRUE) . '/' . $random
->name(8, TRUE) . '.php';
do {
$random = mt_rand(10000, 100000);
} while (isset($GLOBALS[$random]));
$code = "<?php\n\$GLOBALS[{$random}] = TRUE;";
$this
->assertTrue($php
->save($name, $code));
$php_read = new FileReadOnlyStorage($this->readonlyStorage);
$this
->assertFalse($php_read
->deleteAll());
$this
->assertDirectoryExists($this->directory . '/test');
}
}