Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Title: I don't think _simpletest_format_summary_line() should be translating its output? » _simpletest_format_summary_line() should not use t()

Hah, thanks for pointing this out -- it might resolve some weird PHP shutdown function fatal errors I'm getting in
#1808220: Remove run-tests.sh dependency on existing/installed parent site

However, for Simpletest itself, I'm not sure whether this is required. The summary line is (or should be) printed in the full/regular environment of the parent site that runs a test.

jhodgdon’s picture

Really, it needs to be translated? None of the assert messages are being translated, so I figured we also shouldn't translate the summary line?

If it does need to be translated, we should just close this as 'works as designed'. Or are you saying it needs to use st() or $t instead of t()?

jhodgdon’s picture

Oh, and if it can't use t(), then it also probably can't use format_plural(), right?

sun’s picture

Yeah, I don't really care... Simpletest module generally becomes exempt from t()/localization rules, it seems.

So we can remove the t()/format_plural() calls here, like this:

+function _simpletest_format_summary_line($summary) {
+  $summary += array(
+    '#pass' => 0,
+    '#fail' => 0,
+    '#exception' => 0,
+    '#debug' => 0,
+  );
+  $args = array(
+    '@pass' => $summary['#pass'] == 1 ? '1 pass' : $summary['#pass'] . ' passes',
+    '@fail' => $summary['#fail'] == 1 ? '1 fail' : $summary['#fail'] . ' fails',
+    '@exception' => $summary['#exception'] == 1 ? '1 exception' : $summary['#exception'] . ' exceptions',
+  );
+  if (!$summary['#debug']) {
+    return format_string('@pass, @fail, and @exception', $args);
+  }
+  $args['@debug'] = $summary['#debug'] == 1 ? '1 debug message' : $summary['#debug'] . ' debug messages';
+  return format_string('@pass, @fail, @exception, and @debug', $args);
+}

Closely related: #1601146: Allow custom assertion messages using predefined placeholders

sun’s picture

Assigned: Unassigned » sun
Issue summary: View changes
Status: Active » Needs review
FileSize
2.37 KB

Picking this up again. The summary should still not be translated today.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! I have tested this patch manually in the Simpletest UI and it works fine.

I think the approach is good. It updates the tests properly and the slight change to having "and" vs. not having "and" in the test summary string is IMO fine.

Let's get it in -- we simply don't need to be translating these strings since we've decided everywhere else in the Simpletest UI that we are not translating.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

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