I was trying to use the "Recent comments" block and got the following fatal error:
Fatal error: Call to a member function condition() on a non-object in /home/davereid/Projects/drupal-head/modules/comment/comment.module on line 338

Looked in the code and the following is the problem:

    $result = db_select('comment', 'c')
      ->fields('c', array('nid', 'subject', 'cid', 'timestamp') )
      ->innerJoin('node', 'n', 'n.nid = c.nid')
      ->condition('c.nid', $nids, 'IN')
      ->condition('c.status', COMMENT_PUBLISHED)
      ->condition('n.status', 1)
      ->orderBy('c.cid', 'DESC')
      ->range(0, $number)
      ->execute();
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review
FileSize
1.43 KB

Attached patch fixes the error by using $query = db_select('comment', 'c'); and using the rest of the alterations with the $query object.

lut4rp’s picture

Yep, it works all right now!

Dries’s picture

Looks like we need a test here?

Dries’s picture

Status: Needs review » Needs work
Dave Reid’s picture

Issue tags: +Needs tests, +block
webchick’s picture

Ran into this again today. Would be great to see this fixed. :)

catch’s picture

Priority: Normal » Critical
Dave Reid’s picture

Status: Needs work » Needs review
FileSize
8.78 KB

Here's my work on the patch with test so far. I found that the comment tests never tried to enter a comment without a subject, so I added that for good measure. This will probably come back with one fail because the block title is not saving correctly. I might have seen another issue for that somewhere...

Dave Reid’s picture

Ok yay...I figured it out. A block needs to be moved to a region first before you can edit the title. My only question is should the block test be more thorough? Should we directly test the output of theme('comment_block')?

The other changes in this patch:
- Test posting a comment without a subject (hadn't been done in the extensive comment tests)
- Move the tiny CommentNodePage tests into CommentInterfaceTest. It fits better there and it's one less test class that needs to be reset/run.
- Moves testCommentRSS out of CommentHelperCase and into its own test. Every time CommentHelperCase is extended, testCommentRSS is run. Not exactly expected or desired...

This should be ready for a full review!

Dave Reid’s picture

Re-rolled with a quick DBTNG improvment using fetchAll() and doc blocks on the new test.

Dave Reid’s picture

Added missing phpdoc to the tests that were moved around. Nothing wrong with more documentation.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Had a look through this and nitpicked in irc, the tests pass. RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Excellent, thanks! :) Committed to HEAD.

Status: Fixed » Closed (fixed)
Issue tags: -Needs tests, -block

Automatically closed -- issue fixed for 2 weeks with no activity.