view = new Zend_View(); $this->helper = new Zend_View_Helper_FormErrors(); $this->helper->setView($this->view); ob_start(); } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { ob_end_clean(); } public function testGetElementEndReturnsDefaultValue() { $this->assertEquals('', $this->helper->getElementEnd()); } public function testGetElementSeparatorReturnsDefaultValue() { $this->assertEquals('
');
$this->assertEquals('', $this->helper->getElementStart());
}
public function testFormErrorsRendersUnorderedListByDefault()
{
$errors = array('foo', 'bar', 'baz');
$html = $this->helper->formErrors($errors);
$this->assertContains('assertContains('- ' . $error . '
', $html);
}
$this->assertContains('
', $html);
}
public function testFormErrorsRendersWithSpecifiedStrings()
{
$this->helper->setElementStart('- ')
->setElementSeparator('
- ')
->setElementEnd('
');
$errors = array('foo', 'bar', 'baz');
$html = $this->helper->formErrors($errors);
$this->assertContains('', $html);
foreach ($errors as $error) {
$this->assertContains('- ' . $error . '
', $html);
}
$this->assertContains('
', $html);
}
public function testFormErrorsPreventsXssAttacks()
{
$errors = array(
'bad' => '\">',
);
$html = $this->helper->formErrors($errors);
$this->assertNotContains($errors['bad'], $html);
$this->assertContains('&', $html);
}
public function testCanDisableEscapingErrorMessages()
{
$errors = array(
'foo' => 'Field is required',
'bar' => 'Please click here for more information'
);
$html = $this->helper->formErrors($errors, array('escape' => false));
$this->assertContains($errors['foo'], $html);
$this->assertContains($errors['bar'], $html);
}
/**
* @group ZF-3477
* @link http://framework.zend.com/issues/browse/ZF-3477
*/
public function testCanSetClassAttribute()
{
$options = array('class' => 'custom-class');
$actualHtml = $this->helper->formErrors(array(), $options);
$this->assertEquals(
'
',
$actualHtml
);
}
/**
* @group ZF-5962
*/
public function testCanSetElementStringsPerOptions()
{
$actual = $this->helper->formErrors(
array('foo', 'bar', 'baz'),
array(
'elementStart' => '',
'elementEnd' => '
',
'elementSeparator' => '
',
)
);
$this->assertEquals('foo
bar
baz
', $actual);
}
}
// Call Zend_View_Helper_FormErrorsTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormErrorsTest::main") {
Zend_View_Helper_FormErrorsTest::main();
}