diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test index 014fc94..c266009 100644 --- a/modules/simpletest/tests/bootstrap.test +++ b/modules/simpletest/tests/bootstrap.test @@ -267,6 +267,35 @@ class BootstrapVariableTestCase extends DrupalWebTestCase { $this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), t('The default variable parameter is passed through correctly.')); } + /** + * Test for a corrupted variable. + */ + function testFaultyVariable() { + $name = 'simpletest_bootstrap_wrong_variable_test'; + $test_value = 'unserialized_value'; + + // We write a value directly to the database bypassing the serialization + // We cannot use drupal_write_record as that serializes the value + db_merge('variable')->key(array('name' => $name))->fields(array('value' => $test_value))->execute(); + + $pass = FALSE; + try { + cache_clear_all('variables', 'cache_bootstrap'); + variable_initialize(); + } + catch (Exception $exception) { + $pass = TRUE; + } + $this->assertTrue($pass, t("Caught invalid variable setting.")); + + // Show that when variable is set correctly it returns correctly. + variable_set($name, $test_value); + cache_clear_all('variables', 'cache_bootstrap'); + variable_initialize(); + + $value = variable_get($name, 'default_value'); + $this->assertEqual($value, $test_value, 'Variable set correctly returns correct data'); + } } /**