You are here

class CoderReviewSQLTest in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_review/tests/coder_review_sql.test \CoderReviewSQLTest

Hierarchy

Expanded class hierarchy of CoderReviewSQLTest

File

coder_review/tests/coder_review_sql.test, line 9

View source
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";');
  }

}

Members