commit a1a79bb61c656c03f876ff48a62710e4d4e37dbf Author: gnuget Date: Tue Jan 21 21:56:54 2014 -0600 2152207-6 Providing xpath equivalent tests diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php index f8dfb05..1403c95 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php @@ -598,7 +598,7 @@ function testDrupalRenderChildrenPostRenderCache() { $element = array('#cache' => $element['#cache']); $cached_element = cache()->get(drupal_render_cid_create($element))->data; $expected_element = array( - '#markup' => '
Parent
Child
Subchild
', + '#markup' => '', '#attached' => array( 'js' => array( array('type' => 'setting', 'data' => array('foo' => 'bar')) @@ -616,7 +616,19 @@ function testDrupalRenderChildrenPostRenderCache() { ) ), ); - $this->assertIdentical($cached_element, $expected_element, 'The correct data is cached: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.'); + + $dom = filter_dom_load($cached_element['#markup']); + $xpath = new \DOMXPath($dom); + $parent = $xpath->query('//details[@class="form-wrapper" and @open="open"]/summary[@role="button" and @aria-expanded and text()="Parent"]')->length; + $child = $xpath->query('//details[@class="form-wrapper" and @open="open"]/div[@class="details-wrapper"]/details[@class="form-wrapper" and @open="open"]/summary[@role="button" and @aria-expanded and text()="Child"]')->length; + $subchild = $xpath->query('//details[@class="form-wrapper" and @open="open"]/div[@class="details-wrapper"]/details[@class="form-wrapper" and @open="open"]/div [@class="details-wrapper" and text()="Subchild"]')->length; + + $this->assertTrue($parent && $child && $subchild, 'The correct data is cached: the stored #markup is not affected by #post_render_cache callbacks.'); + + unset($cached_element['#markup']); + unset($expected_element['#markup']); + + $this->assertIdentical($cached_element, $expected_element, 'The correct data is cached: the stored #attached properties are not affected by #post_render_cache callbacks.'); // GET request: #cache enabled, cache hit. drupal_static_reset('_drupal_add_js'); @@ -672,7 +684,7 @@ function testDrupalRenderChildrenPostRenderCache() { $cached_parent_element = cache()->get(drupal_render_cid_create($element))->data; $cached_child_element = cache()->get(drupal_render_cid_create($element['child']))->data; $expected_parent_element = array( - '#markup' => '
Parent
Child
Subchild
', + '#markup' => '', '#attached' => array( 'js' => array( array('type' => 'setting', 'data' => array('foo' => 'bar')) @@ -690,9 +702,20 @@ function testDrupalRenderChildrenPostRenderCache() { ) ), ); - $this->assertIdentical($cached_parent_element, $expected_parent_element, 'The correct data is cached for the parent: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.'); + + $dom = filter_dom_load($cached_parent_element['#markup']); + $xpath = new \DOMXPath($dom); + $parent = $xpath->query('//details[@class="form-wrapper" and @open="open"]/summary[@role="button" and @aria-expanded and text()="Parent"]')->length; + $child = $xpath->query('//details[@class="form-wrapper" and @open="open"]/div[@class="details-wrapper"]/details[@class="form-wrapper" and @open="open"]/summary[@role="button" and @aria-expanded and text()="Child"]')->length; + $subchild = $xpath->query('//details[@class="form-wrapper" and @open="open"]/div[@class="details-wrapper"]/details[@class="form-wrapper" and @open="open"]/div [@class="details-wrapper" and text()="Subchild"]')->length; + $this->assertTrue($parent && $child && $subchild, 'The correct data is cached for the parent: the stored #markup is not affected by #post_render_cache callbacks.'); + + unset($cached_parent_element['#markup']); + unset($expected_parent_element['#markup']); + $this->assertIdentical($cached_parent_element, $expected_parent_element, 'The correct data is cached for the parent: the stored #attached properties are not affected by #post_render_cache callbacks.'); + $expected_child_element = array( - '#markup' => '
Child
Subchild
', + '#markup' => '', '#attached' => array( 'library' => array( array('system', 'drupal.collapse'), @@ -705,7 +728,16 @@ function testDrupalRenderChildrenPostRenderCache() { ) ), ); - $this->assertIdentical($cached_child_element, $expected_child_element, 'The correct data is cached for the child: the stored #markup and #attached properties are not affected by #post_render_cache callbacks.'); + + $dom = filter_dom_load($cached_child_element['#markup']); + $xpath = new \DOMXPath($dom); + $child = $xpath->query('//details[@class="form-wrapper" and @open="open"]/summary[@role="button" and @aria-expanded and text()="Child"]')->length; + $subchild = $xpath->query('//details[@class="form-wrapper" and @open="open"]/div [@class="details-wrapper" and text()="Subchild"]')->length; + $this->assertTrue($child && $subchild, 'The correct data is cached for the child: the stored #markup is not affected by #post_render_cache callbacks.'); + + unset($cached_child_element['#markup']); + unset($expected_child_element['#markup']); + $this->assertIdentical($cached_child_element, $expected_child_element, 'The correct data is cached for the child: the stored #attached properties are not affected by #post_render_cache callbacks.'); // GET request: #cache enabled, cache hit, parent element. drupal_static_reset('_drupal_add_js');