Skip to content

Commit

Permalink
Merge pull request #542 from FriendsOfCake/issue-541
Browse files Browse the repository at this point in the history
Fix "undefined index" error.
  • Loading branch information
ADmad committed Jun 19, 2020
2 parents 7cfda1b + 756c42a commit 7f5a43c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObj
if (!empty($dataArray[$field]) && $dataArray[$field]->getError() !== UPLOAD_ERR_NO_FILE) {
continue;
}
unset($data[$field]);
if (isset($data[$field])) {
unset($data[$field]);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ public function testInitializeAddBehaviorOptionsInterfaceConfig()
public function testBeforeMarshalOk()
{
$validator = $this->getMockBuilder('Cake\Validation\Validator')->getMock();
$validator->expects($this->once())
$validator->expects($this->atLeastOnce())
->method('isEmptyAllowed')
->will($this->returnValue(true));

$table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
$table->expects($this->once())
$table->expects($this->atLeastOnce())
->method('getValidator')
->will($this->returnValue($validator));

Expand All @@ -203,6 +203,10 @@ public function testBeforeMarshalOk()
$data = new ArrayObject($this->dataOk);
$behavior->beforeMarshal(new Event('fake.event'), $data, new ArrayObject());
$this->assertEquals(new ArrayObject($this->dataOk), $data);

$data = new ArrayObject();
$behavior->beforeMarshal(new Event('fake.event'), $data, new ArrayObject());
$this->assertEquals(new ArrayObject([]), $data);
}

public function testBeforeMarshalError()
Expand Down

0 comments on commit 7f5a43c

Please sign in to comment.