Issue #1935922 by msonnabaum: Convert PhpStorage tests to phpunit.

8.0.x
webchick 2013-03-17 00:08:45 -07:00
parent c047547318
commit 0d3968eee2
4 changed files with 30 additions and 30 deletions

View File

@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\system\Tests\PhpStorage\FileStorageTest.
* Definition of Drupal\Tests\Component\PhpStorage\FileStorageTest.
*/
namespace Drupal\system\Tests\PhpStorage;
namespace Drupal\Tests\Component\PhpStorage;
/**
* Tests the simple file storage.
@ -23,7 +23,7 @@ class FileStorageTest extends PhpStorageTestBase {
function setUp() {
global $conf;
parent::setUp();
$dir_path = DRUPAL_ROOT . '/' . $this->public_files_directory . '/php';
$dir_path = sys_get_temp_dir() . '/php';
$conf['php_storage']['simpletest'] = array(
'class' => 'Drupal\Component\PhpStorage\FileStorage',
'directory' => $dir_path,
@ -41,7 +41,7 @@ class FileStorageTest extends PhpStorageTestBase {
*/
function testCRUD() {
$php = $this->storageFactory->get('simpletest');
$this->assertIdentical(get_class($php), 'Drupal\Component\PhpStorage\FileStorage');
$this->assertInstanceOf('Drupal\Component\PhpStorage\FileStorage', $php);
$this->assertCRUD($php);
}
@ -60,14 +60,14 @@ class FileStorageTest extends PhpStorageTestBase {
// Write out a PHP file and ensure it's successfully loaded.
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
$success = $php->save($name, $code);
$this->assertIdentical($success, TRUE);
$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->assertIdentical($php_read->exists($name), TRUE);
$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));

View File

@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\system\Tests\PhpStorage\MTimeProtectedFileStorageTest.
* Definition of Drupal\Tests\Component\PhpStorage\MTimeProtectedFileStorageTest.
*/
namespace Drupal\system\Tests\PhpStorage;
namespace Drupal\Tests\Component\PhpStorage;
/**
* Tests the directory mtime based PHP loader implementation.

View File

@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\system\Tests\PhpStorage\MTimeProtectedFileStorageTest.
* Definition of Drupal\Tests\Component\PhpStorage\MTimeProtectedFileStorageTest.
*/
namespace Drupal\system\Tests\PhpStorage;
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\PhpStorage\PhpStorageFactory;
@ -38,7 +38,7 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
$this->secret = $this->randomName();
$conf['php_storage']['simpletest'] = array(
'class' => $this->storageClass,
'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php',
'directory' => sys_get_temp_dir() . '/php',
'secret' => $this->secret,
);
}
@ -48,7 +48,7 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
*/
function testCRUD() {
$php = $this->storageFactory->get('simpletest');
$this->assertIdentical(get_class($php), $this->storageClass);
$this->assertSame(get_class($php), $this->storageClass);
$this->assertCRUD($php);
}
@ -62,7 +62,7 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
$php = $this->storageFactory->get('simpletest');
$name = 'simpletest.php';
$php->save($name, '<?php');
$expected_root_directory = DRUPAL_ROOT . '/' . $this->public_files_directory . '/php/simpletest';
$expected_root_directory = sys_get_temp_dir() . '/php/simpletest';
$expected_directory = $expected_root_directory . '/' . $name;
$directory_mtime = filemtime($expected_directory);
$expected_filename = $expected_directory . '/' . hash_hmac('sha256', $name, $this->secret . $directory_mtime) . '.php';
@ -71,12 +71,12 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
// minimal permissions. fileperms() can return high bits unrelated to
// permissions, so mask with 0777.
$this->assertTrue(file_exists($expected_filename));
$this->assertIdentical(fileperms($expected_filename) & 0777, 0400);
$this->assertIdentical(fileperms($expected_directory) & 0777, 0100);
$this->assertSame(fileperms($expected_filename) & 0777, 0400);
$this->assertSame(fileperms($expected_directory) & 0777, 0100);
// Ensure the root directory for the bin has a .htaccess file denying web
// access.
$this->assertIdentical(file_get_contents($expected_root_directory . '/.htaccess'), "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nDeny from all\nOptions None\nOptions +FollowSymLinks");
$this->assertSame(file_get_contents($expected_root_directory . '/.htaccess'), "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nDeny from all\nOptions None\nOptions +FollowSymLinks");
// Ensure that if the file is replaced with an untrusted one (due to another
// script's file upload vulnerability), it does not get loaded. Since mtime
@ -103,10 +103,10 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
}
chmod($expected_filename, 0400);
chmod($expected_directory, 0100);
$this->assertIdentical(file_get_contents($expected_filename), $untrusted_code);
$this->assertIdentical($php->exists($name), $this->expected[$i]);
$this->assertIdentical($php->load($name), $this->expected[$i]);
$this->assertIdentical($GLOBALS['hacked'], $this->expected[$i]);
$this->assertSame(file_get_contents($expected_filename), $untrusted_code);
$this->assertSame($php->exists($name), $this->expected[$i]);
$this->assertSame($php->load($name), $this->expected[$i]);
$this->assertSame($GLOBALS['hacked'], $this->expected[$i]);
}
}
}

View File

@ -2,18 +2,18 @@
/**
* @file
* Definition of Drupal\system\Tests\PhpStorage\PhpStorageTestBase.
* Definition of Drupal\Tests\Component\PhpStorage\PhpStorageTestBase.
*/
namespace Drupal\system\Tests\PhpStorage;
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\simpletest\UnitTestBase;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\PhpStorage\PhpStorageFactory;
/**
* Base test for PHP storage controllers.
*/
abstract class PhpStorageTestBase extends UnitTestBase {
abstract class PhpStorageTestBase extends UnitTestCase {
/**
* The storage factory object.
@ -23,7 +23,7 @@ abstract class PhpStorageTestBase extends UnitTestBase {
protected $storageFactory;
/**
* Overrides \Drupal\simpletest\UnitTestBase::setUp()
* Overrides \Drupal\Tests\UnitTestCase::setUp()
*/
function setUp() {
parent::setUp();
@ -44,21 +44,21 @@ abstract class PhpStorageTestBase extends UnitTestBase {
// Write out a PHP file and ensure it's successfully loaded.
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
$success = $php->save($name, $code);
$this->assertIdentical($success, TRUE);
$this->assertSame($success, TRUE);
$php->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->assertIdentical($php->exists($name), TRUE);
$this->assertSame($php->exists($name), TRUE);
// Delete the file, and then ensure exists() returns FALSE.
$success = $php->delete($name);
$this->assertIdentical($success, TRUE);
$this->assertIdentical($php->exists($name), FALSE);
$this->assertSame($success, TRUE);
$this->assertSame($php->exists($name), FALSE);
// Ensure delete() can be called on a non-existing file. It should return
// FALSE, but not trigger errors.
$this->assertIdentical($php->delete($name), FALSE);
$this->assertSame($php->delete($name), FALSE);
}
}