Browse Source

Add additional test for inputs in labels.

mark_story 11 years ago
parent
commit
c22621cc56
2 changed files with 23 additions and 0 deletions
  1. 2 0
      src/View/Helper/FormHelper.php
  2. 21 0
      tests/TestCase/View/Helper/FormHelperTest.php

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

@@ -699,6 +699,8 @@ class FormHelper extends Helper {
  * <label for="post-publish">Publish <input type="text" name="published"></label>
  * }}}
  *
+ * If you want to nest inputs in the labels, you will need to modify the default templates.
+ *
  * @param string $fieldName This should be "Modelname.fieldname"
  * @param string $text Text that will appear in the label field. If
  *   $text is left undefined the text will be inflected from the

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

@@ -3033,6 +3033,27 @@ class FormHelperTest extends TestCase {
 	}
 
 /**
+ * Test that label() can accept an input with the correct template vars.
+ *
+ * @return void
+ */
+	public function testLabelContainInput() {
+		$this->Form->templates([
+			'label' => '<label{{attrs}}>{{input}}{{text}}</label>',
+		]);
+		$result = $this->Form->label('Person.accept_terms', 'Accept', [
+			'input' => '<input type="checkbox" name="accept_tos" >'
+		]);
+		$expected = [
+			'label' => ['for' => 'person-accept-terms'],
+			'input' => ['type' => 'checkbox', 'name' => 'accept_tos'],
+			'Accept',
+			'/label',
+		];
+		$this->assertTags($result, $expected);
+	}
+
+/**
  * testTextbox method
  *
  * test textbox element generation