Tests the simple file storage.
Expanded class hierarchy of FileStorageTest
class FileStorageTest extends PhpStorageTestBase {
public static function getInfo() {
return array(
'name' => 'Simple file storage',
'description' => 'Tests the FileStorage implementation.',
'group' => 'PHP Storage',
);
}
function setUp() {
global $conf;
parent::setUp();
$dir_path = sys_get_temp_dir() . '/php';
$conf['php_storage']['simpletest'] = array(
'class' => 'Drupal\\Component\\PhpStorage\\FileStorage',
'directory' => $dir_path,
);
$conf['php_storage']['readonly'] = array(
'class' => 'Drupal\\Component\\PhpStorage\\FileReadOnlyStorage',
'directory' => $dir_path,
// Let this read from the bin where the other instance is writing.
'bin' => 'simpletest',
);
}
/**
* Tests basic load/save/delete operations.
*/
function testCRUD() {
$php = $this->storageFactory
->get('simpletest');
$this
->assertInstanceOf('Drupal\\Component\\PhpStorage\\FileStorage', $php);
$this
->assertCRUD($php);
}
/**
* Tests writing with one class and reading with another.
*/
function testReadOnly() {
$php = $this->storageFactory
->get('simpletest');
$name = $this
->randomName() . '/' . $this
->randomName() . '.php';
// Find a global that doesn't exist.
do {
$random = mt_rand(10000, 100000);
} while (isset($GLOBALS[$random]));
// Write out a PHP file and ensure it's successfully loaded.
$code = "<?php\n\$GLOBALS[{$random}] = TRUE;";
$success = $php
->save($name, $code);
$this
->assertSame($success, TRUE);
$php_read = $this->storageFactory
->get('readonly');
$php_read
->load($name);
$this
->assertTrue($GLOBALS[$random]);
// If the file was successfully loaded, it must also exist, but ensure the
// exists() method returns that correctly.
$this
->assertSame($php_read
->exists($name), TRUE);
// Saving and deleting should always fail.
$this
->assertFalse($php_read
->save($name, $code));
$this
->assertFalse($php_read
->delete($name));
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileStorageTest:: |
public static | function |
This method exists to support the simpletest UI runner. Overrides UnitTestCase:: |
|
FileStorageTest:: |
function |
Overrides \Drupal\Tests\UnitTestCase::setUp() Overrides PhpStorageTestBase:: |
||
FileStorageTest:: |
function | Tests basic load/save/delete operations. | ||
FileStorageTest:: |
function | Tests writing with one class and reading with another. | ||
PhpStorageTestBase:: |
protected | property | The storage factory object. | |
PhpStorageTestBase:: |
public | function | Assert that a PHP storage controller's load/save/delete operations work. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
public static | function | Generates a random string containing letters and numbers. |