Browse Source

Add View::disableAutoLayout().

ADmad 7 years ago
parent
commit
7b54ff897d
2 changed files with 31 additions and 0 deletions
  1. 14 0
      src/View/View.php
  2. 17 0
      tests/TestCase/View/ViewTest.php

+ 14 - 0
src/View/View.php

@@ -564,6 +564,20 @@ class View implements EventDispatcherInterface
     }
 
     /**
+     * Turns off CakePHP's conventional mode of applying layout files.
+
+     * Layouts will not be automatically applied to rendered views.
+     *
+     * @return $this
+     */
+    public function disableAutoLayout()
+    {
+        $this->autoLayout = false;
+
+        return $this;
+    }
+
+    /**
      * Turns on or off CakePHP's conventional mode of applying layout files.
      * On by default. Setting to off means that layouts will not be
      * automatically applied to rendered templates.

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

@@ -2093,6 +2093,23 @@ TEXT;
         $this->assertSame($autoLayout, true);
     }
 
+
+    /**
+     * testDisableAutoLayout
+     *
+     * @return void
+     */
+    public function testDisableAutoLayout()
+    {
+        $this->assertTrue($this->View->isAutoLayoutEnabled());
+
+        $result = $this->View->disableAutoLayout();
+        $this->assertSame($this->View, $result);
+
+        $autoLayout = $this->View->isAutoLayoutEnabled();
+        $this->assertFalse($this->View->isAutoLayoutEnabled());
+    }
+
     /**
      * Test getTheme() and setTheme().
      *