Skip to content

Commit

Permalink
[OutputEscaper] Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Pennequin authored and fabpot committed Oct 18, 2010
1 parent 71ace34 commit dbfa06c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Expand Up @@ -30,6 +30,9 @@ public function testGenericBehavior()

$array = self::$escaped->getTitles();
$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()
Expand All @@ -47,6 +50,21 @@ public function testMagicIsset()
$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');
}

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
Expand All @@ -63,8 +81,18 @@ public function getTitle()
return '<strong>escaped!</strong>';
}

public function sayHello($name)
{
return sprintf('Hello <strong>%s</strong>', $name);
}

public function getTitles()
{
return array(1, 2, '<strong>escaped!</strong>');
}

public function get($key)
{
return isset($this->{$key}) ? $this->{$key} : null;
}
}
15 changes: 15 additions & 0 deletions tests/Symfony/Tests/Component/OutputEscaper/SafeDecoratorTest.php
Expand Up @@ -37,6 +37,13 @@ public function testMagicCall()
$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()
{
$safe = new SafeDecorator(new TestClass3());
Expand Down Expand Up @@ -93,3 +100,11 @@ class TestClass3
$boolValue = true,
$nullValue = null;
}

class TestClass4
{
public function __toString()
{
return 'TestClass4';
}
}

0 comments on commit dbfa06c

Please sign in to comment.