Skip to content

Commit

Permalink
Merge pull request #378 from jorisvaesen/master
Browse files Browse the repository at this point in the history
Fix when using empty settings
  • Loading branch information
josegonzalez committed Mar 26, 2016
2 parents ea42c77 + d26494a commit c298568
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit c298568

Please sign in to comment.