Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zf2-513' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Sep 10, 2012
2 parents c0e5da3 + 1538f6c commit 0cbbdec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Factory.php
Expand Up @@ -232,13 +232,19 @@ public function createInputFilter($inputFilterSpecification)
if (!$inputFilter instanceof InputFilterInterface) {
throw new Exception\RuntimeException(sprintf(
'InputFilter factory expects the "type" to be a class implementing %s; received "%s"',
'Zend\InputFilter\InputFilterInterface',
$class
));
'Zend\InputFilter\InputFilterInterface', $class));
}

foreach ($inputFilterSpecification as $key => $value) {
$input = $this->createInput($value);

if (($value instanceof InputInterface)
|| ($value instanceof InputFilterInterface)
) {
$input = $value;
} else {
$input = $this->createInput($value);
}

$inputFilter->add($input, $key);
}

Expand Down
28 changes: 28 additions & 0 deletions test/FactoryTest.php
Expand Up @@ -240,6 +240,34 @@ public function testFactoryWillCreateInputWithSuggestedName()
$this->assertEquals('foo', $input->getName());
}

public function testFactoryAcceptsInputInterface()
{
$factory = new Factory();
$input = new Input();

$inputFilter = $factory->createInputFilter(array(
'foo' => $input
));

$this->assertInstanceOf('Zend\InputFilter\InputFilterInterface', $inputFilter);
$this->assertTrue($inputFilter->has('foo'));
$this->assertTrue($inputFilter->get('foo') === $input);
}

public function testFactoryAcceptsInputFilterInterface()
{
$factory = new Factory();
$input = new InputFilter();

$inputFilter = $factory->createInputFilter(array(
'foo' => $input
));

$this->assertInstanceOf('Zend\InputFilter\InputFilterInterface', $inputFilter);
$this->assertTrue($inputFilter->has('foo'));
$this->assertTrue($inputFilter->get('foo') === $input);
}

public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfiguration()
{
$factory = new Factory();
Expand Down

0 comments on commit 0cbbdec

Please sign in to comment.