diff --git a/src/Model/Behavior/UploadBehavior.php b/src/Model/Behavior/UploadBehavior.php index f4d13507..0928864e 100644 --- a/src/Model/Behavior/UploadBehavior.php +++ b/src/Model/Behavior/UploadBehavior.php @@ -25,7 +25,17 @@ class UploadBehavior extends Behavior */ public function initialize(array $config) { - $this->config(Hash::normalize($config)); + $configs = []; + foreach ($config as $field => $settings) { + if (is_int($field)) { + $configs[$settings] = []; + } else { + $configs[$field] = $settings; + } + } + + $this->_config = []; + $this->config($configs); Type::map('upload.file', 'Josegonzalez\Upload\Database\Type\FileType'); $schema = $this->_table->schema(); diff --git a/tests/TestCase/Model/Behavior/UploadBehaviorTest.php b/tests/TestCase/Model/Behavior/UploadBehaviorTest.php index 52fdff86..4bb5641f 100644 --- a/tests/TestCase/Model/Behavior/UploadBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/UploadBehaviorTest.php @@ -71,6 +71,32 @@ public function testInitialize() $behavior->initialize($this->settings); } + public function testInitializeIndexedConfig() + { + $settings = ['field']; + $table = $this->getMock('Cake\ORM\Table'); + $schema = $this->getMock('Cake\Database\Schema\Table', [], [$table, []]); + $schema->expects($this->once()) + ->method('columnType') + ->with('field', 'upload.file'); + $table->expects($this->at(0)) + ->method('schema') + ->will($this->returnValue($schema)); + $table->expects($this->at(1)) + ->method('schema') + ->will($this->returnValue($schema)); + + $methods = array_diff($this->behaviorMethods, ['initialize', 'config']); + $behavior = $this->getMock('Josegonzalez\Upload\Model\Behavior\UploadBehavior', $methods, [$table, $settings], '', false); + $reflection = new ReflectionClass($behavior); + $property = $reflection->getProperty('_table'); + $property->setAccessible(true); + $property->setValue($behavior, $table); + $behavior->initialize($settings); + + $this->assertEquals(['field' => []], $behavior->config()); + } + public function testBeforeMarshalOk() { $validator = $this->getMock('Cake\Validation\Validator');