t('api_link_documentation()'),
'description' => t('Test the api_link_documentation() function.'),
'group' => 'API Module',
);
}
function testApiLinkDocumentation() {
$class = api_object_load('Sample', $this->getBranch(), 'class', 'classes.php');
$tests = array(
// Should be linked
array(
'message' => 'Function name linking',
'data' => 'sample_function(',
'expected' => 'sample_function(',
),
array(
'message' => 'Function name linking with preceding space',
'data' => ' sample_function(',
'expected' => ' sample_function(',
),
array(
'message' => 'Function @link',
'data' => '@link sample_function A sample function. @endlink',
'expected' => 'A sample function.',
),
array(
'message' => 'Multiline function @link',
'data' => "@link sample_function\nA sample function. @endlink",
'expected' => 'A sample function.',
),
array(
'message' => 'Method name linking',
'data' => 'Sample::foo(',
'expected' => 'Sample::foo(',
),
array(
'message' => 'Method name linking without explicit class',
'data' => 'foo(',
'expected' => 'foo(',
),
array(
'message' => 'Method name linking without explicit class, but in class context',
'data' => 'foo(',
'expected' => 'foo(',
'class_did' => $class->did,
),
array(
'message' => 'Class constant @link',
'data' => '@link Sample::constant A class constant @endlink',
'expected' => 'A class constant',
),
array(
'message' => 'Property @link',
'data' => '@link Sample::property A property @endlink',
'expected' => 'A property',
),
array(
'message' => 'Class @link',
'data' => '@link Sample A class @endlink',
'expected' => 'A class',
),
array(
'message' => 'Class aggressive link',
'data' => 'Sample',
'expected' => 'Sample',
'aggressive_classes' => TRUE,
),
array(
'message' => 'Constant link',
'data' => 'SAMPLE_CONSTANT',
'expected' => 'SAMPLE_CONSTANT',
),
// Should not be linked
array(
'message' => 'Function name linking with preceding non-space character',
'data' => '.sample_function(',
'expected' => '.sample_function(',
),
array(
'message' => 'Function name linking with preceding letter',
'data' => 'asample_function(',
'expected' => 'asample_function(',
),
array(
'message' => 'Function name linking without parenthesis',
'data' => 'sample_function',
'expected' => 'sample_function',
),
array(
'message' => 'Function name linking inside a HTML tag',
'data' => '',
'expected' => '',
),
array(
'message' => 'Function \\@link',
'data' => '\\@link sample_function A sample function. @endlink',
'expected' => '@link sample_function A sample function. @endlink',
),
array(
'message' => 'Class aggressive link with trailing letter',
'data' => 'Samplea',
'expected' => 'Samplea',
'aggressive_classes' => TRUE,
),
array(
'message' => 'Class link',
'data' => 'Sample',
'expected' => 'Sample',
),
array(
'message' => 'Constant link with trailing chatacter',
'data' => 'SAMPLE_CONSTANTA',
'expected' => 'SAMPLE_CONSTANTA',
),
// Should be linked
array(
'message' => 'File name linking',
'data' => 'sample.php',
'expected' => 'sample.php',
),
array(
'message' => 'File name linking with preceding space',
'data' => ' sample.php',
'expected' => ' sample.php',
),
array(
'message' => 'File name linking with following space',
'data' => 'sample.php ',
'expected' => 'sample.php ',
),
array(
'message' => 'File name linking with following punctuation',
'data' => 'sample.php.',
'expected' => 'sample.php.',
),
array(
'message' => 'File @link',
'data' => '@link sample.php A sample file. @endlink',
'expected' => 'A sample file.',
),
// Should not be linked
array(
'message' => 'File name linking with preceding non-space character',
'data' => '.sample.php',
'expected' => '.sample.php',
),
array(
'message' => 'File name linking with preceding letter',
'data' => 'asample.php',
'expected' => 'asample.php',
),
array(
'message' => 'File name linking inside a HTML tag',
'data' => '',
'expected' => '',
),
array(
'message' => 'File \\@link, does fill in file link',
'data' => '\\@link sample.php A sample file. @endlink',
'expected' => '@link sample.php A sample file. @endlink',
),
array(
'message' => 'Escaped @tag is not unescaped.',
'data' => 'Escaped \\@stuff.',
'expected' => 'Escaped @stuff.',
),
array(
'message' => 'Double-escaped @tag is not unescaped.',
'data' => 'Double-escaped \\\\@stuff.',
'expected' => 'Double-escaped \\@stuff.',
),
);
foreach ($tests as $test) {
$result = api_link_documentation($test['data'], $this->getBranch(), isset($test['class_did']) ? $test['class_did'] : NULL, isset($test['aggressive_classes']) ? $test['aggressive_classes'] : FALSE);
$this->assertEqual($result, $test['expected'], $test['message'] . ' Got: ' . check_plain($result) . '
');
}
}
}