When a page is loaded using DrupalWebTestCase::drupalGet() Drupal settings from javascript is parsed and put into DrupalWebTestCase::drupalSettings.

This is done using a regular expression. This expression does not always return the entire settings json.

It lazily tries to find ); and the Drupal.settings json might contain those characters without it being an error.

Matching it without using laziness is not desirable, as another ); later on the page will have this return to much.

The only solution i see is to modify core, adding some sort of comment at the end of the settings json stating that it has ended here:

includes/common.inc line 4374 in current 7.x-dev from January 22, 2015 - 06:28

$js_element['#value'] = 'jQuery.extend(Drupal.settings, ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ");/*Drupal.settings end*/";

And change the preg match to search for this:

modules/simpletest/drupal_web_test_case.php line 2902 in current 7.x-dev from January 22, 2015 - 06:28

if (preg_match('/jQuery\.extend\(Drupal\.settings, (.*?)\);\/\*Drupal.settings end\*\//', $content, $matches)) {

Patch attached.

Comments

mian3010’s picture

mian3010’s picture

Status: Active » Closed (duplicate)

I see this is a duplicate of issue https://www.drupal.org/node/1816556, sorry