Hello everyone.

In drupal_web_test_case.php we've got a method

protected function drupalCreateNode($settings = array())

and if we pass such array as a parameter:

$settings = array('language' => 'en');

we'll get a fatal error in the line:

$settings['body'][$settings['language']][0] += $body;

As it's an equivalent of

$arr1 = array('some data');
$res = $arr1[4]['hi'] + array(1,2,3); // == null + array(1,2,3) == here we've got fatal error
print_r($res);

Comments

damienmckenna’s picture

StatusFileSize
new1.11 KB

I just ran into this while writing tests for Panelizer.

This changes the $settings+= logic to handle the 'body' field after the language is defined.

damienmckenna’s picture

Status: Active » Needs review
timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Seems logical

damienmckenna’s picture

The patch also lets my Panelizer tests pass :-)

damienmckenna’s picture

This is blocking my ability to have the tests in #2136205: Use translated node's modified panel instead of the default for content type? pass correctly.

damienmckenna’s picture

StatusFileSize
new1.26 KB
new2.37 KB

Now with tests.

The last submitted patch, 6: drupal-n2395385-6-TESTS-ONLY.patch, failed testing.

damienmckenna’s picture

It looks like the codebase has changed significantly in D8, so this issue may not still exist there.

berdir’s picture

This doesn't exist in 8.x, yes.

damienmckenna’s picture

There are already tests in D8 in LocaleContentTest::testContentTypeDirLang() to confirm this works, so yeah, it's D7 only.

David_Rothstein’s picture

Title: simpletest fatal error when creating a non language neutral node » simpletest fatal error when creating a non language neutral node and not specifying a node body
Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

I think the previous code assumed that if you were specifying a language you'd be manually specifying a body in that language also, but I agree this is better.

Minor fixes on commit:

diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 11b49ed..622e1de 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -2242,14 +2242,13 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
    * Verifies that nodes may be created with different languages.
    */
   function testNodeCreationWithLanguage() {
-    // Create an admin user, log them in.
+    // Create an admin user and log them in.
     $perms = array(
       // Standard node permissions.
       'create page content',
       'administer content types',
       'administer nodes',
       'bypass node access',
-
       // Locale.
       'administer languages',
     );
@@ -2265,7 +2264,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
       );
       $node = $this->drupalCreateNode($node_args);
       $node_reloaded = node_load($node->nid, NULL, TRUE);
-      $this->assertEqual($node_reloaded->language, $langcode, 'The language code of the node was successfully set to ' . $langcode . '.');
+      $this->assertEqual($node_reloaded->language, $langcode, format_string('The language code of the node was successfully set to @langcode.', array('@langcode' => $langcode)));
     }
   }

I also wonder if this belongs more in simpletest.test than locale.test since it's testing a simpletest helper method -- although I guess it's sort of testing both that and node_save() itself, so it's OK.

  • David_Rothstein committed a95cb56 on 7.x
    Issue #2395385 by DamienMcKenna: simpletest fatal error when creating a...
damienmckenna’s picture

Thanks David_Rothstein!

Status: Fixed » Closed (fixed)

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