Browse Source

Merge pull request #6736 from cakephp/assert-template

Fix assertTemplate() not working when cells are rendered.
José Lorenzo Rodríguez 10 years ago
parent
commit
09876346ae

+ 3 - 1
src/TestSuite/IntegrationTestCase.php

@@ -307,7 +307,9 @@ abstract class IntegrationTestCase extends TestCase
         $this->_controller = $event->data['controller'];
         $events = $this->_controller->eventManager();
         $events->on('View.beforeRender', function ($event, $viewFile) {
-            $this->_viewName = $viewFile;
+            if (!$this->_viewName) {
+                $this->_viewName = $viewFile;
+            }
         });
         $events->on('View.beforeLayout', function ($event, $viewFile) {
             $this->_layoutName = $viewFile;

+ 13 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -118,6 +118,19 @@ class IntegrationTestCaseTest extends IntegrationTestCase
     }
 
     /**
+     * Assert that the stored template doesn't change when cells are rendered.
+     *
+     * @return void
+     */
+    public function testAssertTemplateAfterCellRender()
+    {
+        $this->get('/posts/get');
+        $this->assertContains('Template' . DS . 'Posts' . DS . 'get.ctp', $this->_viewName);
+        $this->assertTemplate('get');
+        $this->assertResponseContains('cellcontent');
+    }
+
+    /**
      * Test array URLs
      *
      * @return void

+ 10 - 0
tests/test_app/TestApp/Controller/PostsController.php

@@ -47,4 +47,14 @@ class PostsController extends AppController
         ]);
         $this->set('test', 'value');
     }
+
+    /**
+     * Stub get method
+     *
+     * @return void
+     */
+    public function get()
+    {
+        // Do nothing.
+    }
 }

+ 1 - 0
tests/test_app/TestApp/Template/Posts/get.ctp

@@ -0,0 +1 @@
+<?= $this->cell('Articles::doEcho', ['cell', 'content']); ?>