diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-08-21 19:36:39 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-08-21 19:36:39 +0000 |
commit | 69e6f411a9ed5dcf3f71d4320218620d3444d295 (patch) | |
tree | f4d393bbda7d814c825878785221b65c73b225f8 /modules/simpletest | |
parent | 0e79597812ad0b6b72cf65bfc928c4a591d80ff1 (diff) | |
download | brdo-69e6f411a9ed5dcf3f71d4320218620d3444d295.tar.gz brdo-69e6f411a9ed5dcf3f71d4320218620d3444d295.tar.bz2 |
- Patch #225450 by Crell, chx, bjaspan, catch, swentel, recidive et al: next generation database layer for Drupal 7.
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 18 | ||||
-rw-r--r-- | modules/simpletest/simpletest.module | 14 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 7 | ||||
-rw-r--r-- | modules/simpletest/tests/database.test | 182 |
4 files changed, 25 insertions, 196 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 1e4a950ce..6279d59b4 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -70,7 +70,16 @@ class DrupalWebTestCase { } $current_db_prefix = $db_prefix; $db_prefix = $this->db_prefix_original; - db_query("INSERT INTO {simpletest} (test_id, test_class, status, message, message_group, caller, line, file) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $this->test_id, get_class($this), $status, $message, $group, $function['function'], $function['line'], $function['file']); + db_insert('simpletest')->fields(array( + 'test_id' => $this->test_id, + 'test_class' => get_class($this), + 'status' => $status, + 'message' => substr($message, 0, 255), // Some messages are too long for the database. + 'message_group' => $group, + 'caller' => $function['function'], + 'line' => $function['line'], + 'file' => $function['file'], + ))->execute(); $this->_assertions[] = array( 'status' => $status, 'message' => $message, @@ -631,6 +640,7 @@ class DrupalWebTestCase { // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = 'simpletest' . mt_rand(1000, 1000000); + include_once './includes/install.inc'; drupal_install_system(); @@ -639,6 +649,12 @@ class DrupalWebTestCase { $modules = array_unique(array_merge(drupal_verify_profile('default', 'en'), $args)); drupal_install_modules($modules); + // Because the schema is static cached, we need to flush + // it between each run. If we don't, then it will contain + // stale data for the previous run's database prefix and all + // calls to it will fail. + drupal_get_schema(NULL, TRUE); + // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 05907d454..3decbfe76 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -312,8 +312,7 @@ function simpletest_test_form_submit($form, &$form_state) { function simpletest_run_tests($test_list, $reporter = 'drupal', $batch_mode = FALSE) { global $db_prefix, $db_prefix_original; cache_clear_all(); - db_query('INSERT INTO {simpletest_test_id} VALUES (default)'); - $test_id = db_last_insert_id('simpletest_test_id', 'test_id'); + $test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute(); if ($batch_mode) { $batch = array( @@ -501,11 +500,14 @@ function simpletest_clean_database() { * @return mixed Array of matching tables or count of tables. */ function simpletest_get_like_tables($base_table = 'simpletest', $count = FALSE) { - global $db_url, $db_prefix; - $url = parse_url($db_url); - $database = substr($url['path'], 1); + global $db_prefix, $database; + $connection_info = Database::getConnectionInfo(); + $database_name = $connection_info['default']['database']; $select = $count ? 'COUNT(table_name)' : 'table_name'; - $result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = '$database' AND table_name LIKE '$db_prefix$base_table%'"); + $result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array( + ':database' => $database_name, + ':table_name' => $db_prefix . $base_table . '%', + )); $schema = drupal_get_schema_unprocessed('simpletest'); if ($count) { diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index dc76829e5..d9c6ceaa1 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -130,17 +130,10 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase { } function testDrupalHTTPRequest() { - // Parse URL schema. $missing_scheme = drupal_http_request('example.com/path'); $this->assertEqual($missing_scheme->error, 'missing schema', t('Returned with missing scheme error.')); $unable_to_parse = drupal_http_request('http:///path'); $this->assertEqual($unable_to_parse->error, 'unable to parse URL', t('Returned with unable to parse URL error.')); - - // Fetch page. - $result = drupal_http_request(url('node', array('absolute' => TRUE))); - $this->assertEqual($result->code, 200, t('Fetched page successfully.')); - $this->drupalSetContent($result->data); - $this->assertTitle(variable_get('site_name', 'Drupal'), t('Site title matches.')); } } diff --git a/modules/simpletest/tests/database.test b/modules/simpletest/tests/database.test deleted file mode 100644 index 83bb3a123..000000000 --- a/modules/simpletest/tests/database.test +++ /dev/null @@ -1,182 +0,0 @@ -<?php -// $Id$ - -class DatabaseSecurityTestCase extends DrupalWebTestCase { - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Database placeholders'), - 'description' => t('Make sure that invalid values do not get passed through the %n, %d, or %f placeholders.'), - 'group' => t('System') - ); - } - - function testPlaceholders() { - // First test the numeric type - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543.21, - '123.456' => 123.46, - '+0.1e3' => 0.1e3, - ); - $not_valid = array( - '1x' => 0, - '4.4 OR 1=1' => 0, - '9 9' => 0, - '0xff' => 0, - 'XXX' => 0, - '0Xaa' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 0, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'numeric', - 'precision' => 5, - 'scale' => 2, - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_numeric', $schema); - $insert_query = 'INSERT INTO {test_numeric} (n) VALUES (' . db_type_placeholder('numeric') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_numeric}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}')); - $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_numeric}')); - $this->assertEqual($select, $test, "[numeric] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_numeric}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}')); - $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_numeric}')); - $this->assertEqual(0, $test, "[numeric] Got $select ($test) after inserting invalid value $insert"); - } - - // Test ints - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543, - '123.456' => 123, - '22' => 22, - ); - $not_valid = array( - '+0.1e3' => 0, - '0xff' => 0, - '0Xaa' => 0, - '1x' => 1, - '4.4 OR 1=1' => 4, - '9 9' => 9, - 'XXX' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 44, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'int', - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_int', $schema); - $insert_query = 'INSERT INTO {test_int} (n) VALUES (' . db_type_placeholder('int') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_int}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}')); - $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_int}')); - $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_int}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}')); - $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_int}')); - $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting invalid value $insert"); - } - - // Test floats - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543.21, - '123.456' => 123.456, - '22' => 22, - '+0.1e3' => 100, - ); - $not_valid = array( - '0xff' => 0, - '0Xaa' => 0, - '1x' => 1, - '4.4 OR 1=1' => 4.4, - '9 9' => 9, - 'XXX' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 44, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'float', - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_float', $schema); - $insert_query = 'INSERT INTO {test_float} (n) VALUES (' . db_type_placeholder('float') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_float}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}')); - $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_float}')); - $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_float}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}')); - $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_float}')); - $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting invalid value $insert"); - } - - } -} |