diff options
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r-- | modules/simpletest/tests/database_test.module | 12 | ||||
-rw-r--r-- | modules/simpletest/tests/database_test.test | 26 |
2 files changed, 30 insertions, 8 deletions
diff --git a/modules/simpletest/tests/database_test.module b/modules/simpletest/tests/database_test.module index 25631e0c7..573075078 100644 --- a/modules/simpletest/tests/database_test.module +++ b/modules/simpletest/tests/database_test.module @@ -44,7 +44,7 @@ function database_test_query_database_test_alter_remove_range_alter(QueryAlterab * Implementation of hook_menu(). */ function database_test_menu() { - $items['database_test_db_query_temporary'] = array( + $items['database_test/db_query_temporary'] = array( 'access callback' => TRUE, 'page callback' => 'database_test_db_query_temporary', ); @@ -52,15 +52,17 @@ function database_test_menu() { } /** - * Run a db_query_temporary and print the number of rows in the resulting table. + * Run a db_query_temporary and output the table name and its number of rows. * * We need to test that the table created is temporary, so we run it here, in a * separate menu callback request; After this request is done, the temporary * table should automatically dropped. */ function database_test_db_query_temporary() { - db_query_temporary('SELECT status FROM {system}', array(), 'temporary'); - print db_query('SELECT COUNT(*) FROM temporary')->fetchField(); + $table_name = db_query_temporary('SELECT status FROM {system}', array()); + drupal_json(array( + 'table_name' => $table_name, + 'row_count' => db_select($table_name)->countQuery()->execute()->fetchField(), + )); exit; } - diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 5df638346..8451f83f1 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -1934,12 +1934,32 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase { } /** + * Return the number of rows of a table. + */ + function countTableRows($table_name) { + return db_select($table_name)->countQuery()->execute()->fetchField(); + } + + /** * Confirm that temporary tables work and are limited to one request. */ function testTemporaryQuery() { - $this->drupalGet('database_test_db_query_temporary'); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {system}')->fetchField(), $this->drupalGetContent(), t('The temporary table exists and contains the correct amount of rows.')); - $this->assertFalse(db_table_exists('temporary'), t('The temporary table is, indeed, temporary.')); + $this->drupalGet('database_test/db_query_temporary'); + $data = json_decode($this->drupalGetContent()); + if ($data) { + $this->assertEqual($this->countTableRows("system"), $data->row_count, t('The temporary table contains the correct amount of rows.')); + $this->assertFalse(db_table_exists($data->table_name), t('The temporary table is, indeed, temporary.')); + } + else { + $this->fail(t("The creation of the temporary table failed.")); + } + + // Now try to run two db_query_temporary() in the same request. + $table_name_system = db_query_temporary('SELECT status FROM {system}', array()); + $table_name_users = db_query_temporary('SELECT uid FROM {users}', array()); + + $this->assertEqual($this->countTableRows($table_name_system), $this->countTableRows("system"), t('A temporary table was created successfully in this request.')); + $this->assertEqual($this->countTableRows($table_name_users), $this->countTableRows("users"), t('A second temporary table was created successfully in this request.')); } } |