X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FDatabase%2FTemporaryQueryTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FDatabase%2FTemporaryQueryTest.php;h=52265857904accc14c5dd289a940598ee8cc3470;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hp=0000000000000000000000000000000000000000;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a;p=yaffs-website diff --git a/web/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php b/web/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php new file mode 100644 index 000000000..522658579 --- /dev/null +++ b/web/core/modules/system/tests/src/Functional/Database/TemporaryQueryTest.php @@ -0,0 +1,55 @@ +countQuery()->execute()->fetchField(); + } + + /** + * Confirms that temporary tables work and are limited to one request. + */ + public function testTemporaryQuery() { + $this->drupalGet('database_test/db_query_temporary'); + $data = json_decode($this->getSession()->getPage()->getContent()); + if ($data) { + $this->assertEqual($this->countTableRows('test'), $data->row_count, 'The temporary table contains the correct amount of rows.'); + $this->assertFalse(db_table_exists($data->table_name), 'The temporary table is, indeed, temporary.'); + } + else { + $this->fail('The creation of the temporary table failed.'); + } + + // Now try to run two db_query_temporary() in the same request. + $table_name_test = db_query_temporary('SELECT name FROM {test}', []); + $table_name_task = db_query_temporary('SELECT pid FROM {test_task}', []); + + $this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'A temporary table was created successfully in this request.'); + $this->assertEqual($this->countTableRows($table_name_task), $this->countTableRows('test_task'), 'A second temporary table was created successfully in this request.'); + + // Check that leading whitespace and comments do not cause problems + // in the modified query. + $sql = " + -- Let's select some rows into a temporary table + SELECT name FROM {test} + "; + $table_name_test = db_query_temporary($sql, []); + $this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'Leading white space and comments do not interfere with temporary table creation.'); + } + +}