Browse Source

Merge branch 'issue-11620' into master

Mark Story 8 years ago
parent
commit
c33751ab40

+ 1 - 1
src/View/View.php

@@ -1249,7 +1249,7 @@ class View implements EventDispatcherInterface
         if (strlen($this->subDir)) {
             $subDir = $this->subDir . DIRECTORY_SEPARATOR;
             // Check if templatePath already terminates with subDir
-            if (strrpos($templatePath, $subDir) == strlen($templatePath) - strlen($subDir)) {
+            if ($templatePath != $subDir && substr($templatePath, -(strlen($subDir))) == $subDir) {
                 $subDir = '';
             }
         }

+ 21 - 0
tests/TestCase/View/ViewTest.php

@@ -676,6 +676,27 @@ class ViewTest extends TestCase
     }
 
     /**
+     * Test getViewFileName applies subdirectories on equal length names
+     *
+     * @return void
+     */
+    public function testGetViewFileNameSubDirLength()
+    {
+        $viewOptions = [
+            'plugin' => null,
+            'name' => 'Jobs',
+            'viewPath' => 'Jobs',
+            'layoutPath' => 'json',
+        ];
+        $view = new TestView(null, null, null, $viewOptions);
+
+        $view->subDir = 'json';
+        $result = $view->getViewFileName('index');
+        $expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Jobs' . DS . 'json' . DS . 'index.ctp';
+        $this->assertPathEquals($expected, $result);
+    }
+
+    /**
      * Test getting layout filenames
      *
      * @return void

+ 2 - 0
tests/test_app/TestApp/Template/Jobs/json/index.ctp

@@ -0,0 +1,2 @@
+<?php
+// used to test subdir path additions.