coder_review_sql.test in Coder 7
File
coder_review/tests/coder_review_sql.test
View source
<?php
require_once dirname(__FILE__) . '/coder_review_test_case.tinc';
class CoderReviewSQLTest extends CoderReviewTestCase {
function __construct($id = NULL) {
parent::__construct('sql', $id);
}
public static function getInfo() {
return array(
'name' => t('Coder SQL Tests'),
'description' => t('Tests for the coder SQL review.'),
'group' => t('Coder'),
);
}
function testSQLLowerCaseKeywords() {
$this
->assertCoderReviewFail(' $sql = "select * from {node}";');
$this
->assertCoderReviewFail(' $sql = "insert into {node} (changed) VALUES (%d)";');
$this
->assertCoderReviewFail(' $sql = "delete from {node}";');
$this
->assertCoderReviewFail(' $sql = "update {node} set changed = now()";');
$this
->assertCoderReviewFail(' $var = t("select something from this");');
$this
->assertCoderReviewPass(' $var = t("update something");');
$this
->assertCoderReviewPass(' $var = t("insert something");');
$this
->assertCoderReviewPass(' $var = t("delete something");');
}
function testSQLBracketNode() {
$this
->assertCoderReviewFail(' $sql = "INSERT INTO node (changed) VALUES (1)";');
$this
->assertCoderReviewPass(' $sql = "INSERT INTO {node} (changed) VALUES (1)";');
}
function testSQLLimit() {
$this
->assertCoderReviewFail(' $sql = "SELECT * FROM {node} LIMIT 10";');
}
function testSelectCOUNT() {
$this
->assertCoderReviewFail(" db_query('SELECT COUNT(*) FROM {users}')");
}
function testSQLBackTick() {
$this
->assertCoderReviewFail(' $sql = "SELECT * FROM {node} WHERE title=`abc`";');
$this
->assertCoderReviewFail(' $sql = "INSERT INTO {foo} (nid, title) VALUES (\'1\', `abc`)";');
$this
->assertCoderReviewFail(' $sql = "INSERT INTO {foo} VALUES (\'1\', `abc`)";');
$this
->assertCoderReviewFail(' $sql = "UPDATE {foo} SET nid=\'1\', title=`abc`";');
$this
->assertCoderReviewFail(' $sql = "DELETE FROM {foo} WHERE nid=\'1\' AND title=`abc`";');
}
function testSQLNotEquals() {
$this
->assertCoderReviewFail(' $sql = "SELECT * FROM {node} WHERE nid != 10";');
$this
->assertCoderReviewPass(' $sql = "SELECT * FROM {node} WHERE nid = 10";');
$this
->assertCoderReviewPass(' $sql = "SELECT * FROM {node} WHERE nid <> 10";');
}
}