From 12c76c1354f0eda88eb397912c679d535206e433 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Wed, 16 Apr 2014 11:31:29 +0200 Subject: [PATCH] Add ParserOutput::unsetProperty, add tests Change-Id: I29af31918c48a1225b6487c74fd638de26f07b28 --- includes/parser/ParserOutput.php | 4 +++ .../includes/parser/ParserOutputTest.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index b4a1c5dd8c..09f714f53c 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -585,6 +585,10 @@ class ParserOutput extends CacheTime { return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false; } + public function unsetProperty( $name ) { + unset( $this->mProperties[$name] ); + } + public function getProperties() { if ( !isset( $this->mProperties ) ) { $this->mProperties = array(); diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php index c73666dac5..c024cee545 100644 --- a/tests/phpunit/includes/parser/ParserOutputTest.php +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -56,4 +56,32 @@ class ParserOutputTest extends MediaWikiTestCase { $this->assertNull( $po->getExtensionData( "one" ) ); $this->assertEquals( "Bar", $po->getExtensionData( "two" ) ); } + + /** + * @covers ParserOutput::setProperty + * @covers ParserOutput::getProperty + * @covers ParserOutput::unsetProperty + * @covers ParserOutput::getProperties + */ + public function testProperties() { + $po = new ParserOutput(); + + $po->setProperty( 'foo', 'val' ); + + $properties = $po->getProperties(); + $this->assertEquals( $po->getProperty( 'foo' ), 'val' ); + $this->assertEquals( $properties['foo'], 'val' ); + + $po->setProperty( 'foo', 'second val' ); + + $properties = $po->getProperties(); + $this->assertEquals( $po->getProperty( 'foo' ), 'second val' ); + $this->assertEquals( $properties['foo'], 'second val' ); + + $po->unsetProperty( 'foo' ); + + $properties = $po->getProperties(); + $this->assertEquals( $po->getProperty( 'foo' ), false ); + $this->assertArrayNotHasKey( 'foo', $properties ); + } } -- 2.20.1