summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-09-27 01:38:00 +0200
committerAlex Pott2015-09-27 01:38:00 +0200
commit164837635c2f00566d26f63d039f91a9b21f58dc (patch)
tree9a454f2b25aaec1157894f5fcc6f6aaaadd99da5
parent24ed79e1345d32a7846878d2137a9f858a9529b1 (diff)
Issue #2574717 by dawehner, hussainweb, lauriii, pwolanin, davidhernandez, xjm, stefan.r, webchick, Wim Leers: Remove PHPTemplate, and add test coverage for multiple theme engine support
-rw-r--r--core/modules/system/src/Tests/Theme/EngineNyanCatTest.php (renamed from core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php)12
-rw-r--r--core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine52
-rw-r--r--core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.info.yml (renamed from core/themes/engines/phptemplate/phptemplate.info.yml)2
-rw-r--r--core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.info.yml6
-rw-r--r--core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.theme8
-rw-r--r--core/modules/system/tests/themes/test_theme_nyan_cat_engine/theme_test.template_test.nyan-cat.html1
-rw-r--r--core/modules/system/tests/themes/test_theme_phptemplate/node--1.tpl.php4
-rw-r--r--core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.info.yml6
-rw-r--r--core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.theme1
-rw-r--r--core/modules/system/tests/themes/test_theme_phptemplate/theme_test.template_test.tpl.php2
-rw-r--r--core/themes/engines/phptemplate/phptemplate.engine58
11 files changed, 74 insertions, 78 deletions
diff --git a/core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php b/core/modules/system/src/Tests/Theme/EngineNyanCatTest.php
index 37ab343..bfaa1bb 100644
--- a/core/modules/system/src/Tests/Theme/EnginePhpTemplateTest.php
+++ b/core/modules/system/src/Tests/Theme/EngineNyanCatTest.php
@@ -2,7 +2,7 @@
/**
* @file
- * Contains \Drupal\system\Tests\Theme\EnginePhpTemplateTest.
+ * Contains \Drupal\system\Tests\Theme\EngineNyanCatTest.
*/
namespace Drupal\system\Tests\Theme;
@@ -10,11 +10,11 @@ namespace Drupal\system\Tests\Theme;
use Drupal\simpletest\WebTestBase;
/**
- * Tests theme functions with PHPTemplate.
+ * Tests the multi theme engine support.
*
* @group Theme
*/
-class EnginePhpTemplateTest extends WebTestBase {
+class EngineNyanCatTest extends WebTestBase {
/**
* Modules to enable.
@@ -25,7 +25,7 @@ class EnginePhpTemplateTest extends WebTestBase {
protected function setUp() {
parent::setUp();
- \Drupal::service('theme_handler')->install(array('test_theme_phptemplate'));
+ \Drupal::service('theme_handler')->install(array('test_theme_nyan_cat_engine'));
}
/**
@@ -33,10 +33,10 @@ class EnginePhpTemplateTest extends WebTestBase {
*/
function testTemplateOverride() {
$this->config('system.theme')
- ->set('default', 'test_theme_phptemplate')
+ ->set('default', 'test_theme_nyan_cat_engine')
->save();
$this->drupalGet('theme-test/template-test');
- $this->assertText('Success: Template overridden with PHPTemplate theme.', 'Template overridden by PHPTemplate file.');
+ $this->assertText('Success: Template overridden with Nyan Cat theme. All of them', 'Template overridden by Nyan Cat file.');
}
}
diff --git a/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine b/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine
new file mode 100644
index 0000000..a1da728
--- /dev/null
+++ b/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.engine
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * @file
+ * Handles integration of Nyan cat templates because we love kittens.
+ */
+
+use Drupal\Core\Extension\Extension;
+
+/**
+ * Implements hook_init().
+ */
+function nyan_cat_init(Extension $theme) {
+ $theme->load();
+}
+
+/**
+ * Implements hook_theme().
+ */
+function nyan_cat_theme($existing, $type, $theme, $path) {
+ $templates = drupal_find_theme_functions($existing, array($theme));
+ $templates += drupal_find_theme_templates($existing, '.nyan-cat.html', $path);
+ return $templates;
+}
+
+/**
+ * Implements hook_extension().
+ */
+function nyan_cat_extension() {
+ return '.nyan-cat.html';
+}
+
+/**
+ * Implements hook_render_template().
+ *
+ * @param string $template_file
+ * The filename of the template to render.
+ * @param mixed[] $variables
+ * A keyed array of variables that will appear in the output.
+ *
+ * @return string
+ * The output generated by the template.
+ */
+function nyan_cat_render_template($template_file, $variables) {
+ $output = str_replace('div', 'nyancat', file_get_contents(\Drupal::root() . '/' . $template_file));
+ foreach ($variables as $key => $variable) {
+ if (strpos($output, '9' . $key) !== FALSE) {
+ $output = str_replace('9' . $key, theme_render_and_autoescape($variable), $output);
+ }
+ }
+ return $output;
+}
diff --git a/core/themes/engines/phptemplate/phptemplate.info.yml b/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.info.yml
index 2bea7a0..342191c 100644
--- a/core/themes/engines/phptemplate/phptemplate.info.yml
+++ b/core/modules/system/tests/themes/engines/nyan_cat/nyan_cat.info.yml
@@ -1,5 +1,5 @@
type: theme_engine
-name: PHPTemplate
+name: Nyan cat
core: 8.x
version: VERSION
package: Core
diff --git a/core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.info.yml b/core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.info.yml
new file mode 100644
index 0000000..a911bd0
--- /dev/null
+++ b/core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.info.yml
@@ -0,0 +1,6 @@
+name: 'Test theme for Nyan Cat engine'
+type: theme
+description: 'Theme for testing the theme system with the Nyan Cat theme engine'
+version: VERSION
+core: 8.x
+engine: nyan_cat
diff --git a/core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.theme b/core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.theme
new file mode 100644
index 0000000..5b69a12
--- /dev/null
+++ b/core/modules/system/tests/themes/test_theme_nyan_cat_engine/test_theme_nyan_cat_engine.theme
@@ -0,0 +1,8 @@
+<?php
+
+/**
+ * Implements hook_preprocess_theme_test_template_test().
+ */
+function test_theme_nyan_cat_engine_preprocess_theme_test_template_test(&$variables) {
+ $variables['kittens'] = 'All of them';
+}
diff --git a/core/modules/system/tests/themes/test_theme_nyan_cat_engine/theme_test.template_test.nyan-cat.html b/core/modules/system/tests/themes/test_theme_nyan_cat_engine/theme_test.template_test.nyan-cat.html
new file mode 100644
index 0000000..cb21cb5
--- /dev/null
+++ b/core/modules/system/tests/themes/test_theme_nyan_cat_engine/theme_test.template_test.nyan-cat.html
@@ -0,0 +1 @@
+Success: Template overridden with Nyan Cat theme. 9kittens
diff --git a/core/modules/system/tests/themes/test_theme_phptemplate/node--1.tpl.php b/core/modules/system/tests/themes/test_theme_phptemplate/node--1.tpl.php
deleted file mode 100644
index 81974ce..0000000
--- a/core/modules/system/tests/themes/test_theme_phptemplate/node--1.tpl.php
+++ /dev/null
@@ -1,4 +0,0 @@
-<?php
- // node--1.tpl.php - Dummy file for finding the template
-?>
-Node Content Dummy
diff --git a/core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.info.yml b/core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.info.yml
deleted file mode 100644
index da076b1..0000000
--- a/core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.info.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-name: 'Test theme PHPTemplate'
-type: theme
-description: 'Theme for testing the theme system with the PHPTemplate engine'
-version: VERSION
-core: 8.x
-engine: phptemplate
diff --git a/core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.theme b/core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.theme
deleted file mode 100644
index b3d9bbc..0000000
--- a/core/modules/system/tests/themes/test_theme_phptemplate/test_theme_phptemplate.theme
+++ /dev/null
@@ -1 +0,0 @@
-<?php
diff --git a/core/modules/system/tests/themes/test_theme_phptemplate/theme_test.template_test.tpl.php b/core/modules/system/tests/themes/test_theme_phptemplate/theme_test.template_test.tpl.php
deleted file mode 100644
index 86ef138..0000000
--- a/core/modules/system/tests/themes/test_theme_phptemplate/theme_test.template_test.tpl.php
+++ /dev/null
@@ -1,2 +0,0 @@
-<!-- Output for Theme API test -->
-<?php print 'Success: Template overridden with PHPTemplate theme.'; ?>
diff --git a/core/themes/engines/phptemplate/phptemplate.engine b/core/themes/engines/phptemplate/phptemplate.engine
deleted file mode 100644
index 232f78d..0000000
--- a/core/themes/engines/phptemplate/phptemplate.engine
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/**
- * @file
- * Handles integration of PHP templates with the Drupal theme system.
- */
-
-use Drupal\Core\Extension\Extension;
-
-/**
- * Implements hook_init().
- */
-function phptemplate_init(Extension $theme) {
- $theme->load();
-}
-
-/**
- * Implements hook_theme().
- */
-function phptemplate_theme($existing, $type, $theme, $path) {
- $templates = drupal_find_theme_functions($existing, array($theme));
- $templates += drupal_find_theme_templates($existing, '.tpl.php', $path);
- return $templates;
-}
-
-/**
- * Implements hook_extension().
- */
-function phptemplate_extension() {
- return '.tpl.php';
-}
-
-/**
- * Implements hook_render_template().
- *
- * Renders a system default template, which is essentially a PHP template.
- *
- * @param $template_file
- * The filename of the template to render.
- * @param $variables
- * A keyed array of variables that will appear in the output.
- *
- * @return
- * The output generated by the template.
- */
-function phptemplate_render_template($template_file, $variables) {
- // Extract the variables to a local namespace
- extract($variables, EXTR_SKIP);
-
- // Start output buffering
- ob_start();
-
- // Include the template file
- include \Drupal::root() . '/' . $template_file;
-
- // End buffering and return its contents
- return ob_get_clean();
-}