3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\Deferred\DeferredUpdates
;
6 use MediaWiki\MainConfigNames
;
7 use MediaWiki\Title\Title
;
8 use UpdateArticleCount
;
11 * @covers \UpdateArticleCount
15 class UpdateArticleCountTest
extends MaintenanceBaseTestCase
{
17 protected function getMaintenanceClass() {
18 return UpdateArticleCount
::class;
25 private function getExistingTestPages( int $count ): array {
27 for ( $i = 0; $i < $count; $i++
) {
28 $returnArray[] = $this->getExistingTestPage()->getTitle();
33 private function getExistingTestPagesWithLinks( int $count ) {
34 $titles = $this->getExistingTestPages( $count );
35 // Replace the content of the existing pages with a wikilink.
36 foreach ( $titles as $title ) {
37 $this->editPage( $title, '[[Test]]' );
41 /** @dataProvider provideExecute */
42 public function testExecute(
43 $options, $existingPagesCount, $existingPagesWithLinksCount, $articleCountMethod,
44 $expectedArticleCountInDb, $expectedOutputString
46 $this->overrideConfigValue( MainConfigNames
::ArticleCountMethod
, $articleCountMethod );
47 // Get some testing pages
48 $this->getExistingTestPages( $existingPagesCount );
49 $this->getExistingTestPagesWithLinks( $existingPagesWithLinksCount );
50 // Call ::doUpdates to ensure that the site_stats table is properly updated before we set the value to 0.
51 DeferredUpdates
::doUpdates();
52 // Set the site_stats ss_good_articles to 0 to test that it changes after the maintenance script runs.
53 $this->getDb()->newUpdateQueryBuilder()
54 ->update( 'site_stats' )
55 ->set( [ 'ss_good_articles' => 0 ] )
56 ->where( [ 'ss_row_id' => 1 ] )
58 // Run the maintenance script
59 foreach ( $options as $name => $value ) {
60 $this->maintenance
->setOption( $name, $value );
62 $this->maintenance
->execute();
63 // Verify that the output is as expected and that the ss_good_articles column has the correct value.
64 $this->expectOutputString( $expectedOutputString );
66 'site_stats', 'ss_good_articles', [ 'ss_row_id' => 1 ],
67 [ [ $expectedArticleCountInDb ] ],
71 public static function provideExecute() {
73 'Dry-run, use-master specified, 2 pages without links, 1 with links, wgArticleCountMethod as all' => [
74 [ 'use-master' => 1 ], 2, 1, 'all', 0,
75 "Counting articles...found 3.\nTo update the site statistics table, run the script " .
76 "with the --update option.\n"
78 '1 page without links, 4 pages with links, wgArticleCountMethod as link' => [
79 [ 'update' => 1 ], 1, 4, 'link', 4,
80 "Counting articles...found 4.\nUpdating site statistics table...done.\n"