t('Coder Upgrade 7.x Tests'),
'description' => t('Tests for the coder upgrade7x review.'),
'group' => t('Coder'),
);
}
function testTestModule7x() {
// http://drupal.org/node/224333#block_optional
$this->runTestModuleTest();
}
function testModule7x() {
// N/A - in comment review - http://drupal.org/node/224333#afile
// N/A - http://drupal.org/node/224333#module_file_during_install
// N/A - http://drupal.org/node/224333#module_version_dependencies
// NO TESTS - http://drupal.org/node/224333#registry
// Can't implement tests because it's reviewed by a review callback, which
// needs physical files, and because it's a .info file.
// http://drupal.org/node/224333#api_php
// http://drupal.org/node/224333#update_php
}
function testSystem7x() {
// N/A - http://drupal.org/node/224333#variable_get_default_null
// N/A - http://drupal.org/node/224333#hook_modules_action
// N/A - http://drupal.org/node/224333#static_variable_api
// http://drupal.org/node/224333#module_implements_not_module_list
$this->assertCoderReviewFail(" foreach (module_list() as \$module) {\n module_invoke(\$module, 'foo');\n}");
$this->assertCoderReviewPass(" foreach (module_list() as \$module) {\n print 'foo';\n}");
// http://drupal.org/node/224333#absolute_includes
$this->assertCoderReviewFail(" require variable_get('cache_inc', './includes/cache.inc');");
$this->assertCoderReviewFail(" require_once variable_get('cache_inc', './includes/cache.inc');");
$this->assertCoderReviewFail(" include variable_get('cache_inc', './includes/cache.inc');");
$this->assertCoderReviewFail(" include_once variable_get('cache_inc', './includes/cache.inc');");
$this->assertCoderReviewPass(" require DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');");
$this->assertCoderReviewPass(" require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');");
$this->assertCoderReviewPass(" include DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');");
$this->assertCoderReviewPass(" include_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');");
// TODO - http://drupal.org/node/224333#drupal_set_session
$this->assertCoderReviewFail(' $foo = $_SESSION["foo"];');
$this->assertCoderReviewFail(' $foo = $_SESSION[' . "'foo'" . '];');
$this->assertCoderReviewFail(' if ($_SESSION["foo"])');
// http://drupal.org/node/224333#time
$this->assertCoderReviewFail(' $time = time();');
$this->assertCoderReviewFail(' $time = foo(time());');
$this->assertCoderReviewPass(' $time = foo_time();');
// http://drupal.org/node/224333#rebuild-functions
$this->assertCoderReviewFail(' drupal_rebuild_code_registry();');
// http://drupal.org/node/224333#drupal_uninstall_modules
$this->assertCoderReviewFail(' drupal_uninstall_module("foo");');
$this->assertCoderReviewPass(' drupal_uninstall_modules(array("foo"));');
// http://drupal.org/node/224333#drupal_http_request_parameters
$this->assertCoderReviewPass(' drupal_http_request($url, $options);');
$this->assertCoderReviewPass(' drupal_http_request($url, array());');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, $method, $data, $retry);');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, $method, $data);');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, $method);');
$this->assertCoderReviewFail(' drupal_http_request($url, array(), $method, $data, $retry);');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, "GET", $data, $retry);');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, "GET", NULL, $retry);');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, "GET", "foo", $retry);');
$this->assertCoderReviewFail(' drupal_http_request($url, $headers, "GET");');
// http://drupal.org/node/224333#moved_statistics_settings
$this->assertCoderReviewFail(' $path = "admin/reports/settings";');
$this->assertCoderReviewFail(" \$path = 'admin/reports/settings';");
$this->assertCoderReviewFail(' $path = "URL is admin/reports/settings.";');
// http://drupal.org/node/224333#system_get_module_data
$this->assertCoderReviewFail(' module_rebuild_cache();');
$this->assertCoderReviewFail(' system_theme_data();');
// http://drupal.org/node/224333#drupal_set_html_head
$this->assertCoderReviewFail(' drupal_set_html_head($data);');
// http://drupal.org/node/224333#php_eval
$this->assertCoderReviewFail(' drupal_eval(\'\');');
// http://drupal.org/node/224333#http_header_functions
$this->assertCoderReviewPass(" drupal_set_header('Content-Type', 'text/plain');");
$this->assertCoderReviewFail(" drupal_set_header('Content-Type: text/plain');");
$this->assertCoderReviewPass(" drupal_set_header('500 Internal server error');");
$this->assertCoderReviewFail(" drupal_set_header(\$_SERVER['SERVER_PROTOCOL'] . ' 500 Internal server error');");
// http://drupal.org/node/224333#drupal_set_content
$this->assertCoderReviewFail(" drupal_set_content('footer', 'Adding custom text to the footer');");
$this->assertCoderReviewFail(' $content = drupal_get_content();');
// NO TESTS - http://drupal.org/node/224333#cache_implementation
// Can't implement tests because it's reviewed by a review callback, which
// needs physical files.
// http://drupal.org/node/224333#time_limit
$this->assertCoderReviewFail(" function foo () {\n set_time_limit(100);\n}");
$this->assertCoderReviewPass(" function drupal_set_time_limit () {\n set_time_limit(100);\n}");
$this->assertCoderReviewPass(" function foo () {\n drupal_set_time_limit(100);\n}");
// http://drupal.org/node/224333#archive-tar
// http://drupal.org/node/224333#search-api
// http://drupal.org/node/224333#user-1
}
function testPermissions7x() {
// N/A - http://drupal.org/node/224333#moved_statistics_settings
// UNCLEAR - http://drupal.org/node/224333#hook_node_access_records
// UNCLEAR - http://drupal.org/node/224333#bypass_node_access
// http://drupal.org/node/224333#descriptions_permissions
$this->assertCoderReviewFail(" function mymodule_permission() {\n return array('administer mymodule');\n }");
$this->assertCoderReviewFail(" function mymodule_permission() {\n return array('administer mymodule', 'access foo');\n }");
$this->assertCoderReviewPass(" function mymodule_permission() {\n return array('administer mymodule' => array('title' => t('Administer mymodule'), 'description' => t('foo')));\n }");
// http://drupal.org/node/224333#sorting_permissions
// http://drupal.org/node/224333#permission_tables
$this->assertCoderReviewPass(' db_query("SELECT * FROM {role_permission}");');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {permission}");');
$this->assertCoderReviewFail(' db_query("DELETE FROM {permission}");');
// http://drupal.org/node/224333#node_access_alter_hooks
// http://drupal.org/node/224333#hook_permission
$this->assertCoderReviewFail(" function mymodule_perm() {\n}");
$this->assertCoderReviewPass(" function mymodule_permission() {\n}");
// http://drupal.org/node/224333#php_permissions
$this->assertCoderReviewFail(" \$permission = 'use PHP for block visibility';");
$this->assertCoderReviewFail(' $permission = "use PHP for block visibility";');
$this->assertCoderReviewFail(" return array('use PHP for block visibility');");
// http://drupal.org/node/224333#system_admin_menu_block_access
// http://drupal.org/node/224333#hook_node_access
$this->assertCoderReviewFail(" function mymodule_access() {\n}");
$this->assertCoderReviewPass(" function mymodule_node_access() {\n}");
// http://drupal.org/node/224333#user-roles-api
}
function testDatabase7x() {
// http://drupal.org/node/224333#dbtng
// http://drupal.org/node/224333#schema_translation
$this->assertCoderReviewFail(" function mymodule_schema() {\n \$schema['table'] = array(\n 'description' => t('My table description.'));\n}");
$this->assertCoderReviewFail(" function mymodule_schema() {\n \$schema['table'] = array(\n 'description' => st('My table description.'));\n}");
$this->assertCoderReviewFail(" function mymodule_schema() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => t('My field description.'))));\n}");
$this->assertCoderReviewFail(" function mymodule_schema() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => st('My field description.'))));\n}");
$this->assertCoderReviewPass(" function mymodule_schema() {\n \$schema['table'] = array(\n 'description' => 'My table description.');\n}");
$this->assertCoderReviewPass(" function mymodule_schema() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => 'My field description.')));\n}");
$this->assertCoderReviewFail(" function mymodule_update_123() {\n \$schema['table'] = array(\n 'description' => st('My table description.'));\n}");
$this->assertCoderReviewFail(" function mymodule_update_123() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => t('My field description.'))));\n}");
// http://drupal.org/node/224333#db_rewrite_sql
$this->assertCoderReviewFail(' $sql = db_rewrite_sql("SELECT n.nid FROM {node}");');
// http://drupal.org/node/224333#schema_html
$this->assertCoderReviewFail(" function mymodule_schema() {\n \$schema['table'] = array(\n 'description' => 'My table <a href=\"foo.html\">foo</a> description.');\n}");
$this->assertCoderReviewFail(" function mymodule_schema() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => 'My field <a href=\"foo.html\">foo</a> description.')));\n}");
$this->assertCoderReviewPass(" function mymodule_schema() {\n \$schema['table'] = array(\n 'description' => 'My table foo description.');\n}");
$this->assertCoderReviewPass(" function mymodule_schema() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => 'My field foo description.')));\n}");
$this->assertCoderReviewFail(" function mymodule_update_123() {\n \$schema['table'] = array(\n 'description' => 'My table <a href=\"foo.html\">foo</a> description.');\n}");
$this->assertCoderReviewFail(" function mymodule_update_123() {\n \$schema['table'] = array(\n 'fields' => array('nid' => array('description' => 'My field <a href=\"foo.html\">foo</a> description.')));\n}");
// http://drupal.org/node/224333#select_count
$this->assertCoderReviewFail(" db_query( 'SELECT COUNT (*) FROM {users}')");
// http://drupal.org/node/224333#foreign-keys-added
}
function testMenu7x() {
// N/A - http://drupal.org/node/224333#international_item
// http://drupal.org/node/224333#menu_callback_array
// http://drupal.org/node/224333#hook_menu_link_alter
$this->assertCoderReviewFail(' function mymodule_menu_link_alter(&$item, $menu)');
$this->assertCoderReviewPass(' function mymodule_menu_link_alter(&$item)');
// http://drupal.org/node/224333#system_admin_menu_block_access
}
function testBlock7x() {
// TEST MODULE - http://drupal.org/node/224333#block_optional
// N/A - http://drupal.org/node/224333#hook_block_info_alter
// http://drupal.org/node/224333#remove_op
$this->assertCoderReviewFail(" function mymodule_block(\$op, \$delta, \$edit) {\n}");
$this->assertCoderReviewFail(" function mymodule_block(\$delta, \$edit) {\n if (\$op == 'list') {\n }\n}");
$this->assertCoderReviewFail(" function mymodule_block(\$delta, \$edit) {\n switch (\$op) {\n case 'list':\n }\n}");
}
function testComments7x() {
// N/A - http://drupal.org/node/224333#comment_load_multiple
// N/A - http://drupal.org/node/224333#comment_save_refactor
// N/A - http://drupal.org/node/224333#comment_presave_hook
// http://drupal.org/node/224333#comment_load
$this->assertCoderReviewFail(' $comment = _comment_load($cid);');
$this->assertCoderReviewFail(' if (_comment_load($cid))');
$this->assertCoderReviewPass(' $comment = comment_load($cid);');
$this->assertCoderReviewPass(' if (comment_load($cid))');
// Any menu items that are using the %_comment wildcard will need to change to %comment.
$this->assertCoderReviewFail(' function mymodule_menu() {\n$items[\'foo/%_comment\'] = array();\n}');
$this->assertCoderReviewFail(' function mymodule_menu_alter() {\n$items[\'foo/%_comment\'] = array();\n}');
$this->assertCoderReviewPass(' function mymodule_menu() {\n$items[\'foo/%comment\'] = array();\n}');
$this->assertCoderReviewPass(' function mymodule_menu_alter() {\n$items[\'foo/%comment\'] = array();\n}');
$this->assertCoderReviewPass(' $foo = \'foo/%_comment\';');
// http://drupal.org/node/224333#comment_status
$this->assertCoderReviewFail(' db_query(\'SELECT cid FROM {comments} WHERE status = 0\');');
$this->assertCoderReviewFail(' db_query(\'SELECT cid FROM {comments} WHERE status != 0\');');
$this->assertCoderReviewFail(' db_query(\'SELECT cid FROM {comments} WHERE status <> 0\');');
$this->assertCoderReviewPass(' db_query(\'SELECT cid FROM {comments} WHERE status = :status\', array(\':status\' => COMMENT_NOT_PUBLISHED));');
$this->assertCoderReviewPass(' db_query(\'SELECT cid FROM {my_comments} WHERE status = 0\');');
// http://drupal.org/node/224333#comment_validate_removed
$this->assertCoderReviewFail(' comment_validate();');
$this->assertCoderReviewFail(' if (comment_validate())');
// http://drupal.org/node/224333#comment_node_url
$this->assertCoderReviewFail(' comment_node_url();');
$this->assertCoderReviewFail(' if (comment_node_url())');
}
function testInput7x() {
// http://drupal.org/node/224333#check_markup_params
$this->assertCoderReviewFail(' check_markup($body, $format, $check);');
$this->assertCoderReviewFail(' check_markup($body, $format, FALSE);');
$this->assertCoderReviewFail(' check_markup($body, $format, TRUE);');
$this->assertCoderReviewPass(' check_markup($body, $format, $langcode);');
$this->assertCoderReviewPass(' check_markup($body, $format, "en");');
$this->assertCoderReviewPass(' check_markup($body, $format, $langcode, FALSE);');
$this->assertCoderReviewPass(' check_markup($body, $format);');
// http://drupal.org/node/224333#drupal_set_title
$this->assertCoderReviewFail(' drupal_set_title(check_plain($text));');
$this->assertCoderReviewPass(' drupal_set_title($text);');
$this->assertCoderReviewFail(' drupal_set_title(t("%test"));');
$this->assertCoderReviewFail(' drupal_set_title(t("@test"));');
$this->assertCoderReviewFail(' drupal_set_title(t("foo %test"));');
$this->assertCoderReviewFail(' drupal_set_title(t("foo @test"));');
$this->assertCoderReviewPass(' drupal_set_title(t("test @ 10"));');
$this->assertCoderReviewPass(' drupal_set_title(t("test 10% foo"));');
$this->assertCoderReviewPass(' drupal_set_title(t("%test"), PASS_THROUGH);');
$this->assertCoderReviewPass(' drupal_set_title(t("@test"), PASS_THROUGH);');
$this->assertCoderReviewPass(' drupal_set_title(t("test"));');
// http://drupal.org/node/224333#hook_filter_info
$this->assertCoderReviewFail(' function mymodule_filter($op, $delta = 0, $format = -1, $text = \'\')');
$this->assertCoderReviewFail(' function mymodule_filter_tips($delta, $format, $long = FALSE)');
$this->assertCoderReviewPass(' function mymodule_filter_info()');
// http://drupal.org/node/224333#text_format
$this->assertCoderReviewFail(' $form[\'format\'] = filter_form($edit[\'format\']);');
$this->assertCoderReviewFail(' $form[\'comment\'][\'filter\'] = filter_form(FILTER_FORMAT_DEFAULT);');
$this->assertCoderReviewPass(' $format = filter_form();');
// http://drupal.org/node/224333#filter_urls
$this->assertCoderReviewFail(' $url = url("admin/settings/filters");');
$this->assertCoderReviewFail(' $url = url("admin/settings/filters/add");');
$this->assertCoderReviewPass(' $url = url("admin/settings/filter");');
$this->assertCoderReviewPass(' $url = url("admin/settings/filter/add");');
// http://drupal.org/node/224333#default-text-formats
// http://drupal.org/node/224333#text-format-permissions
// http://drupal.org/node/224333#filter-formats-parameters
}
function testTaxonomy7x() {
// N/A - http://drupal.org/node/224333#taxonomy_term_load_multiple
// N/A - http://drupal.org/node/224333#taxonomy_hooks
// N/A - http://drupal.org/node/224333#vocabulary_load_multiple
// http://drupal.org/node/224333#taxonomy_get_tree
$this->assertCoderReviewFail(' $tree = taxonomy_get_tree($vid, $parent, $depth);');
$this->assertCoderReviewFail(' $tree = taxonomy_get_tree($vid, $parent, $depth, $max_depth);');
$this->assertCoderReviewFail(' $tree = taxonomy_get_tree($vid, $parent, -1);');
$this->assertCoderReviewFail(' $tree = taxonomy_get_tree($vid, $parent, -1, $max_depth);');
$this->assertCoderReviewPass(' $tree = taxonomy_get_tree($vid, $parent, $max_depth);');
// http://drupal.org/node/224333#taxonomy_tables
$this->assertCoderReviewFail(' db_query("SELECT * FROM {term_data}")');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {term_hierarchy}")');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {term_node}")');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {term_relation}")');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {term_synonym}")');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {vocabulary}")');
$this->assertCoderReviewFail(' db_query("SELECT * FROM {vocabulary_node_types}")');
// http://drupal.org/node/224333#taxonomy_crud
$this->assertCoderReviewFail(' taxonomy_get_term($tid);');
$this->assertCoderReviewPass(' mytaxonomy_get_term($tid);');
$this->assertCoderReviewFail(' taxonomy_save_term($term);');
$this->assertCoderReviewPass(' mytaxonomy_save_term($term);');
$this->assertCoderReviewFail(' taxonomy_term_save(array(\'tid\' => 123));');
$this->assertCoderReviewFail(' taxonomy_del_term($tid);');
$this->assertCoderReviewPass(' mytaxonomy_del_term($tid);');
$this->assertCoderReviewFail(' taxonomy_save_vocabulary($vocab);');
$this->assertCoderReviewPass(' mytaxonomy_save_vocabulary($vocab);');
$this->assertCoderReviewFail(' taxonomy_vocabulary_save(array(\'tid\' => 123));');
$this->assertCoderReviewFail(' taxonomy_del_vocabulary($vocab);');
$this->assertCoderReviewPass(' mytaxonomy_del_vocabulary($vocab);');
// http://drupal.org/node/224333#taxonomy_paths
$this->assertCoderReviewPass(' $url = url("taxonomy/term/123");');
$this->assertCoderReviewFail(' $url = url("taxonomy/term/1+2+3");');
$this->assertCoderReviewFail(' $url = url("taxonomy/term/1,2,3");');
$this->assertCoderReviewFail(' $url = url("taxonomy/term/123/0");');
$this->assertCoderReviewFail(' $url = url("taxonomy/term/1+2+3/0");');
$this->assertCoderReviewFail(' $url = url("taxonomy/term/1,2,3/0");');
// http://drupal.org/node/224333#related_terms
$this->assertCoderReviewFail(' $related = taxonomy_get_related($tid);');
// http://drupal.org/node/224333#taxonomy-node
}
function testJavascript7x() {
// N/A - http://drupal.org/node/224333#jquery_ui
// N/A - http://drupal.org/node/224333#attached_js
// N/A - http://drupal.org/node/224333#drupal_add_library
// N/A - http://drupal.org/node/224333#drupal_add_js_css_reset
// N/A - http://drupal.org/node/224333#local_settings_behaviors
// NO TESTS - http://drupal.org/node/224333#jquery_13
// NO TESTS - http://drupal.org/node/224333#drupal_behaviors
// NO TESTS - http://drupal.org/node/224333#javascript_compatibility
// NO TESTS - http://drupal.org/node/224333#no-jsenabled
// http://drupal.org/node/224333#drupal_add_js_weight
$this->assertCoderReviewFail(" drupal_add_js(\$data, 'module');");
// http://drupal.org/node/224333#drupal_add_js_options
$this->assertCoderReviewPass(" drupal_add_js(\$data, 'file');");
$this->assertCoderReviewFail(" drupal_add_js(\$data, 'file', 'header');");
$this->assertCoderReviewFail(" drupal_add_js(\$data, 'file', \$header, \$defer);");
$this->assertCoderReviewPass(" drupal_add_js(\$jquery_plugin, array('weight' => JS_LIBRARY));");
// http://drupal.org/node/224333#hook_js_alter
$this->assertCoderReviewPass(" function mytheme_preprocess_page(&\$variables) {\n \$scripts = \$variables['myscripts'];\n}");
$this->assertCoderReviewFail(" function mytheme_preprocess_page(&\$variables) {\n \$scripts = \$variables['scripts'];\n}");
// http://drupal.org/node/224333#drupal_add_js_external
$this->assertCoderReviewPass(' drupal_add_html_head("foo");');
$this->assertCoderReviewFail(' drupal_add_html_head(\'\');');
$this->assertCoderReviewFail(' drupal_add_html_head(\'