From 5efae23cb29158c109b80683d218fc2d7ce51f71 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 29 Apr 2013 17:19:51 +0200 Subject: [PATCH] FIX Template discovery on themed Layout templates Was failing when 'main' template only exists in theme, but 'Layout' template only exists in module. --- core/manifest/TemplateLoader.php | 8 ++++---- core/manifest/TemplateManifest.php | 4 ++-- tests/core/manifest/TemplateLoaderTest.php | 7 +++++++ tests/core/manifest/TemplateManifestTest.php | 9 ++++++++- .../module/templates/Layout/CustomThemePage.ss | 0 .../themes/theme/templates/CustomThemePage.ss | 0 6 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 tests/core/manifest/fixtures/templatemanifest/module/templates/Layout/CustomThemePage.ss create mode 100644 tests/core/manifest/fixtures/templatemanifest/themes/theme/templates/CustomThemePage.ss diff --git a/core/manifest/TemplateLoader.php b/core/manifest/TemplateLoader.php index 50033b949..f1e8e6a66 100644 --- a/core/manifest/TemplateLoader.php +++ b/core/manifest/TemplateLoader.php @@ -75,15 +75,15 @@ class SS_TemplateLoader { } if ($found = $this->getManifest()->getCandidateTemplate($template, $theme)) { - if ($type && isset($found[$type])) { + if ($type && isset($found[$type])) { $found = array( 'main' => $found[$type] ); + } + + $result = array_merge($found, $result); } - - $result = array_merge($found, $result); } - } return $result; } diff --git a/core/manifest/TemplateManifest.php b/core/manifest/TemplateManifest.php index ce81ad359..47de70d56 100644 --- a/core/manifest/TemplateManifest.php +++ b/core/manifest/TemplateManifest.php @@ -115,11 +115,11 @@ class SS_TemplateManifest { if ($this->project && isset($candidates[$this->project])) { $found = $candidates[$this->project]; } else if ($theme && isset($candidates['themes'][$theme])) { - $found = $candidates['themes'][$theme]; + $found = array_merge($candidates, $candidates['themes'][$theme]); } else { - unset($candidates['themes']); $found = $candidates; } + if(isset($found['themes'])) unset($found['themes']); return $found; } diff --git a/tests/core/manifest/TemplateLoaderTest.php b/tests/core/manifest/TemplateLoaderTest.php index 7f7e9b90d..b4e154ced 100644 --- a/tests/core/manifest/TemplateLoaderTest.php +++ b/tests/core/manifest/TemplateLoaderTest.php @@ -42,6 +42,13 @@ class TemplateLoaderTest extends SapphireTest { ); $this->assertEquals($expectCustomPage, $loader->findTemplates(array('CustomPage', 'Page'))); + + // 'main' template only exists in theme, and 'Layout' template only exists in module + $expectCustomThemePage = array( + 'main' => "$base/themes/theme/templates/CustomThemePage.ss", + 'Layout' => "$base/module/templates/Layout/CustomThemePage.ss" + ); + $this->assertEquals($expectCustomThemePage, $loader->findTemplates(array('CustomThemePage', 'Page'), 'theme')); } public function testFindTemplatesApplicationOverridesModule() { diff --git a/tests/core/manifest/TemplateManifestTest.php b/tests/core/manifest/TemplateManifestTest.php index ab4cd84b8..0bf34d5f5 100644 --- a/tests/core/manifest/TemplateManifestTest.php +++ b/tests/core/manifest/TemplateManifestTest.php @@ -47,6 +47,13 @@ class TemplateManifestTest extends SapphireTest { 'subfolder' => array( 'main' => "{$this->base}/module/subfolder/templates/Subfolder.ss" ), + 'customthemepage' => array ( + 'Layout' => "{$this->base}/module/templates/Layout/CustomThemePage.ss", + 'themes' => + array( + 'theme' => array('main' => "{$this->base}/themes/theme/templates/CustomThemePage.ss",) + ) + ), 'include' => array('themes' => array( 'theme' => array( 'Includes' => "{$this->base}/themes/theme/templates/Includes/Include.ss" @@ -66,7 +73,7 @@ class TemplateManifestTest extends SapphireTest { ksort($expectTests); ksort($manifest); ksort($manifestTests); - + $this->assertEquals( $expect, $manifest, 'All templates are correctly loaded in the manifest.' diff --git a/tests/core/manifest/fixtures/templatemanifest/module/templates/Layout/CustomThemePage.ss b/tests/core/manifest/fixtures/templatemanifest/module/templates/Layout/CustomThemePage.ss new file mode 100644 index 000000000..e69de29bb diff --git a/tests/core/manifest/fixtures/templatemanifest/themes/theme/templates/CustomThemePage.ss b/tests/core/manifest/fixtures/templatemanifest/themes/theme/templates/CustomThemePage.ss new file mode 100644 index 000000000..e69de29bb