2023-12-06 07:06:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
|
2024-01-06 16:45:07 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-12-06 07:06:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo
|
|
|
|
* @group Gadgets
|
|
|
|
* @group Database
|
|
|
|
*/
|
|
|
|
class MediaWikiGadgetsDefinitionRepoTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
public function testGadgetsDefinitionRepo() {
|
|
|
|
$gadgetsDef = <<<EOT
|
|
|
|
* foo | foo.js
|
|
|
|
==keep-section1==
|
|
|
|
* bar| bar.js
|
|
|
|
==remove-section==
|
|
|
|
* baz [rights=read] |baz.js
|
|
|
|
==keep-section2==
|
|
|
|
* quux [rights=read] | quux.js
|
2024-01-05 18:23:34 +00:00
|
|
|
* g1 [ResourceLoader | default | namespaces=2 | rights=editmyuserjs] | g1.js <!-- comment -->
|
|
|
|
* g2 [ResourceLoader | default | namespaces=2 | rights=editmyuserjs] | <!-- comment --> g2.js
|
2023-12-06 07:06:06 +00:00
|
|
|
EOT;
|
|
|
|
$this->editPage( 'MediaWiki:Gadgets-definition', $gadgetsDef );
|
|
|
|
|
|
|
|
$services = $this->getServiceContainer();
|
|
|
|
$repo = new MediaWikiGadgetsDefinitionRepo( $services->getMainWANObjectCache(),
|
|
|
|
$services->getRevisionLookup() );
|
|
|
|
$gadgets = $repo->fetchStructuredList();
|
2024-01-05 18:23:34 +00:00
|
|
|
$this->assertCount( 6, $gadgets );
|
2023-12-06 07:06:06 +00:00
|
|
|
|
|
|
|
$bar = $repo->getGadget( 'bar' );
|
|
|
|
$this->assertEquals( 'keep-section1', $bar->toArray()['category'] );
|
2024-01-05 18:23:34 +00:00
|
|
|
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-g1.js' ], $repo->getGadget( 'g1' )->getScripts() );
|
|
|
|
$this->assertEquals( [ 'MediaWiki:Gadget-g2.js' ], $repo->getGadget( 'g2' )->getScripts() );
|
2023-12-06 07:06:06 +00:00
|
|
|
}
|
|
|
|
|
2023-12-09 06:35:12 +00:00
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Hooks::onPageSaveComplete
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\Hooks::onPageDeleteComplete
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\GadgetRepo::handlePageUpdate
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo
|
|
|
|
*/
|
|
|
|
public function testCacheInvalidationOnSave() {
|
|
|
|
$services = $this->getServiceContainer();
|
2023-12-13 03:08:38 +00:00
|
|
|
$wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff ] );
|
2023-12-09 06:35:12 +00:00
|
|
|
$wanCache->useInterimHoldOffCaching( false );
|
|
|
|
|
|
|
|
$repo = new MediaWikiGadgetsDefinitionRepo( $wanCache, $services->getRevisionLookup() );
|
|
|
|
$this->setService( 'GadgetsRepo', $repo );
|
|
|
|
|
|
|
|
$this->editPage( 'MediaWiki:Gadgets-definition', '* X1[ResourceLoader|default]|foo.js' );
|
|
|
|
$this->assertEquals( [ 'X1' ], $repo->getGadgetIds() );
|
|
|
|
$this->assertTrue( $repo->getGadget( 'X1' )->isOnByDefault() );
|
|
|
|
|
|
|
|
$this->editPage( 'MediaWiki:Gadgets-definition', "* X1[ResourceLoader|default]|foo.js\n" .
|
|
|
|
"* X2[ResourceLoader|default]|foo.css" );
|
|
|
|
$this->assertEquals( [ 'X1', 'X2' ], $repo->getGadgetIds() );
|
|
|
|
|
|
|
|
// Disable X1 by default
|
|
|
|
$this->editPage( 'MediaWiki:Gadgets-definition', "* X1[ResourceLoader]|foo.js\n" .
|
|
|
|
"* X2[ResourceLoader|default]|foo.css" );
|
|
|
|
$this->assertFalse( $repo->getGadget( 'X1' )->isOnByDefault() );
|
|
|
|
|
|
|
|
$this->deletePage( $services->getWikiPageFactory()->newFromTitle(
|
|
|
|
Title::newFromText( 'MediaWiki:Gadgets-definition' ) ) );
|
|
|
|
$this->assertEquals( [], $repo->getGadgetIds() );
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:06:06 +00:00
|
|
|
}
|