View source
<?php
require_once dirname(__FILE__) . '/coder_review_test_case.tinc';
class CoderReviewUpgrade6xTest extends CoderReviewTestCase {
function __construct($id = NULL) {
parent::__construct('upgrade6x', $id);
}
public static function getInfo() {
return array(
'name' => t('Coder Upgrade 6.x Tests'),
'description' => t('Tests for the coder upgrade6x review.'),
'group' => t('Coder'),
);
}
function testUpgrade6x() {
$this
->assertCoderReviewFail(' function my_module_forms($args) {');
$this
->assertCoderReviewPass(' function my_module_forms($form_id, $args) {');
$this
->assertCoderReviewPass(' drupal_retrieve_form(\'testform\', $form_state);');
$this
->assertCoderReviewFail(' drupal_retrieve_form(\'testform\');');
$this
->assertCoderReviewPass(' drupal_retrieve_form($form_id, $form_state);');
$this
->assertCoderReviewFail(' drupal_retrieve_form($form_id);');
$this
->assertCoderReviewPass(' form_set_value($element, \'value\', $form_state);');
$this
->assertCoderReviewFail(' form_set_value($element, \'value\');');
$this
->assertCoderReviewFail(' function myform_prerender($form_id, $form) {');
$this
->assertCoderReviewPass(' function myform_prerender($form) {');
$this
->assertCoderReviewFail(' function myform_validate($form_id, $form_values) {');
$this
->assertCoderReviewFail(' function myform_validate($form, $form_state) {');
$this
->assertCoderReviewPass(' function myform_validate($form, $form_state);');
$this
->assertCoderReviewPass(' function myform_validate($form, &$form_state) {');
$this
->assertCoderReviewFail(' function myform_submit($form_id, $form_values) {');
$this
->assertCoderReviewFail(' function myform_submit($form, $form_state) {');
$this
->assertCoderReviewPass(' function myform_submit($form, &$form_state) {');
$this
->assertCoderReviewFail(" function myform_submit(\$form, &\$form_state) {\n return \$foo;\n}");
$this
->assertCoderReviewFail(" function myform_submit(\$form, &\$form_state) {\n return 'my/path';\n}");
$this
->assertCoderReviewFail(" function myform_submit(\$form, &\$form_state) {\n \$form['#submit']['newsubmit'] = array();\n}");
$this
->assertCoderReviewPass(" function myform_submit(\$form, &\$form_state) {\n \$form['#submit'][] = 'newsubmit';\n}");
$this
->assertCoderReviewFail(' function mymodule_form_alter($form_id, &$form) {');
$this
->assertCoderReviewPass(' function mymodule_form_alter(&$form, $form_state, $form_id) {');
$this
->assertCoderReviewFail(' $op = $form_values[\'op\'];');
$this
->assertCoderReviewFail(' $op = $form[\'op\'];');
$this
->assertCoderReviewFail(" function myform_submit() {\n \$a = \$form_values['foo'];\n}");
$this
->assertCoderReviewFail(" function myform_submit() {\n \$a = \$form['foo'];\n}");
$this
->assertCoderReviewFail(" function myform_validate() {\n \$a = \$form_values['foo'];\n}");
$this
->assertCoderReviewFail(" function myform_validate() {\n \$a = \$form['foo'];\n}");
}
function testUpgrade6xFAPI() {
$this
->assertCoderReviewFail(' $form[\'#base\'] = \'http://example.com\';');
$this
->assertCoderReviewFail(' \'#base\' => \'my_shared_form_id\',');
$this
->assertCoderReviewFail(' $form[\'#multistep\'] = TRUE;');
$this
->assertCoderReviewFail(' \'#multistep\' => TRUE,');
$this
->assertCoderReviewFail(' $form[\'#DANGEROUS_SKIP_CHECK\'] = TRUE;');
$this
->assertCoderReviewFail(' \'#DANGEROUS_SKIP_CHECK\' => TRUE,');
$this
->assertCoderReviewPass(' $form[\'#pre_render\'][] = \'my_render_function\';');
$this
->assertCoderReviewFail(' $form[\'#pre_render\'][\'my_render_function\'] = array();');
$this
->assertCoderReviewFail(' $form[\'#submit\'][\'my_submit_function\'] = array($param1, $param2);');
$this
->assertCoderReviewFail(' $form[\'#submit\'][\'my_validate_function\'] = array();');
$this
->assertCoderReviewFail(' $form[\'#validate\'][\'my_custom_validate\'] = array();');
$this
->assertCoderReviewPass(' $form[\'#validate\'][] = \'my_custom_validate\';');
$this
->assertCoderReviewFail(" function mymodule_elements() {\n return array('my_custom_form_element' => array(\n '#custom_property' => 'foo',\n '#validate' => array('my_element_validate' => array()),\n )\n);\n}");
$this
->assertCoderReviewPass(" function mymodule_elements() {\n return array('my_custom_form_element' => array(\n '#custom_property' => 'foo',\n '#element_validate' => array('my_element_validate'),\n );\n);\n}");
$this
->assertCoderReviewFail(' $form[\'abc\'] = array("#value" => t("Submit"));');
}
function testUpgrade6xMenu() {
$this
->assertCoderReviewPass(" function mymodule_menu() {\n \$items = array();\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n \$items[] = array();\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n if (\$may_cache) {\n }\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n \$items['test'] = array('title' => t('my title'));\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n \$items['test'] = array('description' => t('my description'));\n}");
$this
->assertCoderReviewPass(" function mymodule_menu() {\n \$items['test'] = array('title' => 'my title');\n}");
$this
->assertCoderReviewPass(" function mymodule_menu() {\n \$items['test'] = array('description' => 'my description');\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n \$items['node/add/foo'] = array();\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n for (\$i=0; \$i<1; \$i++) {\n }\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n foreach (\$a as \$b) {\n }\n}");
$this
->assertCoderReviewFail(" function mymodule_menu() {\n while (\$a > \$b) {\n }\n}");
$this
->assertCoderReviewPass(" function not_a_menu_hook() {\n \$items[] = array();\n}");
$this
->assertCoderReviewFail(' if ($node = node_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($user = user_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($menu = menu_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($menu_link = menu_link_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($vocab = taxonomy_vocabulary_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($contact = contact_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($format = filter_format_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($term = forum_term_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($feed = aggregator_feed_load(arg(1))) {');
$this
->assertCoderReviewFail(' if ($category = aggregator_category_load(arg(1))) {');
$this
->assertCoderReviewFail(' menu_set_location();');
}
function testUpgrade6xDatabase() {
$this
->assertCoderReviewFail(" function mymodule_install() {\n \$type = \$GLOBALS['db_type'];\n}");
$this
->assertCoderReviewFail(" function mymodule_uninstall() {\n \$type = \$GLOBALS['db_type'];\n}");
$this
->assertCoderReviewFail(" function mymodule_update_1() {\n \$type = \$GLOBALS['db_type'];\n}");
$this
->assertCoderReviewFail(' db_next_id();');
$this
->assertCoderReviewFail(' db_num_rows();');
$this
->assertCoderReviewFail(' db_result($result, $row);');
$this
->assertCoderReviewPass(' db_result($result);');
$this
->assertCoderReviewPass(' $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = \'%s\' AND hostname = \'%s\' AND timestamp > %d", $name, ip_address(), REQUEST_TIME - 3600));');
$this
->assertCoderReviewFail(' $sql = "CREATE TABLE foo ()";');
$this
->assertCoderReviewFail(' $sql = "DROP TABLE foo";');
$this
->assertCoderReviewFail(' $sql = "ALTER TABLE foo";');
}
function testUpgrade6xFile() {
$this
->assertCoderReviewFail(' if ($file = file_check_upload(\'picture_upload\')) {');
$this
->assertCoderReviewFail(' $file = file_save_upload(\'picture_upload\', $destination, FILE_EXISTS_REPLACE); ');
$this
->assertCoderReviewFail(' $file = file_save_upload(\'picture_upload\', $dest); ');
$this
->assertCoderReviewFail(' $file = file_save_upload(\'picture_upload\', \'abc\'); ');
$this
->assertCoderReviewFail(' $file = file_save_upload(\'picture_upload\', "abc"); ');
$this
->assertCoderReviewPass(' $file = file_save_upload(\'picture_upload\', array(\'foo\')); ');
$this
->assertCoderReviewPass(' if ($file = file_save_upload(\'picture_upload\', $validators, $dest)) {');
$this
->assertCoderReviewFail(' $sql = \'UPDATE {file_revisions} SET vid=1');
$this
->assertCoderReviewFail(' if (db_query(\'SELECT * FROM {file_revisions}\')) {');
}
function testUpgrade6xLinkUrl() {
$this
->assertCoderReviewFail(' $link = l($text, $path, $attributes, NULL, NULL, FALSE, TRUE);');
$this
->assertCoderReviewFail(' $link = l($text, $path, $attributes, NULL);');
$this
->assertCoderReviewFail(' $link = l($image, $item[\'filepath\'], $link_attributes, NULL, NULL, FALSE, TRUE);');
$this
->assertCoderReviewFail(' $link = l(t($display_vars[\'back_to_top\']), \'faq\', NULL, NULL);');
$this
->assertCoderReviewPass(' $link = l(t($display_vars[\'back_to_top\']), \'faq\', array(\'fragment\' => \'\'));');
$this
->assertCoderReviewPass(' $link = l($text, $path, $options);');
$this
->assertCoderReviewPass(' $link = l($text, $path, array(\'absolute\' => TRUE));');
$this
->assertCoderReviewFail(' $url = url($path, NULL, NULL, FALSE);');
$this
->assertCoderReviewFail(' $url = url($path, $query, NULL);');
$this
->assertCoderReviewFail(' $url = url($item[\'filepath\'], $query, NULL, FALSE);');
$this
->assertCoderReviewFail(' $url = url(\'faq\', NULL, NULL);');
$this
->assertCoderReviewPass(' $url = url(\'faq\', array(\'absolute\' => TRUE));');
$this
->assertCoderReviewPass(' $url = url($path, $options);');
$this
->assertCoderReviewPass(' $url = url($path, array(\'absolute\' => TRUE));');
}
function testUpgrade6xTaxonomy() {
$this
->assertCoderReviewFail(' taxonomy_get_vocabulary($vid);');
$this
->assertCoderReviewFail(' taxonomy_node_get_terms($nid);');
$this
->assertCoderReviewFail(' taxonomy_node_get_terms($node->nid);');
$this
->assertCoderReviewFail(' taxonomy_node_get_terms(123);');
$this
->assertCoderReviewPass(' taxonomy_node_get_terms($node);');
$this
->assertCoderReviewFail(' taxonomy_node_get_terms_by_vocabulary($nid);');
$this
->assertCoderReviewFail(' taxonomy_node_get_terms_by_vocabulary($node->nid);');
$this
->assertCoderReviewFail(' taxonomy_node_get_terms_by_vocabulary(123);');
$this
->assertCoderReviewPass(' taxonomy_node_get_terms_by_vocabulary($node);');
$this
->assertCoderReviewFail(' taxonomy_node_delete($nid);');
$this
->assertCoderReviewFail(' taxonomy_node_delete($node->nid);');
$this
->assertCoderReviewFail(' taxonomy_node_delete(123);');
$this
->assertCoderReviewPass(' taxonomy_node_delete($node);');
$this
->assertCoderReviewFail(' taxonomy_node_save($nid);');
$this
->assertCoderReviewFail(' taxonomy_node_save($node->nid);');
$this
->assertCoderReviewFail(' taxonomy_node_save(123);');
$this
->assertCoderReviewPass(' taxonomy_node_save($node);');
}
function testUpgrade6xFormatPlural() {
$this
->assertCoderReviewFail(' strtr(format_plural($num, \'1 %type post\', \'@count %type posts\'), array(\'%type\' => theme(\'placeholder\', $type)));');
$this
->assertCoderReviewPass(' format_plural($num, \'1 %type post\', \'@count %type posts\', array(\'%type\' => $type));');
}
function testUpgrade6xWatdog() {
$this
->assertCoderReviewFail(' watchdog(\'debug\', \'My debug message.\');');
$this
->assertCoderReviewFail(' watchdog(\'user\', t(\'Removed user.\'));');
$this
->assertCoderReviewFail(' watchdog(\'user\', t(\'Removed %username user.\', array(\'%username\' => $user->name)));');
$this
->assertCoderReviewPass(' watchdog(\'user\', \'Removed %username user.\', array(\'%username\' => $user->name));');
}
function testUpgrade6xDrupalMail() {
$this
->assertCoderReviewFail(' drupal_mail($action, $to, $subject, $body, $from);');
$this
->assertCoderReviewFail(' drupal_mail(\'action_email\', $recipient, $subject, $body, $from);');
$this
->assertCoderReviewFail(' drupal_mail(\'action_email\', $account->mail, $subject, $body, $from);');
$this
->assertCoderReviewFail(' drupal_mail(\'action_email\', "foo@foo.com", $subject, $body, $from);');
$this
->assertCoderReviewPass(' drupal_mail(\'system\', "action_email", $recipient, $language, $params);');
}
function testUpgrade6xUserAuthenticate() {
$this
->assertCoderReviewFail(' user_authenticate($name, $pass);');
$this
->assertCoderReviewFail(' user_authenticate("name", \'pass\');');
$this
->assertCoderReviewPass(' user_authenticate($array);');
$this
->assertCoderReviewPass(' user_authenticate(array(\'name\' => $name, \'pass\' => $pass));');
}
function testUpgrade6xCache() {
$this
->assertCoderReviewFail(' cache_set(\'simple_cid\', \'cache\', $simple);');
$this
->assertCoderReviewFail(' cache_set(\'simple_cid\', "cache", $simple);');
$this
->assertCoderReviewFail(' cache_set(\'simple_cid\', $table, $simple);');
$this
->assertCoderReviewFail(' cache_set(\'complex_cid\', $tbl, serialize($complex));');
$this
->assertCoderReviewFail(' cache_set(\'complex_cid\', serialize($complex));');
$this
->assertCoderReviewPass(' cache_set(\'simple_cid\', $simple);');
$this
->assertCoderReviewPass(' cache_set(\'simple_cid\', $simple, "cache");');
$this
->assertCoderReviewFail(' $complex = unserialize(cache_get(\'complex_cid\'));');
$this
->assertCoderReviewPass(' $complex = cache_get(\'complex_cid\');');
}
function testUpgrade6xNodeAccessRebuild() {
$this
->assertCoderReviewFail(" function mymodule_enable() {\n node_access_rebuild();\n}");
$this
->assertCoderReviewFail(" function mymodule_disable() {\n node_access_rebuild();\n}");
$this
->assertCoderReviewPass(" function mymodule_function() {\n node_access_rebuild();\n}");
}
function testUpgrade6xNodeAPI() {
$this
->assertCoderReviewFail(" function mymodule_nodeapi() {\n switch (\$op) {\n case 'submit': return;\n }\n}");
$this
->assertCoderReviewFail(" function mymodule_nodeapi() {\n if (\$op == 'submit') {\n }\n}");
}
function testUpgrade6xHooks() {
$this
->assertCoderReviewFail(' function mymodule_access($op, $node) {');
$this
->assertCoderReviewPass(' function mymodule_access($op, $node, $account) {');
$this
->assertCoderReviewFail(' function mymodule_help($section) {');
$this
->assertCoderReviewPass(' function mymodule_help($section, $arg) {');
$this
->assertCoderReviewFail(' function mymodule_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {');
$this
->assertCoderReviewPass(' function mymodule_mail_alter(&$message) {');
$this
->assertCoderReviewFail(' function mymodule_link_alter($node, &$links) {');
$this
->assertCoderReviewPass(' function mymodule_link_alter(&$links, $node) {');
$this
->assertCoderReviewFail(' function mymodule_profile_alter($account, &$fields) {');
$this
->assertCoderReviewPass(' function mymodule_profile_alter(&$account) {');
}
function testUpgrade6xBookAPI() {
$this
->assertCoderReviewFail(' book_admin_orphan();');
$this
->assertCoderReviewFail(' book_content();');
$this
->assertCoderReviewFail(' book_form();');
$this
->assertCoderReviewFail(' book_insert();');
$this
->assertCoderReviewFail(' book_location();');
$this
->assertCoderReviewFail(' book_location_down();');
$this
->assertCoderReviewFail(' book_node_visitor_html_post();');
$this
->assertCoderReviewFail(' book_node_visitor_html_pre();');
$this
->assertCoderReviewFail(' book_recurse();');
$this
->assertCoderReviewFail(' book_toc_recurse();');
$this
->assertCoderReviewFail(' book_tree();');
$this
->assertCoderReviewFail(' book_tree_recurse();');
$this
->assertCoderReviewFail(' book_admin_edit($nid);');
$this
->assertCoderReviewPass(' book_admin_edit($form_state, $node);');
$this
->assertCoderReviewFail(' book_toc();');
$this
->assertCoderReviewFail(' book_toc($exclude);');
$this
->assertCoderReviewPass(' book_toc($bid, array(), $depth);');
$this
->assertCoderReviewFail(' book_export_html($nid, $depth);');
$this
->assertCoderReviewPass(' book_export_html($nid);');
$this
->assertCoderReviewFail(' book_export();');
$this
->assertCoderReviewFail(' book_export($type);');
$this
->assertCoderReviewPass(' book_export($type, $nid);');
$this
->assertCoderReviewFail(' book_outline($nid);');
$this
->assertCoderReviewFail(' book_outline($node->nid);');
$this
->assertCoderReviewPass(' book_outline($node);');
$this
->assertCoderReviewFail(' book_prev($node);');
$this
->assertCoderReviewPass(' book_prev($book_link);');
$this
->assertCoderReviewFail(' book_next($node);');
$this
->assertCoderReviewPass(' book_next($book_link);');
}
function testUpgrade6xDeprecatedHooks() {
$this
->assertCoderReviewFail(' function mymodule_auth($username, $password, $server) {');
$this
->assertCoderReviewFail(' function mymodule_info($field = 0) {');
$this
->assertCoderReviewFail(' locale_refresh_cache();');
$this
->assertCoderReviewFail(' theme_get_function();');
}
function testUpgrade6xDeprecatedMisc() {
$this
->assertCoderReviewFail(' custom_url_rewrite($url);');
$this
->assertCoderReviewPass(' custom_url_rewrite_inbound($url);');
$this
->assertCoderReviewFail(' $form_localtion = variable_get(\'comment_form_location\', COMMENT_FORM_SEPARATE_PAGE);');
$this
->assertCoderReviewFail(' $form_localtion = variable_set(\'comment_form_location\', COMMENT_FORM_SEPARATE_PAGE);');
$this
->assertCoderReviewFail(' $form_localtion = variable_del(\'comment_form_location\');');
$this
->assertCoderReviewPass(' $form_localtion = variable_get(\'comment_form_location_page\', COMMENT_FORM_SEPARATE_PAGE);');
$this
->assertCoderReviewFail(' $variable_name = \'comment_form_location\';');
$this
->assertCoderReviewPass(' $variable_name = \'comment_form_location\' . \'_abc\';');
$this
->assertCoderReviewFail(' $path = \'admin/content/comment/settings\';');
$this
->assertCoderReviewFail(' $log_path = \'admin/logs/\';');
$this
->assertCoderReviewFail(' $user_access_path = \'admin/user/access\';');
$this
->assertCoderReviewFail(' $permission = user_access(\'administer access control\');');
$this
->assertCoderReviewFail(' $ip = $_SERVER[\'REMOTE_ADDR\'];');
$this
->assertCoderReviewFail(' global $locale;');
}
}