Posted by xjm

Problem/Motivation

The setCommentSettings() method in the base comment test class looks like this:

function setCommentSettings($name, $value, $message) {
  variable_set($name . '_article', $value);
  $this->assertTrue(TRUE, t($message)); // Display status message.
}

There are several things wrong with this:

  1. The $this->assertTrue(TRUE) should just be $this->pass().
  2. A variable should not be stuck directly in a t() like that.
  3. In general, t() on assertions that use variables should be replaced with format_string(). Reference: http://drupal.org/simpletest-tutorial-drupal7#t
  4. But actually, we shouldn't be formatting the assertion message at all. That's on the caller.
  5. Also, that inline comment should not be hanging off the end of the line.

See: #1742602: Removing t() from asserts in simpletests in comment module and #1797506: Remove t() from assertion messages in tests for the rdf module

Proposed resolution

  1. Use $this->pass() instead of $this->assertTrue(TRUE).
  2. Remove the t() from the $message parameter in the assertion.
  3. Move the inline comment above the line.
  4. Check the usage of setCommentSetting() throughout core and check whether any callers need to use format_string() on their message strings (e.g., there are variables to output in the message). If so, add it. If not, remove any use of t() on plain-text messages for that parameter.

Remaining tasks

  • Create patch.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Issue summary: View changes

Updated issue summary.

larowlan’s picture

Issue tags: +#pnx-sprint

Tagging

boztek’s picture

Status: Active » Needs review
FileSize
8.61 KB

Implemented proposed solution.

boztek’s picture

Switched array index from double to single quote.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Lars Toomre’s picture

These changes may conflict with #1742602: Removing t() from asserts in simpletests in comment module. However, both this and that issue should be combined when producing a patch to backport to D7.

I reviewed this patch as well and agree that all changes are appropriate and correct. This is good to go. +RTBC!

Dries’s picture

Dries’s picture

Asked for a re-test as I don't think this patch applies. Might require a quick reroll.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1798066-clean-commenttestbase-3.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
FileSize
8.53 KB
xjm’s picture

Status: Needs review » Needs work

So there are two more to clean up I think:

core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php:    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php:    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
boztek’s picture

Status: Needs work » Needs review
FileSize
9.93 KB

Can't see anymore; that should be all of them.

boztek’s picture

+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.phpundefined
@@ -199,7 +199,7 @@ function setCommentForm($enabled) {
+    $this->setCommentSettings('comment_anonymous', $level, format_string('Anonymous commenting set to level @level.', array('level' => $level)));

Spoke too soon - should be '@level' => $level

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @boztek. This looks ready now.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Looks goot. Committed to 8.x.

tim.plunkett’s picture

Status: Fixed » Reviewed & tested by the community

This wasn't pushed.

Dries, please git pull --rebase before you push this, thanks!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed *and pushed* to 8.x. :D Thanks.

Status: Fixed » Closed (fixed)

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

David_Rothstein’s picture

Version: 8.x-dev » 7.x-dev
Status: Closed (fixed) » Patch (to be ported)

It looks like some of this made it into Drupal 7 (probably via other issues), but not all of it.

dcam’s picture

Status: Patch (to be ported) » Needs review
FileSize
8.26 KB

Backported #12 to D7.

dcam’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Removing myself from the author field to unfollow the issue. --xjm

parthipanramesh’s picture

Seems to work fine. Thank you.

parthipanramesh’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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