Add tests for Revision::getParentLengths
authoraddshore <addshorewiki@gmail.com>
Thu, 9 Nov 2017 10:20:49 +0000 (10:20 +0000)
committeraddshore <addshorewiki@gmail.com>
Thu, 9 Nov 2017 10:43:37 +0000 (10:43 +0000)
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

tests/phpunit/includes/RevisionIntegrationTest.php

index 96ce766..48e00e0 100644 (file)
@@ -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] ]
+                       )
+               );
+       }
+
 }