updated drupal core to 7.51
This commit is contained in:
@@ -70,6 +70,15 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
|
||||
'Proxy forwarding with trusted proxy got forwarded IP address.'
|
||||
);
|
||||
|
||||
// Proxy forwarding on and proxy address trusted and visiting from proxy.
|
||||
$_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = $this->proxy_ip;
|
||||
drupal_static_reset('ip_address');
|
||||
$this->assertTrue(
|
||||
ip_address() == $this->proxy_ip,
|
||||
'Visiting from trusted proxy got proxy IP address.'
|
||||
);
|
||||
|
||||
// Multi-tier architecture with comma separated values in header.
|
||||
$_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = implode(', ', array($this->untrusted_ip, $this->forwarded_ip, $this->proxy2_ip));
|
||||
@@ -191,7 +200,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
|
||||
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
|
||||
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Caching was bypassed.');
|
||||
$this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, 'Vary: Cookie header was not sent.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Cache-Control header was sent.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate', 'Cache-Control header was sent.');
|
||||
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
|
||||
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.');
|
||||
|
||||
@@ -379,12 +388,19 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Get filename test',
|
||||
'description' => 'Test that drupal_get_filename() works correctly when the file is not found in the database.',
|
||||
'name' => 'Get filename test (without the system table)',
|
||||
'description' => 'Test that drupal_get_filename() works correctly when the database is not available.',
|
||||
'group' => 'Bootstrap',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The last file-related error message triggered by the filename test.
|
||||
*
|
||||
* Used by BootstrapGetFilenameTestCase::testDrupalGetFilename().
|
||||
*/
|
||||
protected $getFilenameTestTriggeredError;
|
||||
|
||||
/**
|
||||
* Test that drupal_get_filename() works correctly when the file is not found in the database.
|
||||
*/
|
||||
@@ -414,6 +430,203 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
|
||||
// automatically check there for 'script' files, just as it does for (e.g.)
|
||||
// 'module' files in modules.
|
||||
$this->assertIdentical(drupal_get_filename('script', 'test'), 'scripts/test.script', t('Retrieve test script location.'));
|
||||
|
||||
// When searching for a module that does not exist, drupal_get_filename()
|
||||
// should return NULL and trigger an appropriate error message.
|
||||
$this->getFilenameTestTriggeredError = NULL;
|
||||
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
|
||||
$non_existing_module = $this->randomName();
|
||||
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL.');
|
||||
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for an item that does not exist triggers the correct error.');
|
||||
restore_error_handler();
|
||||
|
||||
// Check that the result is stored in the file system scan cache.
|
||||
$file_scans = _drupal_file_scan_cache();
|
||||
$this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files static variable.');
|
||||
|
||||
// Performing the search again in the same request still should not find
|
||||
// the file, but the error message should not be repeated (therefore we do
|
||||
// not override the error handler here).
|
||||
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL during the second search.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips handling of "file not found" errors.
|
||||
*/
|
||||
public function fileNotFoundErrorHandler($error_level, $message, $filename, $line, $context) {
|
||||
// Skip error handling if this is a "file not found" error.
|
||||
if (strpos($message, 'is missing from the file system:') !== FALSE || strpos($message, 'has moved within the file system:') !== FALSE) {
|
||||
$this->getFilenameTestTriggeredError = $message;
|
||||
return;
|
||||
}
|
||||
_drupal_error_handler($error_level, $message, $filename, $line, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test drupal_get_filename() in the context of a full Drupal installation.
|
||||
*/
|
||||
class BootstrapGetFilenameWebTestCase extends DrupalWebTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Get filename test (full installation)',
|
||||
'description' => 'Test that drupal_get_filename() works correctly in the context of a full Drupal installation.',
|
||||
'group' => 'Bootstrap',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('system_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* The last file-related error message triggered by the filename test.
|
||||
*
|
||||
* Used by BootstrapGetFilenameWebTestCase::testDrupalGetFilename().
|
||||
*/
|
||||
protected $getFilenameTestTriggeredError;
|
||||
|
||||
/**
|
||||
* Test that drupal_get_filename() works correctly with a full Drupal site.
|
||||
*/
|
||||
function testDrupalGetFilename() {
|
||||
// Search for a module that exists in the file system and the {system}
|
||||
// table and make sure that it is found.
|
||||
$this->assertIdentical(drupal_get_filename('module', 'node'), 'modules/node/node.module', 'Module found at expected location.');
|
||||
|
||||
// Search for a module that does not exist in either the file system or the
|
||||
// {system} table. Make sure that an appropriate error is triggered and
|
||||
// that the module winds up in the static and persistent cache.
|
||||
$this->getFilenameTestTriggeredError = NULL;
|
||||
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
|
||||
$non_existing_module = $this->randomName();
|
||||
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL.');
|
||||
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for a module that does not exist triggers the correct error.');
|
||||
restore_error_handler();
|
||||
$file_scans = _drupal_file_scan_cache();
|
||||
$this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files static variable.');
|
||||
drupal_file_scan_write_cache();
|
||||
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
|
||||
$this->assertIdentical($cache->data['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files persistent cache.');
|
||||
|
||||
// Simulate moving a module to a location that does not match the location
|
||||
// in the {system} table and perform similar tests as above.
|
||||
db_update('system')
|
||||
->fields(array('filename' => 'modules/simpletest/tests/fake_location/module_test.module'))
|
||||
->condition('name', 'module_test')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
$this->getFilenameTestTriggeredError = NULL;
|
||||
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
|
||||
$this->assertIdentical(drupal_get_filename('module', 'module_test'), 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved finds the module at its new location.');
|
||||
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module has moved within the file system: %name', array('%name' => 'module_test'))) === 0, 'Searching for a module that has moved triggers the correct error.');
|
||||
restore_error_handler();
|
||||
$file_scans = _drupal_file_scan_cache();
|
||||
$this->assertIdentical($file_scans['module']['module_test'], 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved creates a record in the missing and moved files static variable.');
|
||||
drupal_file_scan_write_cache();
|
||||
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
|
||||
$this->assertIdentical($cache->data['module']['module_test'], 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved creates a record in the missing and moved files persistent cache.');
|
||||
|
||||
// Simulate a module that exists in the {system} table but does not exist
|
||||
// in the file system and perform similar tests as above.
|
||||
$non_existing_module = $this->randomName();
|
||||
db_update('system')
|
||||
->fields(array('name' => $non_existing_module))
|
||||
->condition('name', 'module_test')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
$this->getFilenameTestTriggeredError = NULL;
|
||||
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
|
||||
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that exists in the system table but not in the file system returns NULL.');
|
||||
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for a module that exists in the system table but not in the file system triggers the correct error.');
|
||||
restore_error_handler();
|
||||
$file_scans = _drupal_file_scan_cache();
|
||||
$this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that exists in the system table but not in the file system creates a record in the missing and moved files static variable.');
|
||||
drupal_file_scan_write_cache();
|
||||
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
|
||||
$this->assertIdentical($cache->data['module'][$non_existing_module], FALSE, 'Searching for a module that exists in the system table but not in the file system creates a record in the missing and moved files persistent cache.');
|
||||
|
||||
// Simulate a module that exists in the file system but not in the {system}
|
||||
// table and perform similar tests as above.
|
||||
db_delete('system')
|
||||
->condition('name', 'common_test')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
system_list_reset();
|
||||
$this->getFilenameTestTriggeredError = NULL;
|
||||
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
|
||||
$this->assertIdentical(drupal_get_filename('module', 'common_test'), 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table finds the module at its actual location.');
|
||||
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module has moved within the file system: %name', array('%name' => 'common_test'))) === 0, 'Searching for a module that does not exist in the system table triggers the correct error.');
|
||||
restore_error_handler();
|
||||
$file_scans = _drupal_file_scan_cache();
|
||||
$this->assertIdentical($file_scans['module']['common_test'], 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table creates a record in the missing and moved files static variable.');
|
||||
drupal_file_scan_write_cache();
|
||||
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
|
||||
$this->assertIdentical($cache->data['module']['common_test'], 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table creates a record in the missing and moved files persistent cache.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips handling of "file not found" errors.
|
||||
*/
|
||||
public function fileNotFoundErrorHandler($error_level, $message, $filename, $line, $context) {
|
||||
// Skip error handling if this is a "file not found" error.
|
||||
if (strpos($message, 'is missing from the file system:') !== FALSE || strpos($message, 'has moved within the file system:') !== FALSE) {
|
||||
$this->getFilenameTestTriggeredError = $message;
|
||||
return;
|
||||
}
|
||||
_drupal_error_handler($error_level, $message, $filename, $line, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that watchdog messages about missing files are correctly recorded.
|
||||
*/
|
||||
public function testWatchdog() {
|
||||
// Search for a module that does not exist in either the file system or the
|
||||
// {system} table. Make sure that an appropriate warning is recorded in the
|
||||
// logs.
|
||||
$non_existing_module = $this->randomName();
|
||||
$query_parameters = array(
|
||||
':type' => 'php',
|
||||
':severity' => WATCHDOG_WARNING,
|
||||
);
|
||||
$this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND severity = :severity', $query_parameters)->fetchField(), 0, 'No warning message appears in the logs before searching for a module that does not exist.');
|
||||
// Trigger the drupal_get_filename() call. This must be done via a request
|
||||
// to a separate URL since the watchdog() will happen in a shutdown
|
||||
// function, and so that SimpleTest can be told to ignore (and not fail as
|
||||
// a result of) the expected PHP warnings generated during this process.
|
||||
variable_set('system_test_drupal_get_filename_test_module_name', $non_existing_module);
|
||||
$this->drupalGet('system-test/drupal-get-filename');
|
||||
$message_variables = db_query('SELECT variables FROM {watchdog} WHERE type = :type AND severity = :severity', $query_parameters)->fetchCol();
|
||||
$this->assertEqual(count($message_variables), 1, 'A single warning message appears in the logs after searching for a module that does not exist.');
|
||||
$variables = reset($message_variables);
|
||||
$variables = unserialize($variables);
|
||||
$this->assertTrue(isset($variables['!message']) && strpos($variables['!message'], format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) !== FALSE, 'The warning message that appears in the logs after searching for a module that does not exist contains the expected text.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that drupal_get_filename() does not break recursive rebuilds.
|
||||
*/
|
||||
public function testRecursiveRebuilds() {
|
||||
// Ensure that the drupal_get_filename() call due to a missing module does
|
||||
// not break the data returned by an attempted recursive rebuild. The code
|
||||
// path which is tested is as follows:
|
||||
// - Call drupal_get_schema().
|
||||
// - Within a hook_schema() implementation, trigger a drupal_get_filename()
|
||||
// search for a nonexistent module.
|
||||
// - In the watchdog() call that results from that, trigger
|
||||
// drupal_get_schema() again.
|
||||
// Without some kind of recursion protection, this could cause the second
|
||||
// drupal_get_schema() call to return incomplete results. This test ensures
|
||||
// that does not happen.
|
||||
$non_existing_module = $this->randomName();
|
||||
variable_set('system_test_drupal_get_filename_test_module_name', $non_existing_module);
|
||||
$this->drupalGet('system-test/drupal-get-filename-with-schema-rebuild');
|
||||
$original_drupal_get_schema_tables = variable_get('system_test_drupal_get_filename_with_schema_rebuild_original_tables');
|
||||
$final_drupal_get_schema_tables = variable_get('system_test_drupal_get_filename_with_schema_rebuild_final_tables');
|
||||
$this->assertTrue(!empty($original_drupal_get_schema_tables));
|
||||
$this->assertTrue(!empty($final_drupal_get_schema_tables));
|
||||
$this->assertEqual($original_drupal_get_schema_tables, $final_drupal_get_schema_tables);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user