From 139da4501d67828f0db6943264e80358ee0b72d7 Mon Sep 17 00:00:00 2001
From: David Meister <thedavidmeister@gmail.com>
Date: Mon, 10 Jun 2013 01:05:45 +1000
Subject: [PATCH] 2012818-14-test

---
 .../lib/Drupal/system/Tests/Common/RenderTest.php  | 29 ++++++++++++++++++++++
 .../tests/modules/common_test/common_test.module   | 19 ++++++++++++++
 2 files changed, 48 insertions(+)

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 31e4f34..58aece7 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
@@ -384,4 +384,33 @@ function testDrupalRenderCache() {
     // Restore the previous request method.
     $_SERVER['REQUEST_METHOD'] = $request_method;
   }
+
+  /**
+   * Tests that #type is handled correctly.
+   */
+  function testDrupalRenderType() {
+    // Theme suggestion is not implemented, #markup should be the fallback.
+    // #type is not set, should inherit #type 'markup' #pre_render from
+    // common_test_element_info_alter() and therefore #prefix 'foo'.
+    $build = array(
+      '#theme' => array('suggestionnotimplemented'),
+      '#markup' => 'bar',
+      '#prefixme' => TRUE,
+    );
+    $rendered = drupal_render($build);
+    $this->assertIdentical($rendered, 'foobar');
+
+    // Theme is implemented, #markup should not be rendered.
+    // #type is not set but since #markup should not be rendered #pre_render
+    // should also not be inherited from #type 'markup'.
+    $build = array(
+      '#theme' => 'common_test_foo',
+      '#foo' => 'one',
+      '#bar' => 'two',
+      '#markup' => 'bar',
+      '#prefixme' => TRUE,
+    );
+    $rendered = drupal_render($build);
+    $this->assertIdentical($rendered, 'onetwo');
+  }
 }
diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module
index febfd3a..6412bb8 100644
--- a/core/modules/system/tests/modules/common_test/common_test.module
+++ b/core/modules/system/tests/modules/common_test/common_test.module
@@ -334,3 +334,22 @@ function common_test_js_and_css_querystring() {
 function common_test_cron() {
   throw new Exception(t('Uncaught exception'));
 }
+
+/**
+ * Implements hook_element_info().
+ *
+ * Adds a #pre_render to #type 'markup'.
+ */
+function common_test_element_info_alter(&$type) {
+  $type['markup']['#pre_render'] = array('common_test_prefix_renderable_array');
+}
+
+/**
+ * Attempt to add a prefix to the passed renderable array.
+ */
+function common_test_prefix_renderable_array($element) {
+  if (!empty($element['#prefixme'])) {
+    $element['#prefix'] = 'foo';
+  }
+  return $element;
+}
-- 
1.7.11.1

