Tests for WikiPage::newFromID
authoraddshore <addshorewiki@gmail.com>
Mon, 4 Dec 2017 14:14:12 +0000 (15:14 +0100)
committerKunal Mehta <legoktm@member.fsf.org>
Tue, 5 Dec 2017 19:29:17 +0000 (11:29 -0800)
Bug: T180989
Change-Id: Idb4d7ce8ccc27226b0f00e2127acef6158dd32a9

tests/phpunit/includes/page/WikiPageDbTestBase.php

index 99749a2..961b44e 100644 (file)
@@ -1389,4 +1389,37 @@ more stuff
                $assertions( $page, $this );
        }
 
                $assertions( $page, $this );
        }
 
+       public function provideTestNewFromId_returnsNullOnBadPageId() {
+               yield[ 0 ];
+               yield[ -11 ];
+       }
+
+       /**
+        * @covers WikiPage::newFromID
+        * @dataProvider provideTestNewFromId_returnsNullOnBadPageId
+        */
+       public function testNewFromId_returnsNullOnBadPageId( $pageId ) {
+               $this->assertNull( WikiPage::newFromID( $pageId ) );
+       }
+
+       /**
+        * @covers WikiPage::newFromID
+        */
+       public function testNewFromId_appearsToFetchCorrectRow() {
+               $createdPage = $this->createPage( __METHOD__, 'Xsfaij09' );
+               $fetchedPage = WikiPage::newFromID( $createdPage->getId() );
+               $this->assertSame( $createdPage->getId(), $fetchedPage->getId() );
+               $this->assertEquals(
+                       $createdPage->getContent()->getNativeData(),
+                       $fetchedPage->getContent()->getNativeData()
+               );
+       }
+
+       /**
+        * @covers WikiPage::newFromID
+        */
+       public function testNewFromId_returnsNullOnNonExistingId() {
+               $this->assertNull( WikiPage::newFromID( 73574757437437743743 ) );
+       }
+
 }
 }