Commit cce402d1 authored by Dries's avatar Dries

- Patch #446742 by sun, dmitrig01: fixed various bugs.

parent e7211473
......@@ -709,7 +709,7 @@ function comment_node_update_index($node) {
$text = '';
$comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED));
foreach ($comments as $comment) {
$text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, FALSE);
$text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, '', FALSE);
}
return $text;
}
......
......@@ -372,7 +372,7 @@ function hook_node_update_index($node) {
$text = '';
$comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED));
foreach ($comments as $comment) {
$text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, FALSE);
$text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, '', FALSE);
}
return $text;
}
......
......@@ -1507,9 +1507,9 @@ function node_search($op = 'search', $keys = NULL) {
$node->body = drupal_render($node->content);
// Fetch comments for snippet.
$node->body .= module_invoke('comment', 'node', $node, 'update_index');
$node->body .= module_invoke('comment', 'node_update_index', $node);
// Fetch terms for snippet.
$node->body .= module_invoke('taxonomy', 'node', $node, 'update_index');
$node->body .= module_invoke('taxonomy', 'node_update_index', $node);
$extra = module_invoke_all('node_search_result', $node);
......
......@@ -429,3 +429,79 @@ class SearchBlockTestCase extends DrupalWebTestCase {
$this->assertText('Your search yielded no results');
}
}
/**
* Test integration searching comments.
*/
class SearchCommentTestCase extends DrupalWebTestCase {
protected $admin_user;
public static function getInfo() {
return array(
'name' => t('Comment Search tests'),
'description' => t('Verify text formats and filters used elsewhere.'),
'group' => t('Search'),
);
}
function setUp() {
parent::setUp('comment', 'search');
$this->admin_user = $this->drupalCreateUser(array('administer filters', 'administer permissions', 'create page content', 'post comments without approval'));
$this->drupalLogin($this->admin_user);
}
/**
* Verify that comments are rendered using proper format in search results.
*/
function testSearchResultsComment() {
$comment_body = $this->randomName(5, '');
variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL);
// Enable check_plain() for 'Filtered HTML' text format.
$edit = array(
'filters[filter/4]' => 1,
);
$this->drupalPost('admin/settings/filter/1', $edit, t('Save configuration'));
// Allow anonymous users to search content.
$edit = array(
DRUPAL_ANONYMOUS_RID . '[search content]' => 1,
// @todo Comments are added to search index without checking first whether
// anonymous users are allowed to access comments.
DRUPAL_ANONYMOUS_RID . '[access comments]' => 1,
// @todo Without this permission, "Login or register to post comments" is
// added to the search index. Comment.module is not guilty; that text
// seems to be added via node links.
DRUPAL_ANONYMOUS_RID . '[post comments]' => 1,
);
$this->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
// Create a node.
$node = $this->drupalCreateNode(array('type' => 'article'));
// Post a comment using 'Full HTML' text format.
$edit_comment = array(
'subject' => $this->randomName(2, ''),
'comment' => '<h1>' . $comment_body . '</h1>',
'comment_format' => 2,
);
$this->drupalPost('comment/reply/' . $node->nid, $edit_comment, t('Save'));
// Invoke search index update.
$this->drupalLogout();
$this->drupalGet($GLOBALS['base_url'] . '/cron.php', array('external' => TRUE, 'query' => 'cron_key=' . variable_get('cron_key', 'drupal')));
// Search for $title.
$edit = array(
'search_theme_form' => $comment_body,
);
$this->drupalPost('', $edit, t('Search'));
$this->assertText($node->title, t('Node found in search results.'));
// Verify that comment is rendered using proper format.
$this->assertText($edit_comment['subject'], t('Comment subject found in search results.'));
$this->assertText($comment_body, t('Comment body text found in search results.'));
$this->assertNoRaw(t('n/a'), t('HTML in comment body is not hidden.'));
$this->assertNoRaw(check_plain($edit_comment['comment']), t('HTML in comment body is not escaped.'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment