You are here

class CoderReviewStyleTest in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_review/tests/coder_review_style.test \CoderReviewStyleTest

Hierarchy

Expanded class hierarchy of CoderReviewStyleTest

File

coder_review/tests/coder_review_style.test, line 9

View source
class CoderReviewStyleTest extends CoderReviewTestCase {
  function __construct($id = NULL) {
    parent::__construct('style', $id);
  }
  public static function getInfo() {
    return array(
      'name' => t('Coder Style Tests'),
      'description' => t('Tests for the coder style review.'),
      'group' => t('Coder'),
    );
  }
  function testStyleArrayIndex() {
    $this
      ->assertCoderReviewPass('$some_array[FOO_BAR] = $baz;');
    $this
      ->assertCoderReviewFail('$some_array[foo_bar] = $baz;');
    $this
      ->assertCoderReviewFail('  $a[hello] = "hello";');
    $this
      ->assertCoderReviewPass('  $a[\'hello\'] = "hello";');
  }
  function testStyleTabs() {
    $this
      ->assertCoderReviewPass('// Tab in	comment');
    $this
      ->assertCoderReviewPass('$var = "tab in	double quote"');
    $this
      ->assertCoderReviewPass('$var = \'tab in	single quote\'');
    $this
      ->assertCoderReviewFail('	$var = "tab in line";');
  }
  function testStyleCamelCase() {
    $this
      ->assertCoderReviewPass('  $var = new stdClass();');
    $this
      ->assertCoderReviewPass('  $var = $obj->camelCase();');
    $this
      ->assertCoderReviewFail('  $camelCase = "1";');
    $this
      ->assertCoderReviewFail('  function camelCase() {');
    $this
      ->assertCoderReviewPass("  class myClass {\nfunction camelCase() {");
    $this
      ->assertCoderReviewPass("  interface myClass {\nfunction camelCase() {");
    $this
      ->assertCoderReviewPass('  ?>This is embedded php and should Not trigger a camelCase error.<?php');
    $this
      ->assertCoderReviewPass("  ?>This second embedded php and should Not trigger\na camelCase error.<?php");
    $this
      ->assertCoderReviewPass('  $var = 0xFF;');
  }
  function testStyleBr() {
    $this
      ->assertCoderReviewFail('  print "<br>";');
    $this
      ->assertCoderReviewFail('  ?><br><?php');
  }
  function testStyleConstants() {
    $this
      ->assertCoderReviewPass('  $a = TRUE;');
    $this
      ->assertCoderReviewPass('  $atrue = "true";');
    $this
      ->assertCoderReviewFail('  $a = true;');
    $this
      ->assertCoderReviewFail('  $a =true;');
    $this
      ->assertCoderReviewFail('  if ($a == true) {');
    $this
      ->assertCoderReviewFail('    return false;');
  }
  function testStyleClosingPhp() {
    $this
      ->assertCoderReviewFail("  print 'hello';\n?>");
  }
  function testStyleTrailingSpaces() {
    $this
      ->assertCoderReviewFail('  $left = "trailing spaces follow";   ');
    $this
      ->assertCoderReviewPass('  $left = "no trailing spaces";');
  }
  function testStyleControlStructures() {
    $this
      ->assertCoderReviewFail('  if ($a == 1) { }');
    $this
      ->assertCoderReviewPass('  if ($a == 1) {');
    $this
      ->assertCoderReviewFail('  }else {');
    $this
      ->assertCoderReviewFail('  if ($a == 1) { $b = 2;');
    $this
      ->assertCoderReviewFail('  if ($a == 1) {$b = 2;');
    $this
      ->assertCoderReviewFail('  else if ($a == 1) {');
    $this
      ->assertCoderReviewPass('  elseif ($a == 1) {');
  }
  function testStyleStringConcatentation() {
    $this
      ->assertCoderReviewPass('  if ($file = file_check_upload($fieldname . "_upload")) {');
    $this
      ->assertCoderReviewFail('  if ($file = file_check_upload($fieldname ."_upload")) {');
    $this
      ->assertCoderReviewPass('  $v .= \'string\';');
    $this
      ->assertCoderReviewPass('  $a = $v . \'string\';');
    $this
      ->assertCoderReviewPass('  $a = $v . "string";');
    $this
      ->assertCoderReviewPass('  $a = "string" . $v;');
    $this
      ->assertCoderReviewPass('  $a = \'string\' . $v;');
    $this
      ->assertCoderReviewFail('  $a = "string". $v;');
    $this
      ->assertCoderReviewFail('  $a = \'string\'. $v;');
    $this
      ->assertCoderReviewFail('  $a = $v. \'string\';');
    $this
      ->assertCoderReviewFail('  $a = $v. "string";');
    $this
      ->assertCoderReviewFail('  $a = $v .\'string\';');
    $this
      ->assertCoderReviewFail('  $a = $v ."string";');
    $this
      ->assertCoderReviewFail('  $a = $v.\'string\';');
    $this
      ->assertCoderReviewFail('  $a = $v .  \'string\';');
    $this
      ->assertCoderReviewFail('  $a = $v .  "string";');
    $this
      ->assertCoderReviewFail('  $a = $v  . \'string\';');
    $this
      ->assertCoderReviewFail('  $a = $some_func(). \'string\';');
    $this
      ->assertCoderReviewPass('  $a = 1.0 * .1 * 1. * (0.1) * (1.) * (.1) * (1.0);');
  }
  function testStyleHerdocStrings() {
    $this
      ->assertCoderReviewFail("  \$var = <<< __EOD__\n<br>\n__EOD__;");
    $this
      ->assertCoderReviewFail("  \$var = <<< __EOD__\n<B>\n__EOD__;");
    $this
      ->assertCoderReviewPass("  \$var = <<< __EOD__\n<br/>\n__EOD__;");
  }

}

Members