Exemple #1
0
 public function testUnescapeDoesNotUnescapeObjectMarkedAsBeingSafe()
 {
     $this->assertTrue(Escaper::unescape(Escaper::escape('entities', new SafeDecorator(new OutputEscaperTestClass()))) instanceof OutputEscaperTestClass, '::unescape() returns the original value if it is marked as being safe');
     Escaper::markClassAsSafe('OutputEscaperTestClass');
     $this->assertTrue(Escaper::unescape(Escaper::escape('entities', new OutputEscaperTestClass())) instanceof OutputEscaperTestClass, '::unescape() returns the original value if the object class is marked as being safe');
     $this->assertTrue(Escaper::unescape(Escaper::escape('entities', new OutputEscaperTestClassChild())) instanceof OutputEscaperTestClassChild, '::unescape() returns the original value if one of the object parent class is marked as being safe');
 }
$t->diag('::unescape() unescapes strings');
$t->is(Escaper::unescape('&lt;strong&gt;escaped!&lt;/strong&gt;'), '<strong>escaped!</strong>', '::unescape() returns an unescaped string if the value to unescape is a string');
$t->is(Escaper::unescape('&lt;strong&gt;&eacute;chapp&eacute;&lt;/strong&gt;'), '<strong>échappé</strong>', '::unescape() returns an unescaped string if the value to unescape is a string');
$t->diag('::unescape() unescapes arrays');
$input = Escaper::escape('esc_entities', array('foo' => '<strong>escaped!</strong>', 'bar' => array('foo' => '<strong>escaped!</strong>')));
$output = Escaper::unescape($input);
$t->ok(is_array($output), '::unescape() returns an array if the input is a ArrayDecorator object');
$t->is($output['foo'], '<strong>escaped!</strong>', '::unescape() unescapes all elements of the original array');
$t->is($output['bar']['foo'], '<strong>escaped!</strong>', '::unescape() is recursive');
$t->diag('::unescape() unescapes objects');
$object = new OutputEscaperTestClass();
$input = Escaper::escape('esc_entities', $object);
$output = Escaper::unescape($input);
$t->ok($output instanceof OutputEscaperTestClass, '::unescape() returns the original object when a ObjectDecorator object is passed');
$t->is($output->getTitle(), '<strong>escaped!</strong>', '::unescape() unescapes all methods of the original object');
$t->is($output->title, '<strong>escaped!</strong>', '::unescape() unescapes all properties of the original object');
$t->is($output->getTitleTitle(), '<strong>escaped!</strong>', '::unescape() is recursive');
$t->ok(IteratorDecorator::unescape(Escaper::escape('esc_entities', new DirectoryIterator('.'))) instanceof DirectoryIterator, '::unescape() unescapes IteratorDecorator objects');
$t->diag('::unescape() does not unescape object marked as being safe');
$t->ok(Escaper::unescape(Escaper::escape('esc_entities', new Safe(new OutputEscaperTestClass()))) instanceof OutputEscaperTestClass, '::unescape() returns the original value if it is marked as being safe');
Escaper::markClassAsSafe('OutputEscaperTestClass');
$t->ok(Escaper::unescape(Escaper::escape('esc_entities', new OutputEscaperTestClass())) instanceof OutputEscaperTestClass, '::unescape() returns the original value if the object class is marked as being safe');
$t->ok(Escaper::unescape(Escaper::escape('esc_entities', new OutputEscaperTestClassChild())) instanceof OutputEscaperTestClassChild, '::unescape() returns the original value if one of the object parent class is marked as being safe');
$t->diag('::unescape() do nothing to resources');
$fh = fopen(__FILE__, 'r');
$t->is(Escaper::unescape($fh), $fh, '::unescape() do nothing to resources');
$t->diag('::unescape() unescapes mixed arrays');
$object = new OutputEscaperTestClass();
$input = array('foo' => 'bar', 'bar' => Escaper::escape('esc_entities', '<strong>bar</strong>'), 'foobar' => Escaper::escape('esc_entities', $object));
$output = array('foo' => 'bar', 'bar' => '<strong>bar</strong>', 'foobar' => $object);
$t->is(Escaper::unescape($input), $output, '::unescape() unescapes values with some escaped and unescaped values');
Exemple #3
0
 public function boot(ContainerInterface $container)
 {
     Escaper::markClassAsSafe('Bundle\\sfFormBundle\\Form');
 }