Merge pull request #3397 from steinkel/fix-formhelper-with-model-mock

fixed FormHelper to allow create() on Mock Models without errors
This commit is contained in:
Mark Story 2014-04-26 08:53:43 -04:00
commit 5b46eb71ec
2 changed files with 21 additions and 1 deletions

View file

@ -8358,6 +8358,26 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
} }
/**
* 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. * test creating a get form, and get form inputs.
* *

View file

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