diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /extensions/Gadgets/tests/GadgetTest.php | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
Diffstat (limited to 'extensions/Gadgets/tests/GadgetTest.php')
-rw-r--r-- | extensions/Gadgets/tests/GadgetTest.php | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/extensions/Gadgets/tests/GadgetTest.php b/extensions/Gadgets/tests/GadgetTest.php index 8fd09295..26d77e5f 100644 --- a/extensions/Gadgets/tests/GadgetTest.php +++ b/extensions/Gadgets/tests/GadgetTest.php @@ -4,19 +4,25 @@ */ class GadgetsTest extends MediaWikiTestCase { + /** + * @param string $line + * @return Gadget + */ private function create( $line ) { - $g = Gadget::newFromDefinition( $line ); + $repo = new MediaWikiGadgetsDefinitionRepo(); + $g = $repo->newFromDefinition( $line, 'misc' ); $this->assertInstanceOf( 'Gadget', $g ); return $g; } - function testInvalidLines() { - $this->assertFalse( Gadget::newFromDefinition( '' ) ); - $this->assertFalse( Gadget::newFromDefinition( '<foo|bar>' ) ); + public function testInvalidLines() { + $repo = new MediaWikiGadgetsDefinitionRepo(); + $this->assertFalse( $repo->newFromDefinition( '', 'misc' ) ); + $this->assertFalse( $repo->newFromDefinition( '<foo|bar>', 'misc' ) ); } - function testSimpleCases() { + public 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() ); @@ -29,30 +35,36 @@ class GadgetsTest extends MediaWikiTestCase { $this->assertTrue( $g->hasModule() ); } - function testRLtag() { + public 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() { + public 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() { + public function testPreferences() { $prefs = array(); + $repo = TestingAccessWrapper::newFromObject( new MediaWikiGadgetsDefinitionRepo() ); + // Force usage of a MediaWikiGadgetsDefinitionRepo + GadgetRepo::setSingleton( $repo ); - Gadget::loadStructuredList( '* foo | foo.js + $gadgets = $repo->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" ); + + $repo->definitionCache = $gadgets; $this->assertTrue( GadgetHooks::getPreferences( new User, $prefs ), 'GetPrefences hook should return true' ); $options = $prefs['gadgets']['options']; @@ -60,4 +72,9 @@ class GadgetsTest extends MediaWikiTestCase { $this->assertTrue( isset( $options['<gadget-section-keep-section1>'] ) ); $this->assertTrue( isset( $options['<gadget-section-keep-section2>'] ) ); } + + public function tearDown() { + GadgetRepo::setSingleton(); + parent::tearDown(); + } } |