Issue #1935922 by msonnabaum: Convert PhpStorage tests to phpunit.
parent
c047547318
commit
0d3968eee2
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @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.
|
* Tests the simple file storage.
|
||||||
|
@ -23,7 +23,7 @@ class FileStorageTest extends PhpStorageTestBase {
|
||||||
function setUp() {
|
function setUp() {
|
||||||
global $conf;
|
global $conf;
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$dir_path = DRUPAL_ROOT . '/' . $this->public_files_directory . '/php';
|
$dir_path = sys_get_temp_dir() . '/php';
|
||||||
$conf['php_storage']['simpletest'] = array(
|
$conf['php_storage']['simpletest'] = array(
|
||||||
'class' => 'Drupal\Component\PhpStorage\FileStorage',
|
'class' => 'Drupal\Component\PhpStorage\FileStorage',
|
||||||
'directory' => $dir_path,
|
'directory' => $dir_path,
|
||||||
|
@ -41,7 +41,7 @@ class FileStorageTest extends PhpStorageTestBase {
|
||||||
*/
|
*/
|
||||||
function testCRUD() {
|
function testCRUD() {
|
||||||
$php = $this->storageFactory->get('simpletest');
|
$php = $this->storageFactory->get('simpletest');
|
||||||
$this->assertIdentical(get_class($php), 'Drupal\Component\PhpStorage\FileStorage');
|
$this->assertInstanceOf('Drupal\Component\PhpStorage\FileStorage', $php);
|
||||||
$this->assertCRUD($php);
|
$this->assertCRUD($php);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,14 +60,14 @@ class FileStorageTest extends PhpStorageTestBase {
|
||||||
// Write out a PHP file and ensure it's successfully loaded.
|
// Write out a PHP file and ensure it's successfully loaded.
|
||||||
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
|
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
|
||||||
$success = $php->save($name, $code);
|
$success = $php->save($name, $code);
|
||||||
$this->assertIdentical($success, TRUE);
|
$this->assertSame($success, TRUE);
|
||||||
$php_read = $this->storageFactory->get('readonly');
|
$php_read = $this->storageFactory->get('readonly');
|
||||||
$php_read->load($name);
|
$php_read->load($name);
|
||||||
$this->assertTrue($GLOBALS[$random]);
|
$this->assertTrue($GLOBALS[$random]);
|
||||||
|
|
||||||
// If the file was successfully loaded, it must also exist, but ensure the
|
// If the file was successfully loaded, it must also exist, but ensure the
|
||||||
// exists() method returns that correctly.
|
// 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.
|
// Saving and deleting should always fail.
|
||||||
$this->assertFalse($php_read->save($name, $code));
|
$this->assertFalse($php_read->save($name, $code));
|
||||||
$this->assertFalse($php_read->delete($name));
|
$this->assertFalse($php_read->delete($name));
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @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.
|
* Tests the directory mtime based PHP loader implementation.
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @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;
|
use Drupal\Component\PhpStorage\PhpStorageFactory;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
|
||||||
$this->secret = $this->randomName();
|
$this->secret = $this->randomName();
|
||||||
$conf['php_storage']['simpletest'] = array(
|
$conf['php_storage']['simpletest'] = array(
|
||||||
'class' => $this->storageClass,
|
'class' => $this->storageClass,
|
||||||
'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php',
|
'directory' => sys_get_temp_dir() . '/php',
|
||||||
'secret' => $this->secret,
|
'secret' => $this->secret,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
|
||||||
*/
|
*/
|
||||||
function testCRUD() {
|
function testCRUD() {
|
||||||
$php = $this->storageFactory->get('simpletest');
|
$php = $this->storageFactory->get('simpletest');
|
||||||
$this->assertIdentical(get_class($php), $this->storageClass);
|
$this->assertSame(get_class($php), $this->storageClass);
|
||||||
$this->assertCRUD($php);
|
$this->assertCRUD($php);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class MTimeProtectedFileStorageTest extends PhpStorageTestBase {
|
||||||
$php = $this->storageFactory->get('simpletest');
|
$php = $this->storageFactory->get('simpletest');
|
||||||
$name = 'simpletest.php';
|
$name = 'simpletest.php';
|
||||||
$php->save($name, '<?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;
|
$expected_directory = $expected_root_directory . '/' . $name;
|
||||||
$directory_mtime = filemtime($expected_directory);
|
$directory_mtime = filemtime($expected_directory);
|
||||||
$expected_filename = $expected_directory . '/' . hash_hmac('sha256', $name, $this->secret . $directory_mtime) . '.php';
|
$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
|
// minimal permissions. fileperms() can return high bits unrelated to
|
||||||
// permissions, so mask with 0777.
|
// permissions, so mask with 0777.
|
||||||
$this->assertTrue(file_exists($expected_filename));
|
$this->assertTrue(file_exists($expected_filename));
|
||||||
$this->assertIdentical(fileperms($expected_filename) & 0777, 0400);
|
$this->assertSame(fileperms($expected_filename) & 0777, 0400);
|
||||||
$this->assertIdentical(fileperms($expected_directory) & 0777, 0100);
|
$this->assertSame(fileperms($expected_directory) & 0777, 0100);
|
||||||
|
|
||||||
// Ensure the root directory for the bin has a .htaccess file denying web
|
// Ensure the root directory for the bin has a .htaccess file denying web
|
||||||
// access.
|
// 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
|
// 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
|
// 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_filename, 0400);
|
||||||
chmod($expected_directory, 0100);
|
chmod($expected_directory, 0100);
|
||||||
$this->assertIdentical(file_get_contents($expected_filename), $untrusted_code);
|
$this->assertSame(file_get_contents($expected_filename), $untrusted_code);
|
||||||
$this->assertIdentical($php->exists($name), $this->expected[$i]);
|
$this->assertSame($php->exists($name), $this->expected[$i]);
|
||||||
$this->assertIdentical($php->load($name), $this->expected[$i]);
|
$this->assertSame($php->load($name), $this->expected[$i]);
|
||||||
$this->assertIdentical($GLOBALS['hacked'], $this->expected[$i]);
|
$this->assertSame($GLOBALS['hacked'], $this->expected[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,18 +2,18 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @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;
|
use Drupal\Component\PhpStorage\PhpStorageFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test for PHP storage controllers.
|
* Base test for PHP storage controllers.
|
||||||
*/
|
*/
|
||||||
abstract class PhpStorageTestBase extends UnitTestBase {
|
abstract class PhpStorageTestBase extends UnitTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The storage factory object.
|
* The storage factory object.
|
||||||
|
@ -23,7 +23,7 @@ abstract class PhpStorageTestBase extends UnitTestBase {
|
||||||
protected $storageFactory;
|
protected $storageFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides \Drupal\simpletest\UnitTestBase::setUp()
|
* Overrides \Drupal\Tests\UnitTestCase::setUp()
|
||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -44,21 +44,21 @@ abstract class PhpStorageTestBase extends UnitTestBase {
|
||||||
// Write out a PHP file and ensure it's successfully loaded.
|
// Write out a PHP file and ensure it's successfully loaded.
|
||||||
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
|
$code = "<?php\n\$GLOBALS[$random] = TRUE;";
|
||||||
$success = $php->save($name, $code);
|
$success = $php->save($name, $code);
|
||||||
$this->assertIdentical($success, TRUE);
|
$this->assertSame($success, TRUE);
|
||||||
$php->load($name);
|
$php->load($name);
|
||||||
$this->assertTrue($GLOBALS[$random]);
|
$this->assertTrue($GLOBALS[$random]);
|
||||||
|
|
||||||
// If the file was successfully loaded, it must also exist, but ensure the
|
// If the file was successfully loaded, it must also exist, but ensure the
|
||||||
// exists() method returns that correctly.
|
// 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.
|
// Delete the file, and then ensure exists() returns FALSE.
|
||||||
$success = $php->delete($name);
|
$success = $php->delete($name);
|
||||||
$this->assertIdentical($success, TRUE);
|
$this->assertSame($success, TRUE);
|
||||||
$this->assertIdentical($php->exists($name), FALSE);
|
$this->assertSame($php->exists($name), FALSE);
|
||||||
|
|
||||||
// Ensure delete() can be called on a non-existing file. It should return
|
// Ensure delete() can be called on a non-existing file. It should return
|
||||||
// FALSE, but not trigger errors.
|
// FALSE, but not trigger errors.
|
||||||
$this->assertIdentical($php->delete($name), FALSE);
|
$this->assertSame($php->delete($name), FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue