Skip to content
This repository
Browse code

Adding tests for habtm data selection. Refs #256

  • Loading branch information...
commit b974127562049afdae405400c9fe11ad919477bb 1 parent 5f1d090
Mark Story authored November 04, 2009
49  cake/tests/cases/libs/view/helpers/form.test.php
@@ -3040,6 +3040,55 @@ function testSelectMultiple() {
3040 3040
 	}
3041 3041
 
3042 3042
 /**
  3043
+ * test generation of habtm select boxes.
  3044
+ *
  3045
+ * @return void
  3046
+ **/
  3047
+	function testHabtmSelectBox() {
  3048
+		$view =& ClassRegistry::getObject('view');
  3049
+		$view->viewVars['contactTags'] = array(
  3050
+			1 => 'blue',
  3051
+			2 => 'red',
  3052
+			3 => 'green'
  3053
+		);
  3054
+		$this->Form->data = array(
  3055
+			'Contact' => array(),
  3056
+			'ContactTag' => array(
  3057
+				array(
  3058
+					'id' => 1,
  3059
+					'name' => 'blue'
  3060
+				),
  3061
+				array(
  3062
+					'id' => 3,
  3063
+					'name' => 'green'
  3064
+				)
  3065
+			)
  3066
+		);
  3067
+		$this->Form->create('Contact');
  3068
+		$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
  3069
+		$expected = array(
  3070
+			'input' => array(
  3071
+				'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => ''
  3072
+			),
  3073
+			'select' => array(
  3074
+				'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
  3075
+				'multiple' => 'multiple'
  3076
+			),
  3077
+			array('option' => array('value' => '1', 'selected' => 'selected')),
  3078
+			'blue',
  3079
+			'/option',
  3080
+			array('option' => array('value' => '2')),
  3081
+			'red',
  3082
+			'/option',
  3083
+			array('option' => array('value' => '3', 'selected' => 'selected')),
  3084
+			'green',
  3085
+			'/option',
  3086
+			'/select'
  3087
+		);
  3088
+		$this->assertTags($result, $expected);
  3089
+	}
  3090
+
  3091
+/**
3043 3092
  * test generation of multi select elements in checkbox format
3044 3093
  *
3045 3094
  * @access public

0 notes on commit b974127

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