3 namespace MediaWiki\Tests\Maintenance
;
6 use MediaWiki\Title\Title
;
7 use Wikimedia\Rdbms\IDBAccessObject
;
10 * @covers \AttachLatest
14 class AttachLatestTest
extends MaintenanceBaseTestCase
{
16 protected function getMaintenanceClass() {
17 return AttachLatest
::class;
22 * @return Title[] The test pages as values, with the keys as the expected values of page_latest after the
23 * maintenance script run.
25 private function getPagesWithPageLatestAsZero( int $count ): array {
27 for ( $i = 0; $i < $count; $i++
) {
28 $existingTestPage = $this->getExistingTestPage();
29 $returnArray[$existingTestPage->getRevisionRecord()->getId()] = $existingTestPage->getTitle();
31 // Set the page_latest as 0 for the test on all pages in $returnArray
32 $pageIds = array_map( static function ( $page ) {
33 return $page->getId();
35 if ( count( $pageIds ) ) {
36 $this->getDb()->newUpdateQueryBuilder()
38 ->set( [ 'page_latest' => 0 ] )
39 ->where( [ 'page_id' => $pageIds ] )
45 /** @dataProvider provideExecute */
46 public function testExecute( $brokenCount ) {
47 $pagesThatNeedFixing = $this->getPagesWithPageLatestAsZero( $brokenCount );
48 // Run the maintenance script with 'fix' specified to actually fix the broken page rows.
49 $this->maintenance
->setOption( 'fix', 1 );
50 $this->maintenance
->execute();
51 // Verify that the page_latest field has been fixed for all the pages that needed fixed.
52 $expectedOutputRegex = '/';
53 foreach ( $pagesThatNeedFixing as $expectedLatestRevId => $title ) {
54 $expectedOutputRegex .= '.*' . $title->getPrefixedText() . '.*' . $expectedLatestRevId . "\n";
57 $title->getLatestRevID( IDBAccessObject
::READ_LATEST
),
58 'page_latest was not properly fixed by the maintenance script'
61 $expectedOutputRegex .= ".*Done! Processed $brokenCount pages./";
62 $this->expectOutputRegex( $expectedOutputRegex );
65 public static function provideExecute() {
67 'No broken pages' => [ 0 ],
68 'Five broken pages' => [ 5 ],