Sbisson has uploaded a new change for review. https://gerrit.wikimedia.org/r/217260
Change subject: [WIP] Encapsulate rc_params handling in RecentChange ...................................................................... [WIP] Encapsulate rc_params handling in RecentChange Change-Id: I443d14f5d4cdac0945cb9c03608d55745bbb865b --- M includes/changes/RecentChange.php M tests/phpunit/includes/changes/RecentChangeTest.php 2 files changed, 60 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/60/217260/1 diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 13e94db..bf806c4 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -848,4 +848,19 @@ return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge; } + + /** + * Parses and returns the rc_params attribute + * + * @return array|null + */ + public function parseParams() { + $rcParams = $this->getAttribute( 'rc_params' ); + + wfSuppressWarnings(); + $unserializedParams = unserialize( $rcParams ); + wfRestoreWarnings(); + + return $unserializedParams; + } } diff --git a/tests/phpunit/includes/changes/RecentChangeTest.php b/tests/phpunit/includes/changes/RecentChangeTest.php index e39c382..2844004 100644 --- a/tests/phpunit/includes/changes/RecentChangeTest.php +++ b/tests/phpunit/includes/changes/RecentChangeTest.php @@ -337,6 +337,51 @@ */ /** + * @covers RecentChange::parseParams + */ + public function testParseParams() { + $params = array( + 'root' => array( + 'A' => 1, + 'B' => 'two' + ) + ); + + $this->assertParseParams( + $params, + 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}' + ); + + $this->assertParseParams( + null, + null + ); + + $this->assertParseParams( + null, + serialize( false ) + ); + + $this->assertParseParams( + null, + 'not-an-array' + ); + } + + /** + * @param array $expectedParseParams + * @param string|null $rawRcParams + */ + protected function assertParseParams( $expectedParseParams, $rawRcParams ) { + $rc = new RecentChange; + $rc->setAttribs( array( 'rc_params' => $rawRcParams ) ); + + $actualParseParams = $rc->parseParams(); + + $this->assertEquals($expectedParseParams, $actualParseParams); + } + + /** * @param string $expected Expected IRC text without colors codes * @param string $type Log type (move, delete, suppress, patrol ...) * @param string $action A log type action -- To view, visit https://gerrit.wikimedia.org/r/217260 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I443d14f5d4cdac0945cb9c03608d55745bbb865b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sbisson <sbis...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits