Skip to content

Commit

Permalink
MDL-52060 phpunit: Prevent querying database metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
polothy authored and Rajesh Taneja committed Dec 22, 2015
1 parent 22d55b3 commit d494306
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/dml/moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ protected function print_debug_time() {
protected function where_clause($table, array $conditions=null) {
// We accept nulls in conditions
$conditions = is_null($conditions) ? array() : $conditions;

if (empty($conditions)) {
return array('', array());
}

// Some checks performed under debugging only
if (debugging()) {
$columns = $this->get_columns($table);
Expand All @@ -600,9 +605,6 @@ protected function where_clause($table, array $conditions=null) {
}

$allowed_types = $this->allowed_param_types();
if (empty($conditions)) {
return array('', array());
}
$where = array();
$params = array();

Expand Down
6 changes: 3 additions & 3 deletions lib/dml/tests/dml_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1432,9 +1432,9 @@ public function test_get_records() {
$this->assertSame('ddltablenotexist', $e->errorcode);
}
}
// And without params.

try {
$records = $DB->get_records('xxxx', array());
$records = $DB->get_records('xxxx', array('id' => '1'));
$this->fail('An Exception is missing, expected due to query against non-existing table');
} catch (moodle_exception $e) {
$this->assertInstanceOf('dml_exception', $e);
Expand Down Expand Up @@ -5347,7 +5347,7 @@ public function test_queries_counter() {

// The get_records() method generates 2 queries the first time is called
// as it is fetching the table structure.
$whatever = $DB->get_records($tablename);
$whatever = $DB->get_records($tablename, array('id' => '1'));
$this->assertEquals($initreads + 3, $DB->perf_get_reads());
$this->assertEquals($initwrites, $DB->perf_get_writes());

Expand Down

0 comments on commit d494306

Please sign in to comment.