From 4d6c1929f5078fd6005459cc005640c1753dc4b3 Mon Sep 17 00:00:00 2001
From: Dan Mouyard <dcmouyard@gmail.com>
Date: Thu, 12 Apr 2012 08:43:38 -0400
Subject: [PATCH] Issue #1468582: Add mobile friendly meta tags to the html.tpl.php.

---
 core/includes/theme.inc                            |    3 +
 core/modules/system/html.tpl.php                   |    8 ++++
 core/modules/system/system.test                    |   44 ++++++++++++++++++++
 core/modules/system/tests/system_module_test.info  |    7 +++
 .../modules/system/tests/system_module_test.module |   10 ++++
 5 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 core/modules/system/tests/system_module_test.info
 create mode 100644 core/modules/system/tests/system_module_test.module

diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index f5c25f9..97a8ef7 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2535,6 +2535,9 @@ function template_preprocess_html(&$variables) {
   $variables['head_title_array'] = $head_title;
   $variables['head_title'] = implode(' | ', $head_title);
 
+  // Display the html.tpl.php’s default mobile metatags for responsive design.
+  $variables['default_mobile_metatags'] = TRUE;
+
   // Populate the page template suggestions.
   if ($suggestions = theme_get_suggestions(arg(), 'html')) {
     $variables['theme_hook_suggestions'] = $suggestions;
diff --git a/core/modules/system/html.tpl.php b/core/modules/system/html.tpl.php
index 960eefb..59a52b9 100644
--- a/core/modules/system/html.tpl.php
+++ b/core/modules/system/html.tpl.php
@@ -22,6 +22,8 @@
  *   - slogan: The slogan of the site, if any, and if there is no title.
  * - $head: Markup for the HEAD section (including meta tags, keyword tags, and
  *   so on).
+ * - $default_mobile_metatags: TRUE if default mobile metatags for responsive
+ *   design should be displayed.
  * - $styles: Style tags necessary to import all CSS files for the page.
  * - $scripts: Script tags necessary to load the JavaScript files and settings
  *   for the page.
@@ -43,6 +45,12 @@
 <html<?php print $html_attributes; ?>>
   <head>
     <?php print $head; ?>
+    <?php if ($default_mobile_metatags): ?>
+      <meta name="MobileOptimized" content="width" />
+      <meta name="HandheldFriendly" content="true" />
+      <meta name="viewport" content="width=device-width" />
+      <meta http-equiv="cleartype" content="on" />
+    <?php endif; ?>
     <title><?php print $head_title; ?></title>
     <?php print $styles; ?>
     <?php print $scripts; ?>
diff --git a/core/modules/system/system.test b/core/modules/system/system.test
index 78f6a23..74d36fa 100644
--- a/core/modules/system/system.test
+++ b/core/modules/system/system.test
@@ -946,6 +946,50 @@ class AdminMetaTagTestCase extends DrupalWebTestCase {
   }
 }
 
+class DefaultMobileMetaTagsTestCase extends DrupalWebTestCase {
+  /**
+   * Implement getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Default mobile meta tags',
+      'description' => 'Confirm that the default mobile meta tags appear as expected.',
+      'group' => 'System'
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+    $this->default_metatags = array(
+      'MobileOptimized' => '<meta name="MobileOptimized" content="width" />',
+      'HandheldFriendly' => '<meta name="HandheldFriendly" content="true" />',
+      'viewport' => '<meta name="viewport" content="width=device-width" />',
+      'cleartype' => '<meta http-equiv="cleartype" content="on" />'
+    );
+  }
+
+  /**
+   * Verify that the default mobile meta tags are added.
+   */
+  public function testDefaultMetaTagsExist() {
+    $this->drupalGet('');
+    foreach ($this->default_metatags as $name => $metatag) {
+      $this->assertRaw($metatag, 'Default Mobile meta tag "' . $name . '" displayed properly.', t('System'));
+    }
+  }
+
+  /**
+   * Verify that the default mobile meta tags can be removed.
+   */
+  public function testRemovingDefaultMetaTags() {
+    module_enable(array('system_module_test'));
+    $this->drupalGet('');
+    foreach ($this->default_metatags as $name => $metatag) {
+      $this->assertNoRaw($metatag, 'Default Mobile meta tag "' . $name . '" removed properly.', t('System'));
+    }
+  }
+}
+
 /**
  * Tests custom access denied functionality.
  */
diff --git a/core/modules/system/tests/system_module_test.info b/core/modules/system/tests/system_module_test.info
new file mode 100644
index 0000000..42a35f6
--- /dev/null
+++ b/core/modules/system/tests/system_module_test.info
@@ -0,0 +1,7 @@
+name = System test
+description = Provides hook implementations for testing Sytem module functionality.
+package = Core
+version = VERSION
+core = 8.x
+files[] = system_module_test.module
+hidden = TRUE
diff --git a/core/modules/system/tests/system_module_test.module b/core/modules/system/tests/system_module_test.module
new file mode 100644
index 0000000..ec90b15
--- /dev/null
+++ b/core/modules/system/tests/system_module_test.module
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * @file
+ * Provides System module hook implementations for testing purposes.
+ */
+
+function system_module_test_preprocess_html(&$variables) {
+  $variables['default_mobile_metatags'] = FALSE;
+}
-- 
1.7.4.1

