diff --git a/src/Model/Behavior/UploadBehavior.php b/src/Model/Behavior/UploadBehavior.php index 946367b..8de4527 100644 --- a/src/Model/Behavior/UploadBehavior.php +++ b/src/Model/Behavior/UploadBehavior.php @@ -37,6 +37,8 @@ class UploadBehavior extends Behavior */ public function initialize(array $config): void { + unset($config['className']); + $configs = []; foreach ($config as $field => $settings) { if (is_int($field)) { @@ -46,8 +48,7 @@ public function initialize(array $config): void } } - $this->setConfig($configs); - $this->setConfig('className', null); + $this->setConfig($configs, null, false); $schema = $this->_table->getSchema(); /** @var string $field */ diff --git a/tests/TestCase/Model/Behavior/UploadBehaviorTest.php b/tests/TestCase/Model/Behavior/UploadBehaviorTest.php index b7e9f45..d341e31 100644 --- a/tests/TestCase/Model/Behavior/UploadBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/UploadBehaviorTest.php @@ -743,13 +743,13 @@ public function testNameCallback() $table = $this->getTableLocator()->get('Files'); $behavior = new ChildBehavior($table, [ 'filename' => [ - 'nameCallback' => function ($table, $entity, $data, $field, $settings) { - return 'Awesome Filename.png'; - }, + 'nameCallback' => [$this, 'nameCallback'], 'transformer' => SlugTransformer::class, ], ]); + $this->assertSame([$this, 'nameCallback'], $behavior->getConfig('filename.nameCallback')); + $event = new Event('Model.beforeSave', $table); $entity = new Entity([ 'filename' => $this->dataOk['field'], @@ -763,4 +763,9 @@ public function testNameCallback() $this->assertEquals($expected, $behavior->constructedFiles); } + + public function nameCallback($table, $entity, $data, $field, $settings) + { + return 'Awesome Filename.png'; + } }