Przeglądaj źródła

[FrameworkBundle] Simplified TemplateReference::getPath() method and added a unit test.

Hugo Hamon 14 lat temu
rodzic
commit
7d09695903

+ 1 - 6
src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php

@@ -40,12 +40,7 @@ class TemplateReference extends BaseTemplateReference
      */
     public function getPath()
     {
-        $controller = $this->get('controller');
-
-        // Fix for namespaced controllers
-        if (!empty($controller) && false !== strpos($controller, '\\')) {
-            $controller = str_replace('\\', '/', $controller);
-        }
+        $controller = str_replace('\\', '/', $this->get('controller'));
 
         $path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
 

+ 28 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateReferenceTest.php

@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
+
+use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
+use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
+
+class TemplateReferenceTest extends TestCase
+{
+    public function testGetPathWorksWithNamespacedControllers()
+    {
+        $reference = new TemplateReference('AcmeBlogBundle', 'Admin\Post', 'index', 'html', 'twig');
+
+        $this->assertSame(
+            '@AcmeBlogBundle/Resources/views/Admin/Post/index.html.twig',
+            $reference->getPath()
+        );
+    }
+}