From: addshore Date: Thu, 9 Nov 2017 10:20:49 +0000 (+0000) Subject: Add tests for Revision::getParentLengths X-Git-Tag: 1.31.0-rc.0~1568 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=763546fea509a5272d4cc33e5367ec3e2c1faaa7 Add tests for Revision::getParentLengths This method name is quite missleading as it doesnt get the parent lengths at all, it gets the lengths of the rev ids that you ask for...... This method is touched in I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2 hence adding some test coverage now. Change-Id: Ic837bd60a34341860c4d2287a1b999f40d4f95f1 --- diff --git a/tests/phpunit/includes/RevisionIntegrationTest.php b/tests/phpunit/includes/RevisionIntegrationTest.php index 96ce7660c4..48e00e0e2c 100644 --- a/tests/phpunit/includes/RevisionIntegrationTest.php +++ b/tests/phpunit/includes/RevisionIntegrationTest.php @@ -991,4 +991,59 @@ class RevisionIntegrationTest extends MediaWikiTestCase { ); } + /** + * @covers Revision::getParentLengths + */ + public function testGetParentLengths_noRevIds() { + $this->assertSame( + [], + Revision::getParentLengths( + wfGetDB( DB_MASTER ), + [] + ) + ); + } + + /** + * @covers Revision::getParentLengths + */ + public function testGetParentLengths_oneRevId() { + $text = '831jr091jr0921kr21kr0921kjr0921j09rj1'; + $textLength = strlen( $text ); + + $this->testPage->doEditContent( new WikitextContent( $text ), __METHOD__ ); + $rev[1] = $this->testPage->getLatest(); + + $this->assertSame( + [ $rev[1] => strval( $textLength ) ], + Revision::getParentLengths( + wfGetDB( DB_MASTER ), + [ $rev[1] ] + ) + ); + } + + /** + * @covers Revision::getParentLengths + */ + public function testGetParentLengths_multipleRevIds() { + $textOne = '831jr091jr0921kr21kr0921kjr0921j09rj1'; + $textOneLength = strlen( $textOne ); + $textTwo = '831jr091jr092121j09rj1'; + $textTwoLength = strlen( $textTwo ); + + $this->testPage->doEditContent( new WikitextContent( $textOne ), __METHOD__ ); + $rev[1] = $this->testPage->getLatest(); + $this->testPage->doEditContent( new WikitextContent( $textTwo ), __METHOD__ ); + $rev[2] = $this->testPage->getLatest(); + + $this->assertSame( + [ $rev[1] => strval( $textOneLength ), $rev[2] => strval( $textTwoLength ) ], + Revision::getParentLengths( + wfGetDB( DB_MASTER ), + [ $rev[1], $rev[2] ] + ) + ); + } + }