You are here

function JavaScriptLibrariesDrupalTestCase::testEnableDisableLibrary in JavaScript Libraries Manager 7

Test adding and removing built-in libraries.

File

tests/javascript_libraries.test, line 125

Class

JavaScriptLibrariesDrupalTestCase

Code

function testEnableDisableLibrary() {
  variable_set('preprocess_js', FALSE);

  // Verify that anonymous users cannot access admin pages.
  $this
    ->drupalGet('admin/config/system/javascript-libraries');
  $this
    ->assertResponse(403, 'admin/config/system/javascript-libraries');
  $this
    ->drupalGet('admin/config/system/javascript-libraries/default');
  $this
    ->assertResponse(403, 'admin/config/system/javascript-libraries/default');
  $web_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
    'view the administration theme',
  ));
  $this
    ->drupalLogin($web_user);
  $edit = array();
  $edit['enable[system-ui-datepicker]'] = TRUE;
  $this
    ->drupalPost('admin/config/system/javascript-libraries', $edit, t('Save'));
  $this
    ->drupalGet('admin/config/system/javascript-libraries');
  $this
    ->assertText('jQuery UI: Autocomplete', 'Found jQuery UI: Autocomplete library');
  $this
    ->assertFieldChecked("edit-enable-system-ui-datepicker", 'jQuery UI datepicker is marked as enabled');

  // Make sure the script does not appear in the head of this admin page.
  $this
    ->assertNoPattern('@<script type="text/javascript" src="http[^"]+/misc/ui/jquery.ui.datepicker.min.js\\?[^"]+"></script>@');

  // Make sure the script appears in the head of a non-admin page.
  $this
    ->drupalGet('node');
  $this
    ->assertPattern('@<script type="text/javascript" src="http[^"]+/misc/ui/jquery.ui.datepicker.min.js\\?[^"]+"></script>@');
}