protected function CommentAlterBaseTestCase::getCommentAlterations in Comment Alter 7
Get a comment alteration diffs from the current page.
Parameters
(optional) int $ord: If there are multiple diff tables on the page, this specifies which one in sequential order.
Return value
array An associative array keyed by field label pointing to an array which contains arrays which have two values, the original and new value for the given field.
2 calls to CommentAlterBaseTestCase::getCommentAlterations()
- CommentAlterBaseTestCase::assertCommentDiff in ./
comment_alter.test - Asserts that a Comment Alter diff table on the current page is as expected.
- CommentAlterPermissionTestCase::testViewCommentAlterations in ./
comment_alter.test - This function was copied from CommentAlterListTextTestCase::testOptionsSelectSingle(), which should pass for a privileged user, but fail for an unprivileged one.
File
- ./
comment_alter.test, line 152 - Functional tests for the Comment Alter module.
Class
- CommentAlterBaseTestCase
- Parent of all the test cases for Comment Alter.
Code
protected function getCommentAlterations($ord = 0) {
// Extract the values from the
// '<table class="comment-alter-diff">...</table>'.
$results = $this
->xpath('//table[@class=:class]', array(
':class' => 'comment-alter-diff',
));
$result = count($results) >= $ord + 1 ? $results[$ord] : NULL;
$fields = array();
if (!empty($result)) {
$last_field_name = NULL;
foreach ($result->tbody->tr as $tr) {
// Figure out the field name.
$field_name = rtrim($tr->td[0], ':');
if (empty($field_name)) {
$field_name = $last_field_name;
}
// Grab the values and clear for NULL.
$values = array(
$tr->td[1],
$tr->td[3],
);
foreach ($values as $index => $value) {
if ((string) $value == '&') {
$values[$index] = NULL;
}
elseif ((string) $value->div
->asXML() == '<div> </div>') {
// For file fields, it puts the original values as <div> </div>
// which becomes a crazy UTF-8 character when doing $value->asXML(),
// so we need special support here.
$values[$index] = NULL;
}
else {
$values[$index] = strip_tags($value
->asXML());
}
}
// Add to the array and store the field_name process.
$fields[$field_name][] = $values;
$last_field_name = $field_name;
}
}
return $fields;
}