FileStorageReadOnlyTest.php in Zircon Profile 8.0
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;
class FileStorageReadOnlyTest extends PhpStorageTestBase {
protected $standardSettings;
protected $readonlyStorage;
protected function setUp() {
parent::setUp();
$this->standardSettings = array(
'directory' => $this->directory,
'bin' => 'test',
);
$this->readonlyStorage = array(
'directory' => $this->directory,
'bin' => 'test',
);
}
public function testReadOnly() {
$php = new FileStorage($this->standardSettings);
$name = $this
->randomMachineName() . '/' . $this
->randomMachineName() . '.php';
do {
$random = mt_rand(10000, 100000);
} while (isset($GLOBALS[$random]));
$code = "<?php\n\$GLOBALS[{$random}] = TRUE;";
$success = $php
->save($name, $code);
$this
->assertSame($success, TRUE);
$php_read = new FileReadOnlyStorage($this->readonlyStorage);
$php_read
->load($name);
$this
->assertTrue($GLOBALS[$random]);
$this
->assertSame($php_read
->exists($name), TRUE);
$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() {
$php = new FileStorage($this->standardSettings);
$name = $this
->randomMachineName() . '/' . $this
->randomMachineName() . '.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
->assertTrue(file_exists($this->directory . '/test'), 'File storage directory does not exist.');
}
}