diff options
author | Dries Buytaert <dries@buytaert.net> | 2011-02-04 21:36:31 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2011-02-04 21:36:31 +0000 |
commit | 2b3c728a56c4d081039e2bff0f5615a970a60f94 (patch) | |
tree | 2a484e6922bcf954df1fbb93191ba73c68c6ff16 /modules | |
parent | 25a4309ed0f7d9401e0a8b0fe560e77af6c684ce (diff) | |
download | brdo-2b3c728a56c4d081039e2bff0f5615a970a60f94.tar.gz brdo-2b3c728a56c4d081039e2bff0f5615a970a60f94.tar.bz2 |
- Patch #859602 by catch, bfroehle: #cache does not record the #attached declared in child elements.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/common.test | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index ca29e11f8..f48497559 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1522,6 +1522,56 @@ class DrupalRenderTestCase extends DrupalWebTestCase { } /** + * Test #attached functionality in children elements. + */ + function testDrupalRenderChildrenAttached() { + // The cache system is turned off for POST requests. + $request_method = $_SERVER['REQUEST_METHOD']; + $_SERVER['REQUEST_METHOD'] = 'GET'; + + // Create an element with a child and subchild. Each element loads a + // different JavaScript file using #attached. + $parent_js = drupal_get_path('module', 'user') . '/user.js'; + $child_js = drupal_get_path('module', 'forum') . '/forum.js'; + $subchild_js = drupal_get_path('module', 'book') . '/book.js'; + $element = array( + '#type' => 'fieldset', + '#cache' => array( + 'keys' => array('simpletest', 'drupal_render', 'children_attached'), + ), + '#attached' => array('js' => array($parent_js)), + '#title' => 'Parent', + ); + $element['child'] = array( + '#type' => 'fieldset', + '#attached' => array('js' => array($child_js)), + '#title' => 'Child', + ); + $element['child']['subchild'] = array( + '#attached' => array('js' => array($subchild_js)), + '#markup' => 'Subchild', + ); + + // Render the element and verify the presence of #attached JavaScript. + drupal_render($element); + $scripts = drupal_get_js(); + $this->assertTrue(strpos($scripts, $parent_js), t('The element #attached JavaScript was included.')); + $this->assertTrue(strpos($scripts, $child_js), t('The child #attached JavaScript was included.')); + $this->assertTrue(strpos($scripts, $subchild_js), t('The subchild #attached JavaScript was included.')); + + // Load the element from cache and verify the presence of the #attached + // JavaScript. + drupal_static_reset('drupal_add_js'); + $this->assertTrue(drupal_render_cache_get($element), t('The element was retrieved from cache.')); + $scripts = drupal_get_js(); + $this->assertTrue(strpos($scripts, $parent_js), t('The element #attached JavaScript was included when loading from cache.')); + $this->assertTrue(strpos($scripts, $child_js), t('The child #attached JavaScript was included when loading from cache.')); + $this->assertTrue(strpos($scripts, $subchild_js), t('The subchild #attached JavaScript was included when loading from cache.')); + + $_SERVER['REQUEST_METHOD'] = $request_method; + } + + /** * Test passing arguments to the theme function. */ function testDrupalRenderThemeArguments() { |