From: Petr Pchelko Date: Thu, 15 Aug 2019 02:12:44 +0000 (-0700) Subject: Add some tests for DerivedPageDataUpdater::isCountable. X-Git-Tag: 1.34.0-rc.0~711^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=f147b511929743d8b1d0a54e735666ce5cd51feb;p=lhc%2Fweb%2Fwiklou.git Add some tests for DerivedPageDataUpdater::isCountable. Change-Id: I82ed6fd604406d02faf4e966ec4845c8bc779a8b --- diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php index cd19cca81a..3b3e7416e1 100644 --- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php +++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php @@ -874,6 +874,77 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase { ); } + /** + * * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isCountable + */ + public function testIsCountableNotContentPage() { + $updater = $this->getDerivedPageDataUpdater( + Title::newFromText( 'Main_Page', NS_TALK ) + ); + self::assertFalse( $updater->isCountable() ); + } + + public function provideIsCountable() { + yield 'deleted revision' => [ + '$articleCountMethod' => 'any', + '$wikitextContent' => 'Test', + '$revisionVisibility' => RevisionRecord::SUPPRESSED_ALL, + '$isCountable' => false + ]; + yield 'redirect' => [ + '$articleCountMethod' => 'any', + '$wikitextContent' => '#REDIRECT [[Main_Page]]', + '$revisionVisibility' => 0, + '$isCountable' => false + ]; + yield 'no links count method any' => [ + '$articleCountMethod' => 'any', + '$wikitextContent' => 'Test', + '$revisionVisibility' => 0, + '$isCountable' => true + ]; + yield 'no links count method link' => [ + '$articleCountMethod' => 'link', + '$wikitextContent' => 'Test', + '$revisionVisibility' => 0, + '$isCountable' => false + ]; + yield 'with links count method link' => [ + '$articleCountMethod' => 'link', + '$wikitextContent' => '[[Test]]', + '$revisionVisibility' => 0, + '$isCountable' => true + ]; + } + + /** + * @dataProvider provideIsCountable + * + * @param string $articleCountMethod + * @param string $wikitextContent + * @param int $revisionVisibility + * @param bool $isCountable + * @throws \MWException + * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isCountable + */ + public function testIsCountable( + $articleCountMethod, + $wikitextContent, + $revisionVisibility, + $isCountable + ) { + $this->setMwGlobals( [ 'wgArticleCountMethod' => $articleCountMethod ] ); + $title = $this->getTitle( 'Main_Page' ); + $content = new WikitextContent( $wikitextContent ); + $update = new RevisionSlotsUpdate(); + $update->modifyContent( SlotRecord::MAIN, $content ); + $revision = $this->makeRevision( $title, $update, User::newFromName( 'Alice' ), 'rev1', 13 ); + $revision->setVisibility( $revisionVisibility ); + $updater = $this->getDerivedPageDataUpdater( $title ); + $updater->prepareUpdate( $revision ); + self::assertSame( $isCountable, $updater->isCountable() ); + } + /** * @covers \MediaWiki\Storage\DerivedPageDataUpdater::doUpdates() * @covers \MediaWiki\Storage\DerivedPageDataUpdater::doSecondaryDataUpdates()