FileStorageTest.php in Zircon Profile 8.0
File
core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
View source
<?php
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\FileStorage;
class FileStorageTest extends PhpStorageTestBase {
protected $standardSettings;
protected function setUp() {
parent::setUp();
$this->standardSettings = array(
'directory' => $this->directory,
'bin' => 'test',
);
}
public function testCRUD() {
$php = new FileStorage($this->standardSettings);
$this
->assertCRUD($php);
}
public function testWriteable() {
$php = new FileStorage($this->standardSettings);
$this
->assertTrue($php
->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), 'Saved php file');
$php
->load($name);
$this
->assertTrue($GLOBALS[$random], 'File saved correctly with correct value');
$this
->assertTrue(file_exists($this->directory . '/test'), 'File storage directory does not exist.');
$this
->assertTrue($php
->deleteAll(), 'Delete all reported success');
$this
->assertFalse($php
->load($name));
$this
->assertFalse(file_exists($this->directory . '/test'), 'File storage directory does not exist after call to deleteAll()');
$this
->assertTrue($php
->deleteAll(), 'Delete all succeeds with nothing to delete');
unset($GLOBALS[$random]);
}
}