summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/common.test50
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() {