$this->assertEquals('<strong>escaped!</strong>',Escaper::escape('raw','<strong>escaped!</strong>'),'::escape() takes an escaping strategy function name as its first argument');
}
publicfunctiontestEscapeEscapesStrings()
{
$this->assertEquals('<strong>escaped!</strong>',Escaper::escape('entities','<strong>escaped!</strong>'),'::escape() returns an escaped string if the value to escape is a string');
$this->assertEquals('<strong>échappé</strong>',Escaper::escape('entities','<strong>échappé</strong>'),'::escape() returns an escaped string if the value to escape is a string');
$this->assertInstanceOf('Symfony\Component\OutputEscaper\ArrayDecorator',$output,'::escape() returns a ArrayDecorator object if the value to escape is an array');
$this->assertInstanceOf('Symfony\Component\OutputEscaper\ObjectDecorator',$output,'::escape() returns a ObjectDecorator object if the value to escape is an object');
$this->assertEquals('<strong>escaped!</strong>',$output->getTitle(),'::escape() escapes all methods of the original object');
$this->assertEquals('<strong>escaped!</strong>',$output->title,'::escape() escapes all properties of the original object');
$this->assertEquals('<strong>escaped!</strong>',$output->getTitleTitle(),'::escape() is recursive');
$this->assertEquals($input,$output->getRawValue(),'->getRawValue() returns the unescaped value');
$this->assertEquals('<strong>escaped!</strong>',Escaper::escape('entities',$output)->getTitle(),'::escape() does not double escape an object');
$this->assertInstanceOf('Symfony\Component\OutputEscaper\IteratorDecorator',Escaper::escape('entities',new\DirectoryIterator('.')),'::escape() returns a IteratorDecorator object if the value to escape is an object that implements the ArrayAccess interface');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',Escaper::escape('entities',newSafeDecorator(newOutputEscaperTestClass())),'::escape() returns the original value if it is marked as being safe');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',Escaper::escape('entities',newOutputEscaperTestClass()),'::escape() returns the original value if the object class is marked as being safe');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',Escaper::escape('entities',newOutputEscaperTestClassChild()),'::escape() returns the original value if one of the object parent class is marked as being safe');
$this->assertNull(Escaper::unescape(null),'::unescape() returns null if the value to unescape is null');
$this->assertFalse(Escaper::unescape(false),'::unescape() returns false if the value to unescape is false');
$this->assertTrue(Escaper::unescape(true),'::unescape() returns true if the value to unescape is true');
}
publicfunctiontestUnescapeUnescapesStrings()
{
$this->assertEquals('<strong>escaped!</strong>',Escaper::unescape('<strong>escaped!</strong>'),'::unescape() returns an unescaped string if the value to unescape is a string');
$this->assertEquals('<strong>échappé</strong>',Escaper::unescape('<strong>échappé</strong>'),'::unescape() returns an unescaped string if the value to unescape is a string');
}
publicfunctiontestUnescapeUnescapesArrays()
{
$input=Escaper::escape('entities',array(
'foo'=>'<strong>escaped!</strong>',
'bar'=>array('foo'=>'<strong>escaped!</strong>'),
));
$output=Escaper::unescape($input);
$this->assertType('array',$output,'::unescape() returns an array if the input is a ArrayDecorator object');
$this->assertEquals('<strong>escaped!</strong>',$output['foo'],'::unescape() unescapes all elements of the original array');
$this->assertEquals('<strong>escaped!</strong>',$output['bar']['foo'],'::unescape() is recursive');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',$output,'::unescape() returns the original object when a ObjectDecorator object is passed');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',Escaper::unescape(Escaper::escape('entities',newSafeDecorator(newOutputEscaperTestClass()))),'::unescape() returns the original value if it is marked as being safe');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',Escaper::unescape(Escaper::escape('entities',newOutputEscaperTestClass())),'::unescape() returns the original value if the object class is marked as being safe');
$this->assertInstanceOf('Symfony\Tests\Component\OutputEscaper\OutputEscaperTestClass',Escaper::unescape(Escaper::escape('entities',newOutputEscaperTestClassChild())),'::unescape() returns the original value if one of the object parent class is marked as being safe');