diff options
author | C. Scott Ananian <cscott@cscott.net> | 2024-02-16 10:12:12 -0500 |
---|---|---|
committer | C. Scott Ananian <cscott@cscott.net> | 2024-04-05 19:12:29 -0400 |
commit | de57c4e7c271680df5f2e07245c1f9af97816978 (patch) | |
tree | 707076f8872cd7e86b4be5da4b5c0aebe5d27753 /tests/phpunit/includes/parser/ParserOutputTest.php | |
parent | e9218f6afaecd6a06d7aacdcd03e2e81aacf29ce (diff) | |
download | mediawikicore-de57c4e7c271680df5f2e07245c1f9af97816978.tar.gz mediawikicore-de57c4e7c271680df5f2e07245c1f9af97816978.zip |
Add ParserOutput::setIndexedPageProperty(); deprecate numeric properties
Deprecate non-string values to ::setPageProperty(), which introduce easy
traps for programmers to fall into. Instead if page properties are intended
to be indexed, use the new ::setIndexedPageProperty() instead. Also add
::setUnindexedPageProperty() for symmetry, with a tighter string type on
the value.
Bug: T305158
Bug: T350224
Change-Id: I8a39a7c90341dfee932aa819c9a0a637a8782f69
Diffstat (limited to 'tests/phpunit/includes/parser/ParserOutputTest.php')
-rw-r--r-- | tests/phpunit/includes/parser/ParserOutputTest.php | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php index d45c100d8afc..e8e6483847ff 100644 --- a/tests/phpunit/includes/parser/ParserOutputTest.php +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -176,24 +176,27 @@ class ParserOutputTest extends MediaWikiLangTestCase { /** * @covers \MediaWiki\Parser\ParserOutput::setPageProperty + * @covers \MediaWiki\Parser\ParserOutput::setIndexedPageProperty + * @covers \MediaWiki\Parser\ParserOutput::setUnindexedPageProperty * @covers \MediaWiki\Parser\ParserOutput::getPageProperty * @covers \MediaWiki\Parser\ParserOutput::unsetPageProperty * @covers \MediaWiki\Parser\ParserOutput::getPageProperties + * @dataProvider providePageProperties */ - public function testProperties() { + public function testPageProperties( string $setPageProperty, $value1, $value2 ) { $po = new ParserOutput(); - $po->setPageProperty( 'foo', 'val' ); + $po->$setPageProperty( 'foo', $value1 ); $properties = $po->getPageProperties(); - $this->assertSame( 'val', $po->getPageProperty( 'foo' ) ); - $this->assertSame( 'val', $properties['foo'] ); + $this->assertSame( $value1, $po->getPageProperty( 'foo' ) ); + $this->assertSame( $value1, $properties['foo'] ); - $po->setPageProperty( 'foo', 'second val' ); + $po->$setPageProperty( 'foo', $value2 ); $properties = $po->getPageProperties(); - $this->assertSame( 'second val', $po->getPageProperty( 'foo' ) ); - $this->assertSame( 'second val', $properties['foo'] ); + $this->assertSame( $value2, $po->getPageProperty( 'foo' ) ); + $this->assertSame( $value2, $properties['foo'] ); $po->unsetPageProperty( 'foo' ); @@ -202,6 +205,39 @@ class ParserOutputTest extends MediaWikiLangTestCase { $this->assertArrayNotHasKey( 'foo', $properties ); } + public static function providePageProperties() { + yield 'Unindexed' => [ 'setUnindexedPageProperty', 'val', 'second val' ]; + yield 'Indexed' => [ 'setIndexedPageProperty', 42, 3.14 ]; + yield 'Unindexed (old style)' => [ 'setPageProperty', 'val', 'second val' ]; + yield 'Indexed (old style)' => [ 'setPageProperty', 123, 456 ]; + } + + /** + * @covers \MediaWiki\Parser\ParserOutput::setIndexedPageProperty + */ + public function testIndexedPageProperties() { + $po = new ParserOutput(); + + $po->setIndexedPageProperty( 'foo', '123' ); + + $properties = $po->getPageProperties(); + $this->assertSame( 123, $po->getPageProperty( 'foo' ) ); + $this->assertSame( 123, $properties['foo'] ); + } + + /** + * @covers \MediaWiki\Parser\ParserOutput::setUnindexedPageProperty + */ + public function testUnindexedPageProperties() { + $po = new ParserOutput(); + + $po->setUnindexedPageProperty( 'foo', 123 ); + + $properties = $po->getPageProperties(); + $this->assertSame( '123', $po->getPageProperty( 'foo' ) ); + $this->assertSame( '123', $properties['foo'] ); + } + /** * @covers \MediaWiki\Parser\ParserOutput::setLanguage * @covers \MediaWiki\Parser\ParserOutput::getLanguage |