Commit 25f081af authored by alexpott's avatar alexpott

Issue #2051385 by jhedstrom: Expand phpunit tests for \Drupal\Component\PhpStorage.

parent 89773d1a
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\Tests\Component\PhpStorage\FileStorageTest.
* Contains \Drupal\Tests\Component\PhpStorage\FileStorageTest.
*/
namespace Drupal\Tests\Component\PhpStorage;
......@@ -20,7 +20,7 @@ public static function getInfo() {
);
}
function setUp() {
public function setUp() {
global $conf;
parent::setUp();
$dir_path = sys_get_temp_dir() . '/php';
......@@ -38,8 +38,11 @@ function setUp() {
/**
* Tests basic load/save/delete operations.
*
* @group Drupal
* @group PhpStorage
*/
function testCRUD() {
public function testCRUD() {
$php = $this->storageFactory->get('simpletest');
$this->assertInstanceOf('Drupal\Component\PhpStorage\FileStorage', $php);
$this->assertCRUD($php);
......@@ -47,8 +50,11 @@ function testCRUD() {
/**
* Tests writing with one class and reading with another.
*
* @group Drupal
* @group PhpStorage
*/
function testReadOnly() {
public function testReadOnly() {
$php = $this->storageFactory->get('simpletest');
$name = $this->randomName() . '/' . $this->randomName() . '.php';
......@@ -72,4 +78,56 @@ function testReadOnly() {
$this->assertFalse($php_read->save($name, $code));
$this->assertFalse($php_read->delete($name));
}
/**
* Tests writeable() method.
*
* @group Drupal
* @group PhpStorage
*/
public function testWriteable() {
$php_read = $this->storageFactory->get('readonly');
$this->assertFalse($php_read->writeable());
$php = $this->storageFactory->get('simpletest');
$this->assertTrue($php->writeable());
}
/**
* Tests deleteAll() method.
*
* @group Drupal
* @group PhpStorage
*/
public function testDeleteAll() {
$php_read = $this->storageFactory->get('readonly');
$this->assertFalse($php_read->deleteAll());
// Make sure directory exists prior to removal.
$this->assertTrue(file_exists(sys_get_temp_dir() . '/php/simpletest'), 'File storage directory does not exist.');
// Write out some files.
$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->load($name);
$this->assertTrue($GLOBALS[$random]);
$this->assertTrue($php->deleteAll());
$this->assertFalse($php->load($name));
$this->assertFalse(file_exists(sys_get_temp_dir() . '/php/simpletest'), 'File storage directory still exists after call to deleteAll().');
// Should still return TRUE if directory has already been deleted.
$this->assertTrue($php->deleteAll());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment