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

This commit is contained in:
Jorge González 2014-04-25 21:58:17 +01:00
parent 00be120e7a
commit 5cf2ce723c
2 changed files with 21 additions and 1 deletions

View file

@ -8358,6 +8358,26 @@ class FormHelperTest extends CakeTestCase {
$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.
*

View file

@ -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;
}