Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Added Test Methods:
Browse files Browse the repository at this point in the history
testCanCreateFormsAndSpecifyFactory
testCanCreateFactoryFromArray
testCanCreateFactoryFromConcreteClass
testCanCreateFormFromConcreteClassAndSpecifyCustomValidatorByName

The 4th being the most important. It tests for the existance of a custom validator.
  • Loading branch information
tklever committed Jun 29, 2013
1 parent 08eff87 commit 5d59f38
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/ZendTest/Form/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,99 @@ public function testCanCreateHydratorFromConcreteClass()
$this->assertInstanceOf('Zend\Stdlib\Hydrator\ObjectProperty', $hydrator);
}

public function testCanCreateFormsAndSpecifyFactory()
{
$form = $this->factory->createForm(array(
'name' => 'foo',
'factory' => 'Zend\Form\Factory',
));
$this->assertInstanceOf('Zend\Form\FormInterface', $form);
$factory = $form->getFormFactory();
$this->assertInstanceOf('Zend\Form\Factory', $factory);
}

public function testCanCreateFactoryFromArray()
{
$form = $this->factory->createForm(array(
'name' => 'foo',
'factory' => array(
'type' => 'Zend\Form\Factory',
),
));

$this->assertInstanceOf('Zend\Form\FormInterface', $form);
$factory = $form->getFormFactory();
$this->assertInstanceOf('Zend\Form\Factory', $factory);
}

public function testCanCreateFactoryFromConcreteClass()
{
$factory = new \Zend\Form\Factory();
$form = $this->factory->createForm(array(
'name' => 'foo',
'factory' => $factory,
));

$this->assertInstanceOf('Zend\Form\FormInterface', $form);
$test = $form->getFormFactory();
$this->assertSame($factory, $test);
}

public function testCanCreateFormFromConcreteClassAndSpecifyCustomValidatorByName()
{
$validatorManager = new \Zend\Validator\ValidatorPluginManager();
$validatorManager->setInvokableClass('baz', 'ZendTest\Validator\TestAsset\ConcreteValidator');

$defaultValidatorChain = new \Zend\Validator\ValidatorChain();
$defaultValidatorChain->setPluginManager($validatorManager);

$inputFilterFactory = new \Zend\InputFilter\Factory();
$inputFilterFactory->setDefaultValidatorChain($defaultValidatorChain);

$factory = new FormFactory();
$factory->setInputFilterFactory($inputFilterFactory);

$form = $factory->createForm(array(
'name' => 'foo',
'factory' => $factory,
'input_filter' => array(
'bar' => array(
'name' => 'bar',
'required' => true,
'validators' => array(
array(
'name' => 'baz',
),
),
),
),
));

$this->assertInstanceOf('Zend\Form\FormInterface', $form);

$inputFilter = $form->getInputFilter();
$this->assertInstanceOf('Zend\InputFilter\InputFilterInterface', $inputFilter);

$input = $inputFilter->get('bar');
$this->assertInstanceOf('Zend\InputFilter\Input', $input);

$validatorChain = $input->getValidatorChain();
$this->assertInstanceOf('Zend\Validator\ValidatorChain', $validatorChain);

$validatorArray = $validatorChain->getValidators();
$found = false;
foreach($validatorArray as $validator) {
$validatorInstance = $validator['instance'];
$this->assertInstanceOf('Zend\Validator\ValidatorInterface', $validatorInstance);

if($validatorInstance instanceof \ZendTest\Validator\TestAsset\ConcreteValidator) {
$found = true;
break;
}
}
$this->assertTrue($found);
}

public function testCanCreateFormWithHydratorAndInputFilterAndElementsAndFieldsets()
{
$form = $this->factory->createForm(array(
Expand Down

0 comments on commit 5d59f38

Please sign in to comment.