[OutputEscaper] Add some tests
This commit is contained in:
parent
71ace34822
commit
dbfa06c54f
@ -30,6 +30,9 @@ class ObjectDecoratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$array = self::$escaped->getTitles();
|
$array = self::$escaped->getTitles();
|
||||||
$this->assertEquals('<strong>escaped!</strong>', $array[2], 'The escaped object behaves like the real object');
|
$this->assertEquals('<strong>escaped!</strong>', $array[2], 'The escaped object behaves like the real object');
|
||||||
|
|
||||||
|
$this->assertEquals('Hello <strong>Fabien</strong>', self::$escaped->sayHello('Fabien'), 'The escaped object behaves like the real object');
|
||||||
|
$this->assertEquals('Hello <strong>Fabien</strong>', self::$escaped->sayHello('Fabien', 'esc_raw'), 'The escaped object behaves like the real object');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMagicToString()
|
public function testMagicToString()
|
||||||
@ -47,6 +50,21 @@ class ObjectDecoratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue(isset(self::$escaped->someMember), 'The escaped object behaves like the real object');
|
$this->assertTrue(isset(self::$escaped->someMember), 'The escaped object behaves like the real object');
|
||||||
$this->assertFalse(isset(self::$escaped->invalidMember), 'The escaped object behaves like the real object');
|
$this->assertFalse(isset(self::$escaped->invalidMember), 'The escaped object behaves like the real object');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetRaw()
|
||||||
|
{
|
||||||
|
$this->assertEquals('<em>escape me</em>', self::$escaped->getRaw('someMember'), '->getRaw() returns result with any escaping');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException LogicException
|
||||||
|
*/
|
||||||
|
public function testGetRawException()
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$escaped = Escaper::escape('entities', $object);
|
||||||
|
$escaped->getRaw('something');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OutputEscaperTest
|
class OutputEscaperTest
|
||||||
@ -63,8 +81,18 @@ class OutputEscaperTest
|
|||||||
return '<strong>escaped!</strong>';
|
return '<strong>escaped!</strong>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sayHello($name)
|
||||||
|
{
|
||||||
|
return sprintf('Hello <strong>%s</strong>', $name);
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitles()
|
public function getTitles()
|
||||||
{
|
{
|
||||||
return array(1, 2, '<strong>escaped!</strong>');
|
return array(1, 2, '<strong>escaped!</strong>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get($key)
|
||||||
|
{
|
||||||
|
return isset($this->{$key}) ? $this->{$key} : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,13 @@ class SafeDecoratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('ok', $safe->doSomething(), '->__call() invokes the embedded method');
|
$this->assertEquals('ok', $safe->doSomething(), '->__call() invokes the embedded method');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMagicToString()
|
||||||
|
{
|
||||||
|
$safe = new SafeDecorator(new TestClass4());
|
||||||
|
|
||||||
|
$this->assertEquals('TestClass4', (string)$safe, '->__toString() invokes the embedded __toString method');
|
||||||
|
}
|
||||||
|
|
||||||
public function testMagicIssetAndUnset()
|
public function testMagicIssetAndUnset()
|
||||||
{
|
{
|
||||||
$safe = new SafeDecorator(new TestClass3());
|
$safe = new SafeDecorator(new TestClass3());
|
||||||
@ -93,3 +100,11 @@ class TestClass3
|
|||||||
$boolValue = true,
|
$boolValue = true,
|
||||||
$nullValue = null;
|
$nullValue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestClass4
|
||||||
|
{
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return 'TestClass4';
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user