2010-11-11 18:19:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @group Gadgets
|
|
|
|
*/
|
|
|
|
|
2013-05-01 01:19:35 +00:00
|
|
|
class GadgetsTest extends MediaWikiTestCase {
|
2015-07-18 22:40:42 +00:00
|
|
|
/**
|
|
|
|
* @param string $line
|
|
|
|
* @return Gadget
|
|
|
|
*/
|
2010-11-11 18:19:57 +00:00
|
|
|
private function create( $line ) {
|
2015-07-18 22:40:42 +00:00
|
|
|
$repo = new MediaWikiGadgetsDefinitionRepo();
|
|
|
|
$g = $repo->newFromDefinition( $line, 'misc' );
|
2014-06-27 00:33:13 +00:00
|
|
|
$this->assertInstanceOf( 'Gadget', $g );
|
2011-09-23 06:48:37 +00:00
|
|
|
|
2010-11-11 18:19:57 +00:00
|
|
|
return $g;
|
|
|
|
}
|
|
|
|
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testInvalidLines() {
|
2015-07-18 22:40:42 +00:00
|
|
|
$repo = new MediaWikiGadgetsDefinitionRepo();
|
|
|
|
$this->assertFalse( $repo->newFromDefinition( '', 'misc' ) );
|
|
|
|
$this->assertFalse( $repo->newFromDefinition( '<foo|bar>', 'misc' ) );
|
2010-11-11 18:19:57 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testSimpleCases() {
|
2010-11-11 18:19:57 +00:00
|
|
|
$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() );
|
|
|
|
}
|
|
|
|
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testRLtag() {
|
2010-11-11 18:19:57 +00:00
|
|
|
$g = $this->create( '*foo [ResourceLoader]|foo.js|foo.css' );
|
|
|
|
$this->assertEquals( 'foo', $g->getName() );
|
|
|
|
$this->assertTrue( $g->supportsResourceLoader() );
|
2011-09-23 06:48:37 +00:00
|
|
|
$this->assertEquals( 0, count( $g->getLegacyScripts() ) );
|
2010-11-11 18:19:57 +00:00
|
|
|
}
|
2010-11-13 18:45:21 +00:00
|
|
|
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testDependencies() {
|
2010-11-13 18:45:21 +00:00
|
|
|
$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() );
|
|
|
|
}
|
2011-04-03 19:01:52 +00:00
|
|
|
|
2015-06-17 18:21:27 +00:00
|
|
|
public function testPreferences() {
|
2011-04-03 19:01:52 +00:00
|
|
|
$prefs = array();
|
2015-07-18 22:40:42 +00:00
|
|
|
$repo = TestingAccessWrapper::newFromObject( new MediaWikiGadgetsDefinitionRepo() );
|
|
|
|
// Force usage of a MediaWikiGadgetsDefinitionRepo
|
|
|
|
GadgetRepo::setSingleton( $repo );
|
2011-04-03 19:01:52 +00:00
|
|
|
|
2015-07-18 22:40:42 +00:00
|
|
|
$gadgets = $repo->fetchStructuredList( '* foo | foo.js
|
2011-04-03 19:01:52 +00:00
|
|
|
==keep-section1==
|
|
|
|
* bar| bar.js
|
|
|
|
==remove-section==
|
|
|
|
* baz [rights=embezzle] |baz.js
|
|
|
|
==keep-section2==
|
|
|
|
* quux [rights=read] | quux.js' );
|
2015-04-30 05:33:04 +00:00
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $gadgets ), "Gadget list parsed" );
|
|
|
|
|
2015-07-18 22:40:42 +00:00
|
|
|
$repo->definitionCache = $gadgets;
|
2014-06-27 00:33:13 +00:00
|
|
|
$this->assertTrue( GadgetHooks::getPreferences( new User, $prefs ), 'GetPrefences hook should return true' );
|
2011-04-03 19:01:52 +00:00
|
|
|
|
|
|
|
$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>'] ) );
|
|
|
|
}
|
2015-07-18 22:40:42 +00:00
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
GadgetRepo::setSingleton();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2011-05-21 11:23:06 +00:00
|
|
|
}
|