12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace Symfony\Tests\Components\Form;
- use Symfony\Components\Form\HtmlGenerator;
- class HtmlGeneratorTest extends \PHPUnit_Framework_TestCase
- {
- protected $generator;
- public function setUp()
- {
- HtmlGenerator::setXhtml(true);
- $this->generator = new HtmlGenerator();
- }
- public function testEscape()
- {
- $this->assertEquals('<&abcd', $this->generator->escape('<&abcd'));
- }
- public function testEscapeOnlyOnce()
- {
- $this->assertEquals('<&abcd', $this->generator->escape('<&abcd'));
- }
- public function testAttribute()
- {
- $this->assertEquals('foo="bar"', $this->generator->attribute('foo', 'bar'));
- }
- public function testEscapeAttribute()
- {
- $this->assertEquals('foo="<>"', $this->generator->attribute('foo', '<>'));
- }
- public function testXhtmlAttribute()
- {
- HtmlGenerator::setXhtml(true);
- $this->assertEquals('foo="foo"', $this->generator->attribute('foo', true));
- }
- public function testNonXhtmlAttribute()
- {
- HtmlGenerator::setXhtml(false);
- $this->assertEquals('foo', $this->generator->attribute('foo', true));
- }
- public function testAttributes()
- {
- $html = $this->generator->attributes(array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- ));
- $this->assertEquals(' foo="bar" bar="baz"', $html);
- }
- public function testXhtmlTag()
- {
- HtmlGenerator::setXhtml(true);
- $html = $this->generator->tag('input', array(
- 'type' => 'text',
- ));
- $this->assertEquals('<input type="text" />', $html);
- }
- public function testNonXhtmlTag()
- {
- HtmlGenerator::setXhtml(false);
- $html = $this->generator->tag('input', array(
- 'type' => 'text',
- ));
- $this->assertEquals('<input type="text">', $html);
- }
- public function testContentTag()
- {
- $html = $this->generator->contentTag('p', 'asdf', array(
- 'class' => 'foo',
- ));
- $this->assertEquals('<p class="foo">asdf</p>', $html);
- }
- // it should be possible to pass the output of the tag() method as body
- // of the content tag
- public function testDontEscapeContentTag()
- {
- $this->assertEquals('<p><&</p>', $this->generator->contentTag('p', '<&'));
- }
- }
|