RevisionUnitTest for various getters and setters
authoraddshore <addshorewiki@gmail.com>
Sat, 14 Oct 2017 13:07:22 +0000 (14:07 +0100)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 17 Oct 2017 00:55:24 +0000 (17:55 -0700)
getId
setId
setUserIdAndName
getTextId
getParentId

Change-Id: I1890122c0eae16947a4782bc14baa8c3b9ce1391

tests/phpunit/includes/RevisionUnitTest.php

index 5282ae6..24f0b64 100644 (file)
@@ -74,6 +74,87 @@ class RevisionUnitTest extends MediaWikiTestCase {
                ];
        }
 
+       public function provideGetId() {
+               yield [
+                       [],
+                       null
+               ];
+               yield [
+                       [ 'id' => 998 ],
+                       998
+               ];
+       }
+
+       /**
+        * @dataProvider provideGetId
+        * @covers Revision::getId
+        */
+       public function testGetId( $rowArray, $expectedId ) {
+               $rev = new Revision( $rowArray );
+               $this->assertEquals( $expectedId, $rev->getId() );
+       }
+
+       public function provideSetId() {
+               yield [ '123', 123 ];
+               yield [ 456, 456 ];
+       }
+
+       /**
+        * @dataProvider provideSetId
+        * @covers Revision::setId
+        */
+       public function testSetId( $input, $expected ) {
+               $rev = new Revision( [] );
+               $rev->setId( $input );
+               $this->assertSame( $expected, $rev->getId() );
+       }
+
+       public function provideSetUserIdAndName() {
+               yield [ '123', 123, 'GOaT' ];
+               yield [ 456, 456, 'GOaT' ];
+       }
+
+       /**
+        * @dataProvider provideSetUserIdAndName
+        * @covers Revision::setUserIdAndName
+        */
+       public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
+               $rev = new Revision( [] );
+               $rev->setUserIdAndName( $inputId, $name );
+               $this->assertSame( $expectedId, $rev->getUser( Revision::RAW ) );
+               $this->assertEquals( $name, $rev->getUserText( Revision::RAW ) );
+       }
+
+       public function provideGetTextId() {
+               yield [ [], null ];
+               yield [ [ 'text_id' => '123' ], 123 ];
+               yield [ [ 'text_id' => 456 ], 456 ];
+       }
+
+       /**
+        * @dataProvider provideGetTextId
+        * @covers Revision::getTextId()
+        */
+       public function testGetTextId( $rowArray, $expected ) {
+               $rev = new Revision( $rowArray );
+               $this->assertSame( $expected, $rev->getTextId() );
+       }
+
+       public function provideGetParentId() {
+               yield [ [], null ];
+               yield [ [ 'parent_id' => '123' ], 123 ];
+               yield [ [ 'parent_id' => 456 ], 456 ];
+       }
+
+       /**
+        * @dataProvider provideGetParentId
+        * @covers Revision::getParentId()
+        */
+       public function testGetParentId( $rowArray, $expected ) {
+               $rev = new Revision( $rowArray );
+               $this->assertSame( $expected, $rev->getParentId() );
+       }
+
        /**
         * @covers Revision::getRevisionText
         * @dataProvider provideGetRevisionText