mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-15 19:39:33 +00:00
11e1c51d6b
* Bumped the key version due to key wrapping
* Removed isValidList() gived the key versioning
* Follow up ba1311c323
by making APC viable;
previously, definition purges would not work
Bug: T93141
Change-Id: I6da3eede044bf4b840b3f9656a1ae8105941dc6b
67 lines
2.3 KiB
PHP
Executable file
67 lines
2.3 KiB
PHP
Executable file
<?php
|
|
/**
|
|
* @group Gadgets
|
|
*/
|
|
|
|
class GadgetsTest extends MediaWikiTestCase {
|
|
private function create( $line ) {
|
|
$g = Gadget::newFromDefinition( $line );
|
|
$this->assertInstanceOf( 'Gadget', $g );
|
|
|
|
return $g;
|
|
}
|
|
|
|
function testInvalidLines() {
|
|
$this->assertFalse( Gadget::newFromDefinition( '' ) );
|
|
$this->assertFalse( Gadget::newFromDefinition( '<foo|bar>' ) );
|
|
}
|
|
|
|
function testSimpleCases() {
|
|
$g = $this->create( '* foo bar| foo.css|foo.js|foo.bar' );
|
|
$this->assertEquals( 'foo_bar', $g->getName() );
|
|
$this->assertEquals( 'ext.gadget.foo_bar', $g->getModuleName() );
|
|
$this->assertEquals( array( 'Gadget-foo.js' ), $g->getScripts() );
|
|
$this->assertEquals( array( 'Gadget-foo.css' ), $g->getStyles() );
|
|
$this->assertEquals( array( 'Gadget-foo.js', 'Gadget-foo.css' ),
|
|
$g->getScriptsAndStyles() );
|
|
$this->assertEquals( array( 'Gadget-foo.js' ), $g->getLegacyScripts() );
|
|
$this->assertFalse( $g->supportsResourceLoader() );
|
|
$this->assertTrue( $g->hasModule() );
|
|
}
|
|
|
|
function testRLtag() {
|
|
$g = $this->create( '*foo [ResourceLoader]|foo.js|foo.css' );
|
|
$this->assertEquals( 'foo', $g->getName() );
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
|
$this->assertEquals( 0, count( $g->getLegacyScripts() ) );
|
|
}
|
|
|
|
function testDependencies() {
|
|
$g = $this->create( '* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
|
|
$this->assertEquals( array( 'Gadget-bar.js' ), $g->getScripts() );
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
|
$this->assertEquals( array( 'jquery.ui' ), $g->getDependencies() );
|
|
}
|
|
|
|
function testPreferences() {
|
|
$prefs = array();
|
|
|
|
$gadgets = Gadget::fetchStructuredList( '* foo | foo.js
|
|
==keep-section1==
|
|
* bar| bar.js
|
|
==remove-section==
|
|
* baz [rights=embezzle] |baz.js
|
|
==keep-section2==
|
|
* quux [rights=read] | quux.js' );
|
|
$this->assertGreaterThanOrEqual( 2, count( $gadgets ), "Gadget list parsed" );
|
|
|
|
Gadget::injectDefinitionCache( $gadgets );
|
|
$this->assertTrue( GadgetHooks::getPreferences( new User, $prefs ), 'GetPrefences hook should return true' );
|
|
|
|
$options = $prefs['gadgets']['options'];
|
|
$this->assertFalse( isset( $options['<gadget-section-remove-section>'] ), 'Must not show empty sections' );
|
|
$this->assertTrue( isset( $options['<gadget-section-keep-section1>'] ) );
|
|
$this->assertTrue( isset( $options['<gadget-section-keep-section2>'] ) );
|
|
}
|
|
}
|