From: addshore Date: Thu, 30 Nov 2017 18:23:01 +0000 (+0100) Subject: Add test for WikiPage::updateCategoryCounts X-Git-Tag: 1.31.0-rc.0~1286^2~2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/One?a=commitdiff_plain;h=ec5d1fd6f9083637a52670ce6eba10cf569a2c29;p=lhc%2Fweb%2Fwiklou.git Add test for WikiPage::updateCategoryCounts Bug: T180989 Change-Id: Iff4bb885e5d385a7b3ec6169ee9a3e1e82d7d993 --- diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index 7ef279e174..64ad6441da 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -12,6 +12,7 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase { [ 'page', 'revision', 'archive', + 'category', 'ip_changes', 'text', @@ -1154,4 +1155,32 @@ more stuff ]; } + /** + * @covers WikiPage::updateCategoryCounts + */ + public function testUpdateCategoryCounts() { + $page = new WikiPage( Title::newFromText( __METHOD__ ) ); + + // Add an initial category + $page->updateCategoryCounts( [ 'A' ], [], 0 ); + + $this->assertEquals( 1, Category::newFromName( 'A' )->getPageCount() ); + $this->assertEquals( 0, Category::newFromName( 'B' )->getPageCount() ); + $this->assertEquals( 0, Category::newFromName( 'C' )->getPageCount() ); + + // Add a new category + $page->updateCategoryCounts( [ 'B' ], [], 0 ); + + $this->assertEquals( 1, Category::newFromName( 'A' )->getPageCount() ); + $this->assertEquals( 1, Category::newFromName( 'B' )->getPageCount() ); + $this->assertEquals( 0, Category::newFromName( 'C' )->getPageCount() ); + + // Add and remove a category + $page->updateCategoryCounts( [ 'C' ], [ 'A' ], 0 ); + + $this->assertEquals( 0, Category::newFromName( 'A' )->getPageCount() ); + $this->assertEquals( 1, Category::newFromName( 'B' )->getPageCount() ); + $this->assertEquals( 1, Category::newFromName( 'C' )->getPageCount() ); + } + }