summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-05-11 09:16:02 (GMT)
committerAlex Pott2018-05-11 09:16:02 (GMT)
commit5972c776e6445d514b23dcbb6b281bd55df61488 (patch)
treed2d1a9355397c7b969ad752977aef18012ec1460
parent4105b5560b4f3b9f29734b6ab12e213367c9fd5a (diff)
Issue #2832083 by rbayliss, pounard, alexpott, dawehner: ThemeRegistryLoader::findTemplate() breaks Twig_Loader_Filesystem signature
-rw-r--r--core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php6
-rw-r--r--core/tests/Drupal/Tests/Core/Template/Loader/ThemeRegistryLoaderTest.php29
2 files changed, 33 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php b/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php
index 67a82dd..862092b 100644
--- a/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php
+++ b/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php
@@ -36,8 +36,8 @@ class ThemeRegistryLoader extends \Twig_Loader_Filesystem {
* @param bool $throw
* Whether to throw an exception when an error occurs.
*
- * @return string
- * The path to the template.
+ * @return string|false
+ * The path to the template, or false if the template is not found.
*
* @throws \Twig_Error_Loader
* Thrown if a template matching $name cannot be found.
@@ -63,6 +63,8 @@ class ThemeRegistryLoader extends \Twig_Loader_Filesystem {
if ($throw) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" in the Drupal theme registry.', $name));
}
+
+ return FALSE;
}
}
diff --git a/core/tests/Drupal/Tests/Core/Template/Loader/ThemeRegistryLoaderTest.php b/core/tests/Drupal/Tests/Core/Template/Loader/ThemeRegistryLoaderTest.php
new file mode 100644
index 0000000..9325eae
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Template/Loader/ThemeRegistryLoaderTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Drupal\Tests\Core\Template\Loader;
+
+use Drupal\Core\Template\Loader\ThemeRegistryLoader;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Template\Loader\ThemeRegistryLoader
+ * @group Template
+ */
+class ThemeRegistryLoaderTest extends UnitTestCase {
+
+ /**
+ * @covers ::findTemplate
+ */
+ public function testLoaderReturnsFalseForExistsOnNonexistent() {
+ $registry = $this->prophesize('Drupal\Core\Theme\Registry');
+ $runtime = $this->prophesize('Drupal\Core\Utility\ThemeRegistry');
+ $runtime->has('foo')
+ ->shouldBeCalled()
+ ->willReturn(FALSE);
+ $registry->getRuntime()->willReturn($runtime);
+
+ $loader = new ThemeRegistryLoader($registry->reveal());
+ $this->assertFalse($loader->exists('foo'));
+ }
+
+}