1 common.test CommonJavaScriptTestCase::testDeprecatedBrowserConditionalComments()

Test deprecated conditional comments are no longer output.

Since Backdrop 1.27.0, the "browsers" option for backdrop_add_js() and backdrop_add_css() no longer outputs conditional comments, because conditional comments only work on IE 4-10 (which is completely unsupported). The "browsers" attribute still exists to prevent IE-only files from suddenly appearing on existing sites.

See also

backdrop_pre_render_conditional_comments()

File

core/modules/simpletest/tests/common.test, line 1485
Tests for common.inc functionality.

Class

CommonJavaScriptTestCase
Tests for the JavaScript system.

Code

function testDeprecatedBrowserConditionalComments() {
  $default_query_string = state_get('css_js_query_string', '0');

  backdrop_add_js('core/misc/collapse.js', array('browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE)));
  backdrop_add_js('jQuery(function () { });', array('type' => 'inline', 'browsers' => array('IE' => FALSE)));
  $javascript = backdrop_get_js();

  $expected_1 = '<script src="' . file_create_url('core/misc/collapse.js') . '?' . $default_query_string . '"></script>';
  $expected_2 = '<script>jQuery(function () { });</script>';

  $this->assertTrue(strpos($javascript, $expected_1) === FALSE, 'IE-only browser file not output at all.');
  $this->assertTrue(strpos($javascript, '<!--[if lte IE 8]>') === FALSE, 'IE conditional comment output is suppressed.');
  $this->assertTrue(strpos($javascript, $expected_2) > 0, 'Browsers except IE file output directly with no conditional comments.');
  $this->assertTrue(strpos($javascript, '<!--[if !IE]>') === FALSE, 'Not-IE conditional comment output is suppressed.');
}