mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fixed FormHelper to allow create() on Mock Models without errors
This commit is contained in:
parent
00be120e7a
commit
5cf2ce723c
2 changed files with 21 additions and 1 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue