Browse Source

fixed FormHelper to allow create() on Mock Models without errors

Jorge González 12 years ago
parent
commit
5cf2ce723c

+ 20 - 0
lib/Cake/Test/Case/View/Helper/FormHelperTest.php

@@ -8359,6 +8359,26 @@ class FormHelperTest extends CakeTestCase {
 	}
 
 /**
+ * test that create() works without raising errors with a Mock Model
+ *
+ * @return void
+ */
+	public function testCreateNoErrorsWithMockModel() {
+		$encoding = strtolower(Configure::read('App.encoding'));
+		$ContactMock = $this->getMockBuilder('Contact')
+				->disableOriginalConstructor()
+				->getMock();
+		ClassRegistry::removeObject('Contact');
+		ClassRegistry::addObject('Contact', $ContactMock);
+		$result = $this->Form->create('Contact', array('type' => 'GET'));
+		$expected = array('form' => array(
+			'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
+			'accept-charset' => $encoding
+		));
+		$this->assertTags($result, $expected);
+	}
+
+/**
  * test creating a get form, and get form inputs.
  *
  * @return void

+ 1 - 1
lib/Cake/View/Helper/FormHelper.php

@@ -226,7 +226,7 @@ class FormHelper extends AppHelper {
 
 		if ($key === 'validates' && !isset($this->fieldset[$model]['validates'])) {
 			$validates = array();
-			foreach ($object->validator() as $validateField => $validateProperties) {
+			foreach (iterator_to_array($object->validator(), true) as $validateField => $validateProperties) {
 				if ($this->_isRequiredField($validateProperties)) {
 					$validates[$validateField] = true;
 				}