Skip to content
This repository
Browse code

Fix label element for attributes not matching their inputs.

Radio elements would contain ModelModelFieldValue instead of
ModelFieldValue like they should. This was caused by the fix for #3936
and lack of tests for create() + radio().

Fixes #4071
  • Loading branch information...
commit 5ec9b145bf5ba9132bb663e0b889a2eb89824a8b 1 parent aee71fa
Mark Story authored
21  lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -4098,6 +4098,27 @@ public function testRadioLabelArray() {
4098 4098
 	}
4099 4099
 
4100 4100
 /**
  4101
+ * Test that label id's match the input element id's when radio is called after create().
  4102
+ *
  4103
+ * @return void
  4104
+ */
  4105
+	public function testRadioWithCreate() {
  4106
+		$this->Form->create('Model');
  4107
+		$result = $this->Form->radio('recipient',
  4108
+			array('1' => '1', '2' => '2', '3' => '3'),
  4109
+			array('legend' => false, 'value' => '1')
  4110
+		);
  4111
+		$this->assertTextNotContains(
  4112
+			'<label for="ModelModelRecipient1">1</label>',
  4113
+			$result
  4114
+		);
  4115
+		$this->assertTextContains(
  4116
+			'<label for="ModelRecipient1">1</label>',
  4117
+			$result
  4118
+		);
  4119
+	}
  4120
+
  4121
+/**
4101 4122
  * testSelect method
4102 4123
  *
4103 4124
  * Test select element generation.
4  lib/Cake/View/Helper/FormHelper.php
@@ -1520,7 +1520,9 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
1520 1520
 			);
1521 1521
 
1522 1522
 			if ($label) {
1523  
-				$optTitle = $this->label($tagName, $optTitle, is_array($label) ? $label : null);
  1523
+				$labelOpts = is_array($label) ? $label : array();
  1524
+				$labelOpts += array('for' => $tagName);
  1525
+				$optTitle = $this->label($tagName, $optTitle, $labelOpts);
1524 1526
 			}
1525 1527
 
1526 1528
 			if (is_array($between)) {

0 notes on commit 5ec9b14

Please sign in to comment.
Something went wrong with that request. Please try again.