示例#1
0
$t->diag('::escapeOnce()');
$t->is(sfWidget::escapeOnce('This a > text to "escape"'), 'This a > text to "escape"', '::escapeOnce() escapes an HTML strings');
$t->is(sfWidget::escapeOnce(sfWidget::escapeOnce('This a > text to "escape"')), 'This a > text to "escape"', '::escapeOnce() does not escape an already escaped string');
$t->is(sfWidget::escapeOnce('This a > text to "escape"'), 'This a > text to "escape"', '::escapeOnce() does not escape an already escaped string');
class MyClass
{
    public function __toString()
    {
        return 'mycontent';
    }
}
$t->is(sfWidget::escapeOnce(new MyClass()), 'mycontent', '::escapeOnce() converts objects to string');
// ::fixDoubleEscape()
$t->diag('::fixDoubleEscape()');
$t->is(sfWidget::fixDoubleEscape(htmlspecialchars(htmlspecialchars('This a > text to "escape"'), ENT_QUOTES, sfWidget::getCharset()), ENT_QUOTES, sfWidget::getCharset()), 'This a > text to "escape"', '::fixDoubleEscape() fixes double escaped strings');
// ::getCharset() ::setCharset()
$t->diag('::getCharset() ::setCharset()');
$t->is(sfWidget::getCharset(), 'UTF-8', '::getCharset() returns the charset to use for widgets');
sfWidget::setCharset('ISO-8859-1');
$t->is(sfWidget::getCharset(), 'ISO-8859-1', '::setCharset() changes the charset to use for widgets');
// ::setXhtml() ::isXhtml()
$t->diag('::setXhtml() ::isXhtml()');
$w = new MyWidget();
$t->is(sfWidget::isXhtml(), true, '::isXhtml() return true if the widget must returns XHTML tags');
sfWidget::setXhtml(false);
$t->is($w->renderTag('input', array('value' => 'Test')), '<input value="Test">', '::setXhtml() changes the value of the XHTML tag');
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
$w = new MyWidget();
$t->is($w->getJavaScripts(), array(), '->getJavaScripts() returns an array of stylesheets');
$t->is($w->getStylesheets(), array(), '->getStylesheets() returns an array of JavaScripts');