function JavaScriptTest::testLibraryRender

Adds a library to the page and tests for both its JavaScript and its CSS.

File

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

Class

JavaScriptTest
Tests the JavaScript system.

Namespace

Drupal\system\Tests\Common

Code

function testLibraryRender() {
  $result = drupal_add_library('system', 'jquery.farbtastic');
  $this
    ->assertTrue($result !== FALSE, 'Library was added without errors.');
  $scripts = drupal_get_js();
  $styles = drupal_get_css();
  $this
    ->assertTrue(strpos($scripts, 'core/misc/farbtastic/farbtastic.js'), 'JavaScript of library was added to the page.');
  $this
    ->assertTrue(strpos($styles, 'core/misc/farbtastic/farbtastic.css'), 'Stylesheet of library was added to the page.');
  $result = drupal_add_library('common_test', 'shorthand.plugin');
  $path = drupal_get_path('module', 'common_test') . '/js/shorthand.js';
  $scripts = drupal_get_js();
  $this
    ->assertTrue(strpos($scripts, $path), 'JavaScript specified in hook_library_info() using shorthand format (without any options) was added to the page.');
}