wiki.techinc.nl/tests/phpunit/maintenance/WikiBirthdayTest.php
Dreamy Jazz 0532313deb Test wikiBirthday.php
Why:
* Maintenance scripts in core are mostly untested, and testing the
  scripts which are less complex will allow raising the test
  coverage.
* Furthermore, when testing these scripts bugs can be found which
  can then be fixed. In this commit, a bug is found where the
  script fails to generate the correct age for the wiki if the
  wiki has no revisions in the revision table but does in the
  archive table.

What:
* Fix wikiBirthday.php to correctly generate the age when the
  wiki has no undeleted revisions.
* Create WikiBirthdayTest which covers the script.

Bug: T371167
Change-Id: I15721f076beb8221bd4fa1ce8cb7a7f07635c1b5
2024-08-10 09:28:21 +00:00

43 lines
1.5 KiB
PHP

<?php
namespace MediaWiki\Tests\Maintenance;
use MediaWiki\Title\Title;
use WikiBirthday;
use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
* @covers \WikiBirthday
* @group Database
* @author Dreamy Jazz
*/
class WikiBirthdayTest extends MaintenanceBaseTestCase {
protected function getMaintenanceClass() {
return WikiBirthday::class;
}
public function testExecuteForOneRevision() {
// Create a fake revision with a set timestamp
ConvertibleTimestamp::setFakeTime( '20230405060708' );
$this->editPage( Title::newFromText( 'Testing1234' ), 'Test1234' );
// Set the timestamp to a year in advance
ConvertibleTimestamp::setFakeTime( '20240405060708' );
$this->maintenance->execute();
$this->expectOutputRegex( '/Wiki was created on: 5 April 2023.*age: 1 yr.*0 month.*0 day.*old/' );
}
public function testExecuteForDeletedRevision() {
// Create a fake revision with a set timestamp, and then delete the associated page
ConvertibleTimestamp::setFakeTime( '20230505060708' );
$editStatus = $this->editPage( Title::newFromText( 'Testing1234' ), 'Test1234' );
ConvertibleTimestamp::setFakeTime( '20230505060709' );
$this->deletePage( $this->getServiceContainer()->getWikiPageFactory()->newFromTitle(
$editStatus->getNewRevision()->getPage()
) );
// Set the timestamp to 3 months and 3 days in advance
ConvertibleTimestamp::setFakeTime( '20230708060708' );
$this->maintenance->execute();
$this->expectOutputRegex( '/Wiki was created on: 5 May.*age: 0 yr.*2 month.*3 day.*old/' );
}
}