示例#1
0
 /**
  * Tests AjaxResponse::prepare() AJAX commands ordering.
  */
 public function testOrder()
 {
     $path = drupal_get_path('module', 'system');
     $expected_commands = array();
     // Expected commands, in a very specific order.
     $expected_commands[0] = new SettingsCommand(array('ajax' => 'test'), TRUE);
     drupal_static_reset('_drupal_add_css');
     $attached = array('#attached' => array('css' => array($path . '/css/system.admin.css' => array(), $path . '/css/system.maintenance.css' => array())));
     drupal_render($attached);
     drupal_process_attached($attached);
     $expected_commands[1] = new AddCssCommand(drupal_get_css(_drupal_add_css(), TRUE));
     drupal_static_reset('_drupal_add_js');
     $attached = array('#attached' => array('js' => array($path . '/system.js' => array())));
     drupal_render($attached);
     drupal_process_attached($attached);
     $expected_commands[2] = new PrependCommand('head', drupal_get_js('header', _drupal_add_js(), TRUE));
     drupal_static_reset('_drupal_add_js');
     $attached = array('#attached' => array('js' => array($path . '/system.modules.js' => array('scope' => 'footer'))));
     drupal_render($attached);
     drupal_process_attached($attached);
     $expected_commands[3] = new AppendCommand('body', drupal_get_js('footer', _drupal_add_js(), TRUE));
     $expected_commands[4] = new HtmlCommand('body', 'Hello, world!');
     // Load any page with at least one CSS file, at least one JavaScript file
     // and at least one #ajax-powered element. The latter is an assumption of
     // drupalPostAjaxForm(), the two former are assumptions of
     // AjaxReponse::ajaxRender().
     // @todo refactor AJAX Framework + tests to make less assumptions.
     $this->drupalGet('ajax_forms_test_lazy_load_form');
     // Verify AJAX command order — this should always be the order:
     // 1. JavaScript settings
     // 2. CSS files
     // 3. JavaScript files in the header
     // 4. JavaScript files in the footer
     // 5. Any other AJAX commands, in whatever order they were added.
     $commands = $this->drupalPostAjaxForm(NULL, array(), NULL, 'ajax-test/order', array(), array(), NULL, array());
     $this->assertCommand(array_slice($commands, 0, 1), $expected_commands[0]->render(), 'Settings command is first.');
     $this->assertCommand(array_slice($commands, 1, 1), $expected_commands[1]->render(), 'CSS command is second (and CSS files are ordered correctly).');
     $this->assertCommand(array_slice($commands, 2, 1), $expected_commands[2]->render(), 'Header JS command is third.');
     $this->assertCommand(array_slice($commands, 3, 1), $expected_commands[3]->render(), 'Footer JS command is fourth.');
     $this->assertCommand(array_slice($commands, 4, 1), $expected_commands[4]->render(), 'HTML command is fifth.');
 }
 /**
  * Tests that CSS query string remains intact when added to file.
  */
 function testAddCssFileWithQueryString()
 {
     $css_without_query_string = drupal_get_path('module', 'node') . '/css/node.admin.css';
     $css_with_query_string = '/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2';
     _drupal_add_css($css_without_query_string);
     _drupal_add_css($css_with_query_string);
     $styles = drupal_get_css();
     $query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0';
     $this->assertTrue(strpos($styles, $css_without_query_string . '?' . $query_string), 'Query string was appended correctly to css.');
     $this->assertTrue(strpos($styles, str_replace('&', '&', $css_with_query_string)), 'Query string not escaped on a URI.');
 }
示例#3
0
 /**
  * Tests css/js storage and restoring mechanism.
  */
 function testHeaderStorage()
 {
     // Create a view with output caching enabled.
     // Some hook_views_pre_render in views_test_data.module adds the test css/js file.
     // so they should be added to the css/js storage.
     $view = Views::getView('test_view');
     $view->setDisplay();
     $view->storage->set('id', 'test_cache_header_storage');
     $view->display_handler->overrideOption('cache', array('type' => 'time', 'options' => array('output_lifespan' => '3600')));
     $output = $view->preview();
     drupal_render($output);
     unset($view->pre_render_called);
     drupal_static_reset('_drupal_add_css');
     drupal_static_reset('_drupal_add_js');
     $view->destroy();
     $view->setDisplay();
     $output = $view->preview();
     drupal_render($output);
     $css = _drupal_add_css();
     $css_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.css';
     $js_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.js';
     $js = _drupal_add_js();
     $this->assertTrue(isset($css[basename($css_path)]), 'Make sure the css is added for cached views.');
     $this->assertTrue(isset($js[$js_path]), 'Make sure the js is added for cached views.');
     $this->assertFalse(!empty($view->build_info['pre_render_called']), 'Make sure hook_views_pre_render is not called for the cached view.');
     // Now add some css/jss before running the view.
     // Make sure that this css is not added when running the cached view.
     $view->storage->set('id', 'test_cache_header_storage_2');
     $attached = array('#attached' => array('css' => array(drupal_get_path('module', 'system') . '/css/system.maintenance.css' => array()), 'js' => array(drupal_get_path('module', 'user') . '/user.permissions.js' => array())));
     drupal_render($attached);
     $view->destroy();
     $output = $view->preview();
     drupal_render($output);
     drupal_static_reset('_drupal_add_css');
     drupal_static_reset('_drupal_add_js');
     $view->destroy();
     $output = $view->preview();
     drupal_render($output);
     $css = _drupal_add_css();
     $js = _drupal_add_js();
     $this->assertFalse(isset($css['system.maintenance.css']), 'Make sure that unrelated css is not added.');
     $this->assertFalse(isset($js[drupal_get_path('module', 'user') . '/user.permissions.js']), 'Make sure that unrelated js is not added.');
 }