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.assertCoderReviewPass(" ?>This second embedded php and should Not trigger\na camelCase error.assertCoderReviewPass(' $var = 0xFF;'); } function testStyleBr() { $this->assertCoderReviewFail(' print "
";'); $this->assertCoderReviewFail(' ?>
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
\n__EOD__;"); $this->assertCoderReviewFail(" \$var = <<< __EOD__\n\n__EOD__;"); $this->assertCoderReviewPass(" \$var = <<< __EOD__\n
\n__EOD__;"); } }