summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/comment/comment.module2
-rw-r--r--modules/node/node.api.php2
-rw-r--r--modules/node/node.module4
-rw-r--r--modules/search/search.test76
4 files changed, 80 insertions, 4 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 395d84221..22962b06f 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -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;
}
diff --git a/modules/node/node.api.php b/modules/node/node.api.php
index 9f39c7386..65446cad9 100644
--- a/modules/node/node.api.php
+++ b/modules/node/node.api.php
@@ -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;
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 8bd143d23..92a088871 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -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);
diff --git a/modules/search/search.test b/modules/search/search.test
index bb4705ff8..fabc48dac 100644
--- a/modules/search/search.test
+++ b/modules/search/search.test
@@ -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.'));
+ }
+}