1 common.test | CommonJavaScriptTestCase::testHeaderSetting() |
Test backdrop_get_js() for JavaScript settings.
File
- core/
modules/ simpletest/ tests/ common.test, line 1422 - Tests for common.inc functionality.
Class
- CommonJavaScriptTestCase
- Tests for the JavaScript system.
Code
function testHeaderSetting() {
// Only the second of these two entries should appear in Backdrop.settings.
backdrop_add_js(array('commonTest' => 'commonTestShouldNotAppear'), 'setting');
backdrop_add_js(array('commonTest' => 'commonTestShouldAppear'), 'setting');
// All three of these entries should appear in Backdrop.settings.
backdrop_add_js(array('commonTestArray' => array('commonTestValue0')), 'setting');
backdrop_add_js(array('commonTestArray' => array('commonTestValue1')), 'setting');
backdrop_add_js(array('commonTestArray' => array('commonTestValue2')), 'setting');
// Only the second of these two entries should appear in Backdrop.settings.
backdrop_add_js(array('commonTestArray' => array('key' => 'commonTestOldValue')), 'setting');
backdrop_add_js(array('commonTestArray' => array('key' => 'commonTestNewValue')), 'setting');
$javascript = backdrop_get_js('header');
$this->assertTrue(strpos($javascript, 'basePath') > 0, 'Rendered JavaScript header returns basePath setting.');
$this->assertTrue(strpos($javascript, 'core/misc/jquery.js') > 0, 'Rendered JavaScript header includes jQuery.');
$this->assertTrue(strpos($javascript, 'pathPrefix') > 0, 'Rendered JavaScript header returns pathPrefix setting.');
// Test whether backdrop_add_js can be used to override a previous setting.
$this->assertTrue(strpos($javascript, 'commonTestShouldAppear') > 0, 'Rendered JavaScript header returns custom setting.');
$this->assertTrue(strpos($javascript, 'commonTestShouldNotAppear') === FALSE, 'backdrop_add_js() correctly overrides a custom setting.');
// Test whether backdrop_add_js can be used to add numerically indexed values
// to an array.
$array_values_appear = strpos($javascript, 'commonTestValue0') > 0 && strpos($javascript, 'commonTestValue1') > 0 && strpos($javascript, 'commonTestValue2') > 0;
$this->assertTrue($array_values_appear, 'backdrop_add_js() correctly adds settings to the end of an indexed array.');
// Test whether backdrop_add_js can be used to override the entry for an
// existing key in an associative array.
$associative_array_override = strpos($javascript, 'commonTestNewValue') > 0 && strpos($javascript, 'commonTestOldValue') === FALSE;
$this->assertTrue($associative_array_override, 'backdrop_add_js() correctly overrides settings within an associative array.');
}