Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
These are the release notes for the [SubPageList extension](../README.md).

## Version 4.0.1 (2026-04-14)

* Fixed fatal error when deleting pages due to `PageDeleteComplete` hook receiving
a `ProperPageIdentity` instead of a `WikiPage` ([#85](https://github.com/ProfessionalWiki/SubPageList/issues/85))

## Version 4.0.0 (2026-04-10)

* Added support for MediaWiki 1.44
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SubPageList",
"version": "4.0.0",
"version": "4.0.1",
"author": [
"[https://www.entropywins.wtf/mediawiki Jeroen De Dauw]",
"[https://professional.wiki/ Professional.Wiki]"
Expand Down
106 changes: 87 additions & 19 deletions tests/Unit/SubPageList/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,108 @@ public function testRun() {
}

public function testDeletedPageInvalidatesCache() {
$registeredCallbacks = [];
$callbacks = [];
$spy = $this->newSpyCacheInvalidator();

$hookContainer = $this->createMock( HookContainer::class );
$hookContainer->method( 'register' )
->willReturnCallback( function ( $name, $callback ) use ( &$registeredCallbacks ) {
$registeredCallbacks[$name] = $callback;
} );
$this->runSetupWithAutoRefresh( $spy, $callbacks );

$cacheInvalidator = new class implements CacheInvalidator {
public ?Title $invalidatedTitle = null;
$page = $this->createMock( ProperPageIdentity::class );
$page->method( 'getNamespace' )->willReturn( NS_MAIN );
$page->method( 'getDBkey' )->willReturn( 'DeletedPage' );

public function invalidateCaches( Title $title ): void {
$this->invalidatedTitle = $title;
}
};
$callbacks['PageDeleteComplete']( $page );

$this->assertCount( 1, $spy->invalidatedTitles );
$this->assertSame( 'DeletedPage', $spy->invalidatedTitles[0]->getDBkey() );
$this->assertSame( NS_MAIN, $spy->invalidatedTitles[0]->getNamespace() );
}

public function testSavedPageInvalidatesCache() {
$callbacks = [];
$spy = $this->newSpyCacheInvalidator();

$this->runSetupWithAutoRefresh( $spy, $callbacks );

$wikiPage = $this->createMock( \WikiPage::class );
$wikiPage->method( 'getTitle' )->willReturn( Title::makeTitle( NS_TALK, 'SavedPage' ) );

$callbacks['PageSaveComplete']( $wikiPage );

$this->assertCount( 1, $spy->invalidatedTitles );
$this->assertSame( 'SavedPage', $spy->invalidatedTitles[0]->getDBkey() );
$this->assertSame( NS_TALK, $spy->invalidatedTitles[0]->getNamespace() );
}

public function testMovedPageInvalidatesCacheForBothTitles() {
$callbacks = [];
$spy = $this->newSpyCacheInvalidator();

$this->runSetupWithAutoRefresh( $spy, $callbacks );

$callbacks['PageMoveComplete'](
Title::makeTitle( NS_MAIN, 'OldPage' ),
Title::makeTitle( NS_MAIN, 'NewPage' )
);

$this->assertCount( 2, $spy->invalidatedTitles );
$this->assertSame( 'OldPage', $spy->invalidatedTitles[0]->getDBkey() );
$this->assertSame( 'NewPage', $spy->invalidatedTitles[1]->getDBkey() );
}

public function testAutoRefreshDisabledDoesNotInvalidateCache() {
$callbacks = [];
$hookContainer = $this->newCapturingHookContainer( $callbacks );
$spy = $this->newSpyCacheInvalidator();

$extension = $this->createMock( Extension::class );
$extension->method( 'getSettings' )
->willReturn( new Settings( [ Settings::AUTO_REFRESH => true ] ) );
->willReturn( new Settings( [ Settings::AUTO_REFRESH => false ] ) );
$extension->method( 'getCacheInvalidator' )
->willReturn( $cacheInvalidator );
->willReturn( $spy );

$setup = new Setup( $extension, $hookContainer, __DIR__ . '/..' );
$setup->run();

$page = $this->createMock( ProperPageIdentity::class );
$page->method( 'getNamespace' )->willReturn( NS_MAIN );
$page->method( 'getDBkey' )->willReturn( 'TestPage' );
$page->method( 'getDBkey' )->willReturn( 'SomePage' );

$callbacks['PageDeleteComplete']( $page );

$this->assertEmpty( $spy->invalidatedTitles );
}

private function runSetupWithAutoRefresh( CacheInvalidator $cacheInvalidator, array &$callbacks ): void {
$hookContainer = $this->newCapturingHookContainer( $callbacks );

$this->assertArrayHasKey( 'PageDeleteComplete', $registeredCallbacks );
$registeredCallbacks['PageDeleteComplete']( $page );
$extension = $this->createMock( Extension::class );
$extension->method( 'getSettings' )
->willReturn( new Settings( [ Settings::AUTO_REFRESH => true ] ) );
$extension->method( 'getCacheInvalidator' )
->willReturn( $cacheInvalidator );

$this->assertSame( 'TestPage', $cacheInvalidator->invalidatedTitle->getDBkey() );
$this->assertSame( NS_MAIN, $cacheInvalidator->invalidatedTitle->getNamespace() );
$setup = new Setup( $extension, $hookContainer, __DIR__ . '/..' );
$setup->run();
}

private function newCapturingHookContainer( array &$callbacks ): HookContainer {
$hookContainer = $this->createMock( HookContainer::class );
$hookContainer->method( 'register' )
->willReturnCallback( function ( $name, $callback ) use ( &$callbacks ) {
$callbacks[$name] = $callback;
} );
return $hookContainer;
}

private function newSpyCacheInvalidator() {
return new class implements CacheInvalidator {
/** @var Title[] */
public array $invalidatedTitles = [];

public function invalidateCaches( Title $title ): void {
$this->invalidatedTitles[] = $title;
}
};
}

private function newExtension() {
Expand Down
Loading