From 491bd633a1255b105c301e549c43420f8e542f2b Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Sat, 14 Sep 2013 01:21:48 -0700
Subject: [PATCH] Issue #1987870 by disasm: Convert theme_test() callbacks to a
 new style controller.

---
 .../Drupal/theme_test/ThemeTestController.php | 79 ++++++++++++++++---
 .../modules/theme_test/theme_test.module      | 77 +-----------------
 .../modules/theme_test/theme_test.routing.yml | 37 +++++++++
 3 files changed, 109 insertions(+), 84 deletions(-)

diff --git a/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/ThemeTestController.php b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/ThemeTestController.php
index d9f0767de92b..31bbd93613d0 100644
--- a/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/ThemeTestController.php
+++ b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/ThemeTestController.php
@@ -7,28 +7,89 @@
 
 namespace Drupal\theme_test;
 
-use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Controller\ControllerBase;
 
 /**
  * Controller routines for theme test routes.
  */
-class ThemeTestController implements ContainerInjectionInterface {
+class ThemeTestController extends ControllerBase {
 
   /**
-   * {@inheritdoc}
+   * A theme template that overrides a theme function.
+   *
+   * @return array
+   *   Render array containing a theme.
    */
-  public static function create(ContainerInterface $container) {
-    return new static();
+  public function functionTemplateOverridden() {
+    return array(
+      '#theme' => 'theme_test_function_template_override',
+    );
   }
 
   /**
-   * Menu callback for testing that a theme template overrides a theme function.
+   * Adds stylesheets to test theme .info.yml property processing.
+   *
+   * @return array
+   *   A render array containing custom stylesheets.
    */
-  function functionTemplateOverridden() {
+  public function testInfoStylesheets() {
+    $path = drupal_get_path('module', 'theme_test');
     return array(
-      '#theme' => 'theme_test_function_template_override',
+      '#attached' => array(
+        'css' => array(
+          "$path/css/base-override.css",
+          "$path/css/base-override.sub-remove.css",
+          "$path/css/base-remove.css",
+          "$path/css/base-remove.sub-override.css",
+          "$path/css/sub-override.css",
+          "$path/css/sub-remove.css",
+        ),
+      ),
     );
   }
 
+  /**
+   * Tests template overridding based on filename.
+   *
+   * @return array
+   *   A render array containing a theme override.
+   */
+  public function testTemplate() {
+    return theme('theme_test_template_test');
+  }
+
+  /**
+   * Calls a theme hook suggestion.
+   *
+   * @return string
+   *   An HTML string containing the themed output.
+   */
+  public function testSuggestion() {
+    return theme(array('theme_test__suggestion', 'theme_test'), array());
+  }
+
+/**
+ * This is for testing that the theme can have hook_*_alter() implementations
+ * that run during page callback execution, even before theme() is called for
+ * the first time.
+ *
+ * @return string
+ *   A string containing the altered data.
+ */
+  public function testAlter() {
+    $data = 'foo';
+    $this->moduleHandler()->alter('theme_test_alter', $data);
+    return "The altered data is $data.";
+  }
+
+  /**
+   * Tests themed output generated in a request listener.
+   *
+   * @return string
+   *   Content in theme_test_output GLOBAL.
+   */
+  public function testRequestListener() {
+    return $GLOBALS['theme_test_output'];
+  }
+
 }
diff --git a/core/modules/system/tests/modules/theme_test/theme_test.module b/core/modules/system/tests/modules/theme_test/theme_test.module
index 40a78f31788f..42555e436068 100644
--- a/core/modules/system/tests/modules/theme_test/theme_test.module
+++ b/core/modules/system/tests/modules/theme_test/theme_test.module
@@ -46,32 +46,13 @@ function theme_test_system_theme_info() {
  */
 function theme_test_menu() {
   $items['theme-test/suggestion'] = array(
-    'title' => 'Suggestion',
-    'page callback' => '_theme_test_suggestion',
-    'access callback' => TRUE,
+    'route_name' => 'theme_test_suggestion',
     'theme callback' => '_theme_custom_theme',
     'type' => MENU_CALLBACK,
   );
   $items['theme-test/alter'] = array(
-    'title' => 'Suggestion',
-    'page callback' => '_theme_test_alter',
-    'access callback' => TRUE,
     'theme callback' => '_theme_custom_theme',
-    'type' => MENU_CALLBACK,
-  );
-  $items['theme-test/request-listener'] = array(
-    'page callback' => 'theme_test_request_listener_page_callback',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-  );
-  $items['theme-test/template-test'] = array(
-    'page callback' => 'theme_test_template_test_page_callback',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-  );
-  $items['theme-test/info/stylesheets'] = array(
-    'page callback' => 'theme_test_info_stylesheets',
-    'access callback' => TRUE,
+    'route_name' => 'theme_test_alter',
     'type' => MENU_CALLBACK,
   );
   $items['theme-test/function-template-overridden'] = array(
@@ -80,7 +61,6 @@ function theme_test_menu() {
   );
   return $items;
 }
-
 /**
  * Fake registry loading callback.
  */
@@ -89,39 +69,6 @@ function _theme_test_load_registry() {
   return array();
 }
 
-/**
- * Menu callback for testing themed output generated in a request listener.
- */
-function theme_test_request_listener_page_callback() {
-  return $GLOBALS['theme_test_output'];
-}
-
-/**
- * Menu callback for testing template overridding based on filename.
- */
-function theme_test_template_test_page_callback() {
-  return theme('theme_test_template_test');
-}
-
-/**
- * Page callback; Adds stylesheets to test theme .info.yml property processing.
- *
- * @see test_basetheme.info.yml
- * @see test_subtheme.info.yml
- * @see \Drupal\system\Tests\Theme\ThemeInfoStylesTest
- * @see http://drupal.org/node/967266#comment-3689670
- */
-function theme_test_info_stylesheets() {
-  $path = drupal_get_path('module', 'theme_test');
-  drupal_add_css("$path/css/base-override.css");
-  drupal_add_css("$path/css/base-override.sub-remove.css");
-  drupal_add_css("$path/css/base-remove.css");
-  drupal_add_css("$path/css/base-remove.sub-override.css");
-  drupal_add_css("$path/css/sub-override.css");
-  drupal_add_css("$path/css/sub-remove.css");
-  return '';
-}
-
 /**
  * Custom theme callback.
  */
@@ -129,26 +76,6 @@ function _theme_custom_theme() {
   return 'test_theme';
 }
 
-/**
- * Page callback, calls drupal_alter().
- *
- * This is for testing that the theme can have hook_*_alter() implementations
- * that run during page callback execution, even before theme() is called for
- * the first time.
- */
-function _theme_test_alter() {
-  $data = 'foo';
-  drupal_alter('theme_test_alter', $data);
-  return "The altered data is $data.";
-}
-
-/**
- * Page callback, calls a theme hook suggestion.
- */
-function _theme_test_suggestion() {
-  return theme(array('theme_test__suggestion', 'theme_test'), array());
-}
-
 /**
  * Implements hook_preprocess_HOOK() for html.tpl.php.
  */
diff --git a/core/modules/system/tests/modules/theme_test/theme_test.routing.yml b/core/modules/system/tests/modules/theme_test/theme_test.routing.yml
index 866171e2be0d..35a0ff108896 100644
--- a/core/modules/system/tests/modules/theme_test/theme_test.routing.yml
+++ b/core/modules/system/tests/modules/theme_test/theme_test.routing.yml
@@ -4,3 +4,40 @@ function_template_override:
     _content: '\Drupal\theme_test\ThemeTestController::functionTemplateOverridden'
   requirements:
     _permission: 'access content'
+
+theme_test_info_stylesheets:
+  pattern: '/theme-test/info/stylesheets'
+  defaults:
+    _content: '\Drupal\theme_test\ThemeTestController::testInfoStylesheets'
+  requirements:
+    _access: 'TRUE'
+
+theme_test_template_test:
+  pattern: '/theme-test/template-test'
+  defaults:
+    _content: '\Drupal\theme_test\ThemeTestController::testTemplate'
+  requirements:
+    _access: 'TRUE'
+
+theme_test_suggestion:
+  pattern: '/theme-test/suggestion'
+  defaults:
+    _content: '\Drupal\theme_test\ThemeTestController::testSuggestion'
+    _title: 'Suggestion'
+  requirements:
+    _access: 'TRUE'
+
+theme_test_alter:
+  pattern: '/theme-test/alter'
+  defaults:
+    _content: '\Drupal\theme_test\ThemeTestController::testAlter'
+    _title: 'Suggestion'
+  requirements:
+    _access: 'TRUE'
+
+theme_test_request_listener:
+  pattern: '/theme-test/request-listener'
+  defaults:
+    _content: '\Drupal\theme_test\ThemeTestController::testRequestListener'
+  requirements:
+    _access: 'TRUE'
-- 
GitLab