Commit 4a32c5d3 authored by webchick's avatar webchick
Browse files

Issue #1764634 by tim.plunkett, nod_: Fixed Drupal.settings is only populated...

Issue #1764634 by tim.plunkett, nod_: Fixed Drupal.settings is only populated if a custom setting is added.
parent c58b08ae
......@@ -77,7 +77,6 @@ function testAddFile() {
function testAddSetting() {
// Add a file in order to test default settings.
drupal_add_library('system', 'drupal.settings');
drupal_add_js(array('dummy' => 'value'), 'setting');
$javascript = drupal_add_js();
$last_settings = reset($javascript['settings']['data']);
$this->assertTrue($last_settings['currentPath'], 'The current path JavaScript setting is set correctly.');
......@@ -138,6 +137,15 @@ function testDeferAttribute() {
*/
function testHeaderSetting() {
drupal_add_library('system', 'drupal.settings');
$javascript = drupal_get_js('header');
$this->assertTrue(strpos($javascript, 'basePath') > 0, 'Rendered JavaScript header returns basePath setting.');
$this->assertTrue(strpos($javascript, 'scriptPath') > 0, 'Rendered JavaScript header returns scriptPath setting.');
$this->assertTrue(strpos($javascript, 'pathPrefix') > 0, 'Rendered JavaScript header returns pathPrefix setting.');
$this->assertTrue(strpos($javascript, 'currentPath') > 0, 'Rendered JavaScript header returns currentPath setting.');
$this->assertTrue(strpos($javascript, 'core/misc/drupal.js') > 0, 'Rendered JavaScript header includes Drupal.js.');
$this->assertTrue(strpos($javascript, 'core/misc/jquery.js') > 0, 'Rendered JavaScript header includes jQuery.');
// Only the second of these two entries should appear in Drupal.settings.
drupal_add_js(array('commonTest' => 'commonTestShouldNotAppear'), 'setting');
drupal_add_js(array('commonTest' => 'commonTestShouldAppear'), 'setting');
......@@ -150,12 +158,6 @@ function testHeaderSetting() {
drupal_add_js(array('commonTestArray' => array('key' => 'commonTestNewValue')), 'setting');
$javascript = drupal_get_js('header');
$this->assertTrue(strpos($javascript, 'basePath') > 0, 'Rendered JavaScript header returns basePath setting.');
$this->assertTrue(strpos($javascript, 'scriptPath') > 0, 'Rendered JavaScript header returns scriptPath setting.');
$this->assertTrue(strpos($javascript, 'pathPrefix') > 0, 'Rendered JavaScript header returns pathPrefix setting.');
$this->assertTrue(strpos($javascript, 'currentPath') > 0, 'Rendered JavaScript header returns currentPath setting.');
$this->assertTrue(strpos($javascript, 'core/misc/jquery.js') > 0, 'Rendered JavaScript header includes jQuery.');
// Test whether drupal_add_js can be used to override a previous setting.
$this->assertTrue(strpos($javascript, 'commonTestShouldAppear') > 0, t('Rendered JavaScript header returns custom setting.'));
$this->assertTrue(strpos($javascript, 'commonTestShouldNotAppear') === FALSE, t('drupal_add_js() correctly overrides a custom setting.'));
......
......@@ -1212,6 +1212,9 @@ function system_library_info() {
$libraries['drupal.settings'] = array(
'title' => 'Drupal Settings',
'version' => VERSION,
'js' => array(
array('type' => 'setting', 'data' => array()),
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
......
......@@ -273,7 +273,6 @@ function common_test_library_info() {
*/
function common_test_js_and_css_querystring() {
drupal_add_library('system', 'drupal.settings');
drupal_add_js(array('dummy' => 'value'), 'setting');
drupal_add_js(drupal_get_path('module', 'node') . '/node.js');
drupal_add_css(drupal_get_path('module', 'node') . '/node.admin.css');
// A relative URI may have a query string.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment