summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-07-13 08:32:51 (GMT)
committerAlex Pott2014-07-13 08:32:51 (GMT)
commit7fe5f2ac1e5d4ff2f41fdd9cc8a42579ae531a57 (patch)
tree76a7ce018c62d219625ff8eaec18708fbf9ed075
parent158863a08ce36598901978148c8366d2bf4e685e (diff)
Issue #2080311 by rhm50, amitgoyal, InternetDevels, Rajesh Ashok, pfrenssen, natemow, areke, chertzog | mrsinguyen: Clean up Drupal\system\Tests\Database\SelectTest.php.
-rw-r--r--core/modules/system/src/Tests/Database/SelectTest.php37
1 files changed, 13 insertions, 24 deletions
diff --git a/core/modules/system/src/Tests/Database/SelectTest.php b/core/modules/system/src/Tests/Database/SelectTest.php
index 996d269..3579f83 100644
--- a/core/modules/system/src/Tests/Database/SelectTest.php
+++ b/core/modules/system/src/Tests/Database/SelectTest.php
@@ -20,14 +20,9 @@ class SelectTest extends DatabaseTestBase {
*/
function testSimpleSelect() {
$query = db_select('test');
- $name_field = $query->addField('test', 'name');
- $age_field = $query->addField('test', 'age', 'age');
- $result = $query->execute();
-
- $num_records = 0;
- foreach ($result as $record) {
- $num_records++;
- }
+ $query->addField('test', 'name');
+ $query->addField('test', 'age', 'age');
+ $num_records = $query->countQuery()->execute()->fetchField();
$this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
@@ -37,19 +32,16 @@ class SelectTest extends DatabaseTestBase {
*/
function testSimpleComment() {
$query = db_select('test')->comment('Testing query comments');
- $name_field = $query->addField('test', 'name');
- $age_field = $query->addField('test', 'age', 'age');
+ $query->addField('test', 'name');
+ $query->addField('test', 'age', 'age');
$result = $query->execute();
- $num_records = 0;
- foreach ($result as $record) {
- $num_records++;
- }
+ $records = $result->fetchAll();
- $query = (string)$query;
+ $query = (string) $query;
$expected = "/* Testing query comments */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
- $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
+ $this->assertEqual(count($records), 4, 'Returned the correct number of rows.');
$this->assertEqual($query, $expected, 'The flattened query contains the comment string.');
}
@@ -58,19 +50,16 @@ class SelectTest extends DatabaseTestBase {
*/
function testVulnerableComment() {
$query = db_select('test')->comment('Testing query comments */ SELECT nid FROM {node}; --');
- $name_field = $query->addField('test', 'name');
- $age_field = $query->addField('test', 'age', 'age');
+ $query->addField('test', 'name');
+ $query->addField('test', 'age', 'age');
$result = $query->execute();
- $num_records = 0;
- foreach ($result as $record) {
- $num_records++;
- }
+ $records = $result->fetchAll();
- $query = (string)$query;
+ $query = (string) $query;
$expected = "/* Testing query comments SELECT nid FROM {node}; -- */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
- $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
+ $this->assertEqual(count($records), 4, 'Returned the correct number of rows.');
$this->assertEqual($query, $expected, 'The flattened query contains the sanitised comment string.');
}