</body>
</html>
END;
    $waited = <<<END
<html>
  <head>
<script type="text/javascript" src="/dynamics/foo.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="/dynamics/foo.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="/bar.css" />
    <script type="text/javascript" src="/bar.js"></script>
  </head>
  <body>
    <p>Lorem ipsum</p>
  </body>
</html>
END;
    $t->is($manager->filterContent(new sfEvent('lorem', 'event.name'), $content), $waited, '->addSfDynamicsTags() inserts tags at the beginning of <head> if position "prepend" and placeholder not found');
}
$t->comment('->getTag()');
$manager = sfDynamics::getManager();
sfWidget::setXhtml(false);
$t->is($manager->getTag('foo.js', 'javascript'), '<script type="text/javascript" src="foo.js"></script>', '->getTag() returns a "<script>" tag for the js type');
$t->is($manager->getTag('foo.css', 'stylesheet'), '<link rel="stylesheet" type="text/css" media="all" href="foo.css" >', '->getTag() returns a "<style media="screen">" tag for the css type');
sfWidget::setXhtml(true);
$t->is($manager->getTag('foo.css', 'stylesheet'), '<link rel="stylesheet" type="text/css" media="all" href="foo.css" />', '->getTag() uses the sfWidget::getXhtml() config');
try {
    $manager->getTag('foo.swf', 'swf');
    $t->fail('->getTag() throws an exception if type isn’t stylesheet or javascript');
} catch (Exception $e) {
    $t->pass('->getTag() throws an exception if type isn’t stylesheet or javascript');
}
Example #2
0
$t->diag('::escapeOnce()');
$t->is(sfWidget::escapeOnce('This a > text to "escape"'), 'This a &gt; text to &quot;escape&quot;', '::escapeOnce() escapes an HTML strings');
$t->is(sfWidget::escapeOnce(sfWidget::escapeOnce('This a > text to "escape"')), 'This a &gt; text to &quot;escape&quot;', '::escapeOnce() does not escape an already escaped string');
$t->is(sfWidget::escapeOnce('This a &gt; text to "escape"'), 'This a &gt; text to &quot;escape&quot;', '::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 &gt; text to &quot;escape&quot;', '::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');