function JavaScriptTest::testAlter

Tests altering a JavaScript's weight via hook_js_alter().

See also

simpletest_js_alter()

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php, line 458
Definition of Drupal\system\Tests\Common\JavaScriptTest.

Class

JavaScriptTest
Tests the JavaScript system.

Namespace

Drupal\system\Tests\Common

Code

function testAlter() {

  // Add both tableselect.js and simpletest.js, with a larger weight on SimpleTest.
  drupal_add_js('core/misc/tableselect.js');
  drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', array(
    'weight' => 9999,
  ));

  // Render the JavaScript, testing if simpletest.js was altered to be before
  // tableselect.js. See simpletest_js_alter() to see where this alteration
  // takes place.
  $javascript = drupal_get_js();
  $this
    ->assertTrue(strpos($javascript, 'simpletest.js') < strpos($javascript, 'core/misc/tableselect.js'), 'Altering JavaScript weight through the alter hook.');
}