| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\Deferred\DeferredUpdates; |
| 6 |
use MediaWiki\MainConfigNames; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
use UpdateArticleCount; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class UpdateArticleCountTest extends MaintenanceBaseTestCase { |
| 16 |
|
| 17 |
protected function getMaintenanceClass() { |
| 18 |
return UpdateArticleCount::class; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
private function getExistingTestPages( int $count ): array { |
| 26 |
$returnArray = []; |
| 27 |
for ( $i = 0; $i < $count; $i++ ) { |
| 28 |
$returnArray[] = $this->getExistingTestPage()->getTitle(); |
| 29 |
} |
| 30 |
return $returnArray; |
| 31 |
} |
| 32 |
|
| 33 |
private function getExistingTestPagesWithLinks( int $count ) { |
| 34 |
$titles = $this->getExistingTestPages( $count ); |
| 35 |
|
| 36 |
foreach ( $titles as $title ) { |
| 37 |
$this->editPage( $title, '[[Test]]' ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
public function testExecute( |
| 43 |
$options, $existingPagesCount, $existingPagesWithLinksCount, $articleCountMethod, |
| 44 |
$expectedArticleCountInDb, $expectedOutputString |
| 45 |
) { |
| 46 |
$this->overrideConfigValue( MainConfigNames::ArticleCountMethod, $articleCountMethod ); |
| 47 |
|
| 48 |
$this->getExistingTestPages( $existingPagesCount ); |
| 49 |
$this->getExistingTestPagesWithLinks( $existingPagesWithLinksCount ); |
| 50 |
|
| 51 |
DeferredUpdates::doUpdates(); |
| 52 |
|
| 53 |
$this->getDb()->newUpdateQueryBuilder() |
| 54 |
->update( 'site_stats' ) |
| 55 |
->set( [ 'ss_good_articles' => 0 ] ) |
| 56 |
->where( [ 'ss_row_id' => 1 ] ) |
| 57 |
->execute(); |
| 58 |
|
| 59 |
foreach ( $options as $name => $value ) { |
| 60 |
$this->maintenance->setOption( $name, $value ); |
| 61 |
} |
| 62 |
$this->maintenance->execute(); |
| 63 |
|
| 64 |
$this->expectOutputString( $expectedOutputString ); |
| 65 |
$this->assertSelect( |
| 66 |
'site_stats', 'ss_good_articles', [ 'ss_row_id' => 1 ], |
| 67 |
[ [ $expectedArticleCountInDb ] ], |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
public static function provideExecute() { |
| 72 |
return [ |
| 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" |
| 77 |
], |
| 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" |
| 81 |
], |
| 82 |
]; |
| 83 |
} |
| 84 |
} |