t('api_link_documentation()'),
'desc' => t('Test the api_link_documentation() function.'),
'group' => 'API Module',
);
}
function setUp() {
}
function testApiLinkDocumentation() {
$branch_name = variable_get('api_default_branch', 'HEAD');
$function_name = 'drupal_bootstrap';
$function_summary = db_result(db_query("SELECT summary FROM {api_documentation} WHERE branch_name = '%s' AND object_type = 'function' AND object_name = '%s'", $branch_name, $function_name));
$function_link = ''. $function_name .'';
$file_path = 'modules/system/system.module';
$file_name = basename($file_path);
$file_summary = db_result(db_query("SELECT summary FROM {api_documentation} WHERE branch_name = '%s' AND object_type = 'file' AND object_name = '%s'", $branch_name, $file_path));
$file_link = ''. $file_name .'';
$tests = array(
// Should be linked
array(
'message' => 'Function name linking',
'data' => $function_name .'(',
'expected' => $function_link .'(',
),
array(
'message' => 'Function name linking with preceding space',
'data' => ' '. $function_name .'(',
'expected' => ' '. $function_link .'(',
),
// Should not be linked
array(
'message' => 'Function name linking with preceding non-space character',
'data' => '.'. $function_name .'(',
'expected' => '.'. $function_name .'(',
),
array(
'message' => 'Function name linking with preceding letter',
'data' => 'a'. $function_name .'(',
'expected' => 'a'. $function_name .'(',
),
array(
'message' => 'Function name linking without parenthesis',
'data' => $function_name,
'expected' => $function_name,
),
array(
'message' => 'Function name linking inside a HTML tag',
'data' => '',
'expected' => '',
),
// Should be linked
array(
'message' => 'File name linking',
'data' => $file_name,
'expected' => $file_link,
),
array(
'message' => 'File name linking with preceding space',
'data' => ' '. $file_name,
'expected' => ' '. $file_link,
),
array(
'message' => 'File name linking with following space',
'data' => $file_name .' ',
'expected' => $file_link .' ',
),
array(
'message' => 'File name linking with following punctuation',
'data' => $file_name .'.',
'expected' => $file_link .'.',
),
// Should not be linked
array(
'message' => 'File name linking with preceding non-space character',
'data' => '.'. $file_name,
'expected' => '.'. $file_name,
),
array(
'message' => 'File name linking with preceding letter',
'data' => 'a'. $file_name,
'expected' => 'a'. $file_name,
),
array(
'message' => 'File name linking inside a HTML tag',
'data' => '',
'expected' => '',
),
);
foreach ($tests as $test) {
$result = api_link_documentation($test['data'], $branch_name);
$this->assertEqual($result, $test['expected'], $test['message']);
}
}
}