From f147b511929743d8b1d0a54e735666ce5cd51feb Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Wed, 14 Aug 2019 19:12:44 -0700 Subject: [PATCH] Add some tests for DerivedPageDataUpdater::isCountable. Change-Id: I82ed6fd604406d02faf4e966ec4845c8bc779a8b --- .../Storage/DerivedPageDataUpdaterTest.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) 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() -- 2.20.1