Add test for WikiPage::updateCategoryCounts
authoraddshore <addshorewiki@gmail.com>
Thu, 30 Nov 2017 18:23:01 +0000 (19:23 +0100)
committerAddshore <addshorewiki@gmail.com>
Mon, 4 Dec 2017 09:46:33 +0000 (09:46 +0000)
Bug: T180989
Change-Id: Iff4bb885e5d385a7b3ec6169ee9a3e1e82d7d993

tests/phpunit/includes/page/WikiPageDbTestBase.php

index 7ef279e..64ad644 100644 (file)
@@ -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() );
+       }
+
 }