Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Version: 8.x-dev » 7.x-dev
FileSize
532 bytes

patch for D7

Anonymous’s picture

Status: Needs review » Needs work

i'm not sure if the bug here is the we use $t(), or that we don't have a $t = get_t(); - can someone with FAPI clue comment on this?

also, lets sort it out for D8 before doing the port to D7.

sun’s picture

Version: 7.x-dev » 8.x-dev

This needs to use

$t = get_t();

typically done as first line of the function.

sun’s picture

Title: Typo in form_pre_render_conditional_form_element() » $t not defined in form_pre_render_conditional_form_element()
Issue tags: +Needs backport to D7
andypost’s picture

Status: Needs work » Needs review
FileSize
586 bytes

I see no way to test this so simple fix.

andypost’s picture

added comment about get_t()

sun’s picture

Status: Needs review » Reviewed & tested by the community

No need for a comment, so #5 is RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This seems to have spotted a hole in our test suite. Could we adjust the tests so this function gets hit?

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
3.87 KB
2.4 KB

This functionality was totally broken

So I write a test and improved patch

andypost’s picture

Removed commented line in test

sun’s picture

The test does not seem to fully trigger the error for some reason. I don't see a fatal error in the testbot results?

Trying to invoke a function name in a undefined string should yield a fatal error:

> php -r "print $t('foo'); print 'bar';"

Notice: Undefined variable: t in Command line code on line 1

Call Stack:
    0.0003     317704   1. {main}() Command line code:0

Fatal error: Function name must be a string in Command line code on line 1

Call Stack:
    0.0003     317704   1. {main}() Command line code:0
andypost’s picture

@sun suppose it depends on bot's php.ini settings
probably core take over a fatal error because it happens in eval() of theme()...wtf!?

because if I enable form_test module with drush and navigate to /form_test/form-labels I got a page without form and not styled. watchdog has only

Notice: Undefined variable: t in form_pre_render_conditional_form_element() (line 3034 of /var/www/core8/core/includes/form.inc).

page get rendered for until title only http://clip2net.com/s/1xJ9n

sun’s picture

Please disregard #11, we see the PHP notice in the tests. The fatal error happens in the child site. We'd only see the fatal error if the test itself would attempt to render the form element in the parent site.

andypost’s picture

@sun so #10 should fix bug or do you have something oposit?

andypost’s picture

This issue now depends on wrong commited patch in #1475666: Rollback - PHP error because of typo in form.inc line 3025

webchick’s picture

That patch was rolled back, so we should be good to go here.

Niklas Fiekas’s picture

Priority: Normal » Major

Yep. And #1475666: Rollback - PHP error because of typo in form.inc line 3025 was major. (Not sure if it should have been.)

andypost’s picture

#10: 1421410-title-attribute.patch queued for re-testing.

# patch -p1 --dry-run < 1421410-title-attribute.patch
patching file core/includes/form.inc
patching file core/modules/simpletest/tests/form.test
Hunk #1 succeeded at 740 (offset 8 lines).
patching file core/modules/simpletest/tests/form_test.module
Niklas Fiekas’s picture

Status: Needs review » Needs work

Lets get this done ... here's a review:

+++ b/core/includes/form.incundefined
@@ -2753,6 +2753,9 @@ function theme_radios($variables) {
+  if (!empty($element['#attributes']['title'])) {

Shouldn't we use isset() here? Otherwise '0' couldn't be used as a title, could it?

+++ b/core/includes/form.incundefined
@@ -3014,6 +3017,9 @@ function theme_checkboxes($variables) {
+  if (!empty($element['#attributes']['title'])) {

Same here. We also wouldn't need the negation.

+++ b/core/modules/simpletest/tests/form.testundefined
@@ -664,6 +664,12 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase {
+    $this->assertEqual($elements[0]['title'], t('Checkboxes test') . ' (' . t('Required') . ')', t('Title attribute found.'));

The assertion message shouldn't have a t().

+++ b/core/modules/simpletest/tests/form.testundefined
@@ -664,6 +664,12 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase {
+    $this->assertEqual($elements[0]['title'], t('Radios test') . ' (' . t('Required') . ')', t('Title attribute found.'));

Neither this one. (Yes, t() in assertion messages are all around, but cleaning that up is another issue.)

+++ b/core/modules/simpletest/tests/form_test.moduleundefined
@@ -752,10 +752,31 @@ function form_label_test_form() {
-  // Textfield test for title set not to display
+  // Textfield test for title set not to display.

Baby-kitten hunk. (Just saying. If it's here anyway, let's get it in.)

+++ b/core/modules/simpletest/tests/form_test.moduleundefined
@@ -752,10 +752,31 @@ function form_label_test_form() {
+    '#title' => t('Checkboxes test'),
+    '#options' => array(
+      'first-checkbox' => t('First checkbox'),
+      'second-checkbox' => t('Second checkbox'),

t() in a test again. The rule is not to introduce any *new* translatable strings. So simply remove them.

+++ b/core/modules/simpletest/tests/form_test.moduleundefined
@@ -752,10 +752,31 @@ function form_label_test_form() {
+    '#title' => t('Radios test'),
+    '#options' => array(
+      'first-radio' => t('First radio'),
+      'second-radio' => t('Second radio'),

Here, as well.

andypost’s picture

Status: Needs work » Needs review
FileSize
3.76 KB

Talked in IRC with Niklas Fiekas :
1) isset() is a right choice for string item
2) Removed t() in assert message
3) Baby-kitten hunk. :)
4) keep t() for the form builder items to mimic form_label_test_form() previous elements

Niklas Fiekas’s picture

I don't agree with 4 - very minor point, though, as xjm said. Looks good otherwise. Thank you @andypost!

andypost’s picture

The only t() in test form is waiting for review, but I sure we should use t() because this labels are used in assert.

+++ b/core/modules/simpletest/tests/form.testundefined
@@ -740,6 +740,12 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase {
+    $this->assertEqual($elements[0]['title'], t('Checkboxes test') . ' (' . t('Required') . ')', 'Title attribute found.');

Also this introduces no new strings

+++ b/core/modules/simpletest/tests/form_test.moduleundefined
@@ -817,10 +817,31 @@ function form_label_test_form() {
+    '#title' => t('Checkboxes test'),
+    '#options' => array(
+      'first-checkbox' => t('First checkbox'),
+      'second-checkbox' => t('Second checkbox'),

This strings already used above in this function and test should check for translated element title

Niklas Fiekas’s picture

It introduces no new t()'s because some wrong t()'s are already there. That doesn't count :P

Actually it's about decoupling and stuff. Before were discussing "must we really do this" over and over, here is a slightly adjusted patch. No other changes than this minor stuff.

andypost’s picture

Let's get more reviews

+++ b/core/modules/simpletest/tests/form.testundefined
@@ -785,6 +785,12 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase {
+    $this->assertEqual($elements[0]['title'], 'Checkboxes test' . ' (' . t('Required') . ')', 'Title attribute found.');

This mix of t() and 'Checkboxes test' looks unreadable

+++ b/core/modules/simpletest/tests/form.testundefined
@@ -785,6 +785,12 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase {
+    $this->assertEqual($elements[0]['title'], 'Radios test' . ' (' . t('Required') . ')', 'Title attribute found.');

same

xjm’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs backport to D7

@andypost asked me to comment on this issue. It's a little messy but I don't think it's that bad, and honestly I can't think of a better way. This patch looks ready to me.

Edit: Didn't mean to take the backport tag off; not sure why that happened.

andypost’s picture

Issue tags: +Needs backport to D7

I does not want to hold a patch...

talked with xjm - let's proceed with this spaghetti mix of t() and ''
all other parts of this test method uses t() but probably there's a principle

... but for D7 we need a cleaner code, with follow-up for D8

xjm’s picture

To clarify, core already has an inconsistent mix of using t() and not in test modules, so I don't think it's worth holding the patch back one way or the other. There are arguments both for and against in this case, but at the end of the day it really doesn't make much difference, and I am not comfortable saying it should be one way or another because there isn't consensus. Edit: we have a brief discussion of this point at http://drupal.org/simpletest-tutorial-drupal7#t and the issue to bikeshed about it in is #500866: [META] remove t() from assert message.

The patch is also fine to backport as-is.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Looks sane to me. Thanks a bunch for the tests!

Committed and pushed to 8.x and 7.x.

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