Skip to content

Commit

Permalink
update test for multiple forms and rules
Browse files Browse the repository at this point in the history
  • Loading branch information
roed committed Sep 17, 2014
1 parent f224601 commit 1227d85
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions tests/StrokerFormTest/Renderer/JqueryValidate/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ function ($string) {
* Get a test form with fields setup
*
* @param string $alias
* @param string $emailFieldName
* @return \Zend\Form\FormInterface
*/
protected function createForm($alias)
protected function createForm($alias, $emailFieldName = 'email')
{
$factory = new Factory();
$form = $factory->createForm(
array(
'hydrator' => 'Zend\Stdlib\Hydrator\ArraySerializable',
'name' => 'test',
'name' => $alias,
'elements' => array(
array(
'spec' => array(
Expand Down Expand Up @@ -469,6 +470,59 @@ public function testIfSetOptionsAddsRecursively()

$this->assertEquals($expectedOptions['validate_options'], $this->renderer->getOptions()->getValidateOptions());
}

public function testIfRulesAreResetWithMultipleForms()
{
$form1 = $this->createForm('test', 'customEmailName');

$inputFilter1 = new InputFilter();
$inputFilter1->add(array(
'name' => 'email',
'required' => true,
'validators' => array(
array(
'name' => 'emailAddress'
)
)
));
$inputFilter1->add([
'name' => 'name',
'required' => true
]);

$form1->setInputFilter($inputFilter1);

$this->renderer->preRenderForm('test', $this->view);


$form2 = $this->createForm('test2', 'email');

$inputFilter2 = new InputFilter();
$inputFilter2->add(array(
'name' => 'otherfieldname',
'required' => true,
'validators' => array(
array(
'name' => 'emailAddress'
)
)
));
$inputFilter2->add([
'name' => 'name',
'required' => true
]);

$form2->setInputFilter($inputFilter2);

$this->renderer->preRenderForm('test2', $this->view);

$inlineScript = $this->view->plugin('inlineScript');
$inlineString = preg_replace('/(\r\n|\r|\n|\t)+/', '', $inlineScript->toString());
$explodedString = explode('form[name="test2"]', $inlineString);
$lastPart = end($explodedString);

$this->assertNotContains('customEmailName', $lastPart);
}

/**
* Get rules and messages as matches from the inlineScript string
Expand Down

0 comments on commit 1227d85

Please sign in to comment.