From d0f584696d7aa8b28db938a4d476c07a6a972f67 Mon Sep 17 00:00:00 2001 From: addshore Date: Mon, 4 Dec 2017 15:03:41 +0100 Subject: [PATCH] Test for WikiPage::newFromRow Bug: T180989 Change-Id: If630e3e3561ac2017a2b7c82ade842e86f8cb22e --- .../includes/page/WikiPageDbTestBase.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index f6887dd058..99749a21e7 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -1303,4 +1303,90 @@ more stuff $this->assertRedirectTableCountForPageId( $page->getId(), 0 ); } + private function getRow( array $overrides = [] ) { + $row = [ + 'page_id' => '44', + 'page_len' => '76', + 'page_is_redirect' => '1', + 'page_latest' => '99', + 'page_namespace' => '3', + 'page_title' => 'JaJaTitle', + 'page_restrictions' => 'edit=autoconfirmed,sysop:move=sysop', + 'page_touched' => '20120101020202', + 'page_links_updated' => '20140101020202', + ]; + foreach ( $overrides as $key => $value ) { + $row[$key] = $value; + } + return (object)$row; + } + + public function provideNewFromRowSuccess() { + yield 'basic row' => [ + $this->getRow(), + function ( WikiPage $wikiPage, self $test ) { + $test->assertSame( 44, $wikiPage->getId() ); + $test->assertSame( 76, $wikiPage->getTitle()->getLength() ); + $test->assertTrue( $wikiPage->isRedirect() ); + $test->assertSame( 99, $wikiPage->getLatest() ); + $test->assertSame( 3, $wikiPage->getTitle()->getNamespace() ); + $test->assertSame( 'JaJaTitle', $wikiPage->getTitle()->getDBkey() ); + $test->assertSame( + [ + 'edit' => [ 'autoconfirmed', 'sysop' ], + 'move' => [ 'sysop' ], + ], + $wikiPage->getTitle()->getAllRestrictions() + ); + $test->assertSame( '20120101020202', $wikiPage->getTouched() ); + $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() ); + } + ]; + yield 'different timestamp formats' => [ + $this->getRow( [ + 'page_touched' => '2012-01-01 02:02:02', + 'page_links_updated' => '2014-01-01 02:02:02', + ] ), + function ( WikiPage $wikiPage, self $test ) { + $test->assertSame( '20120101020202', $wikiPage->getTouched() ); + $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() ); + } + ]; + yield 'no restrictions' => [ + $this->getRow( [ + 'page_restrictions' => '', + ] ), + function ( WikiPage $wikiPage, self $test ) { + $test->assertSame( + [ + 'edit' => [], + 'move' => [], + ], + $wikiPage->getTitle()->getAllRestrictions() + ); + } + ]; + yield 'not redirect' => [ + $this->getRow( [ + 'page_is_redirect' => '0', + ] ), + function ( WikiPage $wikiPage, self $test ) { + $test->assertFalse( $wikiPage->isRedirect() ); + } + ]; + } + + /** + * @covers WikiPage::newFromRow + * @covers WikiPage::loadFromRow + * @dataProvider provideNewFromRowSuccess + * + * @param object $row + * @param callable $assertions + */ + public function testNewFromRow( $row, $assertions ) { + $page = WikiPage::newFromRow( $row, 'fromdb' ); + $assertions( $page, $this ); + } + } -- 2.20.1