t('api_link_code()'),
'description' => t('Test the api_link_code() function.'),
'group' => 'API Module',
);
}
function testApiLinkCode() {
$branch = $this->getBranch();
$interface = api_object_load('SampleInterface', $branch, 'interface', 'classes.php');
$class = api_object_load('Sample', $branch, 'class', 'classes.php');
$tests = array(
// Should be linked
array(
'message' => 'Marked-up function name linking',
'data' => 'sample_function',
'expected' => 'sample_function',
),
array(
'message' => 'Linking to method defined in multiple classes',
'data' => 'foo',
'expected' => 'foo',
),
array(
'message' => 'Linking to method defined in multiple classes from class',
'data' => 'foo',
'expected' => 'foo',
'class_did' => $class->did,
),
array(
'message' => 'Linking to method defined in multiple classes from interface',
'data' => 'foo',
'expected' => 'foo',
'class_did' => $interface->did,
),
array(
'message' => 'Linking to method defined in multiple subclasses from interface',
'data' => 'baz',
'expected' => 'baz',
'class_did' => $interface->did,
),
array(
'message' => 'Marked-up class name linking',
'data' => 'Sample',
'expected' => 'Sample',
),
array(
'message' => 'Duplicate function name linking',
'data' => 'duplicate_function',
'expected' => 'duplicate_function',
),
// Should not be linked
array(
'message' => 'Function name linking',
'data' => 'sample_function',
'expected' => 'sample_function',
),
array(
'message' => 'Function name linking with (',
'data' => 'sample_function(',
'expected' => 'sample_function(',
),
);
foreach ($tests as $test) {
if (!isset($test['class_did'])) {
$test['class_did'] = NULL;
}
$result = api_link_code($test['data'], $this->getBranch(), $test['class_did']);
$this->assertEqual($result, $test['expected'], $test['message'] . ' Got: ' . check_plain($result) . '
');
}
}
}