Browse Source

Add a way to reset templates on the FormHelper.

Now that there are multiple ways to mutate the templates at runtime,
having a way to restore any edits will probably come in handy.
Mark Story 12 years ago
parent
commit
dbe809b3f8
2 changed files with 26 additions and 0 deletions
  1. 13 0
      src/View/Helper/FormHelper.php
  2. 13 0
      tests/TestCase/View/Helper/FormHelperTest.php

+ 13 - 0
src/View/Helper/FormHelper.php

@@ -2233,6 +2233,19 @@ class FormHelper extends Helper {
 	}
 
 /**
+ * Restores the default values built into FormHelper.
+ *
+ * This method will not reset any templates set in custom widgets.
+ *
+ * @return void
+ */
+	public function resetTemplates() {
+		$reflection = new \ReflectionClass($this);
+		$properties = $reflection->getDefaultProperties();
+		$this->templates($properties['_defaultTemplates']);
+	}
+
+/**
  * Event listeners.
  *
  * @return array

+ 13 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -5770,4 +5770,17 @@ class FormHelperTest extends TestCase {
 		$this->assertTags($result, $expected);
 	}
 
+/**
+ * Test resetting templates.
+ *
+ * @return void
+ */
+	public function testResetTemplates() {
+		$this->Form->templates(['input' => '<input>']);
+		$this->assertEquals('<input>', $this->Form->getTemplater()->get('input'));
+
+		$this->assertNull($this->Form->resetTemplates());
+		$this->assertNotEquals('<input>', $this->Form->getTemplater()->get('input'));
+	}
+
 }