Skip to content

Commit 7f5a43c

Browse files
authored
Merge pull request #542 from FriendsOfCake/issue-541
Fix "undefined index" error.
2 parents 7cfda1b + 756c42a commit 7f5a43c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Model/Behavior/UploadBehavior.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObj
7575
if (!empty($dataArray[$field]) && $dataArray[$field]->getError() !== UPLOAD_ERR_NO_FILE) {
7676
continue;
7777
}
78-
unset($data[$field]);
78+
if (isset($data[$field])) {
79+
unset($data[$field]);
80+
}
7981
}
8082
}
8183

tests/TestCase/Model/Behavior/UploadBehaviorTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ public function testInitializeAddBehaviorOptionsInterfaceConfig()
182182
public function testBeforeMarshalOk()
183183
{
184184
$validator = $this->getMockBuilder('Cake\Validation\Validator')->getMock();
185-
$validator->expects($this->once())
185+
$validator->expects($this->atLeastOnce())
186186
->method('isEmptyAllowed')
187187
->will($this->returnValue(true));
188188

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

@@ -203,6 +203,10 @@ public function testBeforeMarshalOk()
203203
$data = new ArrayObject($this->dataOk);
204204
$behavior->beforeMarshal(new Event('fake.event'), $data, new ArrayObject());
205205
$this->assertEquals(new ArrayObject($this->dataOk), $data);
206+
207+
$data = new ArrayObject();
208+
$behavior->beforeMarshal(new Event('fake.event'), $data, new ArrayObject());
209+
$this->assertEquals(new ArrayObject([]), $data);
206210
}
207211

208212
public function testBeforeMarshalError()

0 commit comments

Comments
 (0)