You are here

coder_sql.test in Coder 6

Same filename and directory in other branches
  1. 6.2 tests/coder_sql.test

File

tests/coder_sql.test
View source
<?php

require_once dirname(__FILE__) . '/coder_test_case.tinc';
class CoderSQLTest extends CoderTestCase {
  function __construct($id = NULL) {
    parent::__construct('sql', $id);
  }
  function getInfo() {
    return array(
      'name' => t('Coder SQL Tests'),
      'description' => t('Tests for the coder SQL review.'),
      'group' => t('Coder'),
    );
  }
  function testSQLLowerCaseKeywords() {
    $this
      ->assertCoderFail('  $sql = "select * from {node}";');
    $this
      ->assertCoderFail('  $sql = "insert into {node} (changed) VALUES (%d)";');
    $this
      ->assertCoderFail('  $sql = "delete from {node}";');
    $this
      ->assertCoderFail('  $sql = "update {node} set changed = now()";');
    $this
      ->assertCoderFail('  $var = t("select something from this");');
    $this
      ->assertCoderPass('  $var = t("update something");');
    $this
      ->assertCoderPass('  $var = t("insert something");');
    $this
      ->assertCoderPass('  $var = t("delete something");');
  }
  function testSQLBracketNode() {
    $this
      ->assertCoderFail('  $sql = "INSERT INTO node (changed) VALUES (1)";');
    $this
      ->assertCoderPass('  $sql = "INSERT INTO {node} (changed) VALUES (1)";');
  }
  function testSQLLimit() {
    $this
      ->assertCoderFail('  $sql = "SELECT * FROM {node} LIMIT 10";');
  }
  function testSQLBackTick() {
    $this
      ->assertCoderFail('  $sql = "SELECT * FROM {node} WHERE title=`abc`";');
    $this
      ->assertCoderFail('  $sql = "INSERT INTO {foo} (nid, title) VALUES (\'1\', `abc`)";');
    $this
      ->assertCoderFail('  $sql = "INSERT INTO {foo} VALUES (\'1\', `abc`)";');
    $this
      ->assertCoderFail('  $sql = "UPDATE {foo} SET nid=\'1\', title=`abc`";');
    $this
      ->assertCoderFail('  $sql = "DELETE FROM {foo} WHERE nid=\'1\' AND title=`abc`";');
  }

}

Classes

Namesort descending Description
CoderSQLTest