From 58be73fcf779359c2848cc1185e368f012639f24 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 1 Oct 2006 18:39:48 +0000 Subject: [PATCH] [1.2.0] Added exists() method to HTMLPurifier_Context. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@483 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/Context.php | 8 ++++++++ tests/HTMLPurifier/ContextTest.php | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/HTMLPurifier/Context.php b/library/HTMLPurifier/Context.php index 1f58671e..93942ada 100644 --- a/library/HTMLPurifier/Context.php +++ b/library/HTMLPurifier/Context.php @@ -52,6 +52,14 @@ class HTMLPurifier_Context unset($this->_storage[$name]); } + /** + * Checks whether or not the variable exists. + * @param $name String name + */ + function exists($name) { + return isset($this->_storage[$name]); + } + } ?> \ No newline at end of file diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index b8f5014f..caf8e367 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -18,13 +18,17 @@ class HTMLPurifier_ContextTest extends UnitTestCase generate_mock_once('HTMLPurifier_IDAccumulator'); + $this->assertFalse($this->context->exists('IDAccumulator')); + $accumulator =& new HTMLPurifier_IDAccumulatorMock($this); $this->context->register('IDAccumulator', $accumulator); - // ... + $this->assertTrue($this->context->exists('IDAccumulator')); + $accumulator_2 =& $this->context->get('IDAccumulator'); $this->assertReference($accumulator, $accumulator_2); $this->context->destroy('IDAccumulator'); + $this->assertFalse($this->context->exists('IDAccumulator')); $accumulator_3 =& $this->context->get('IDAccumulator'); $this->assertError('Attempted to retrieve non-existent variable'); $this->assertNull($accumulator_3);