Improve tests

* Reduce globals usage thanks to core improvements
* Use new assertion that wasn't available before

Change-Id: I9b7fb065ea9e235e6c5e7ea5116ccacac91f8846
This commit is contained in:
Max Semenik 2014-06-26 17:33:13 -07:00
parent f251892b42
commit c2be054951

View file

@ -6,8 +6,7 @@
class GadgetsTest extends MediaWikiTestCase { class GadgetsTest extends MediaWikiTestCase {
private function create( $line ) { private function create( $line ) {
$g = Gadget::newFromDefinition( $line ); $g = Gadget::newFromDefinition( $line );
// assertInstanceOf() is available since PHPUnit 3.5 $this->assertInstanceOf( 'Gadget', $g );
$this->assertEquals( 'Gadget', get_class( $g ) );
return $g; return $g;
} }
@ -45,20 +44,7 @@ class GadgetsTest extends MediaWikiTestCase {
} }
function testPreferences() { function testPreferences() {
global $wgUser, $wgOut, $wgTitle;
// This test makes call to the parser which requires valids Outputpage
// and Title objects. Set them up there, they will be released at the
// end of the test.
$old_wgOut = $wgOut;
$old_wgTitle = $wgTitle;
$wgTitle = Title::newFromText( 'Parser test for Gadgets extension' );
// Proceed with test setup:
$prefs = array(); $prefs = array();
$context = new RequestContext();
$wgOut = $context->getOutput();
$wgOut->setTitle( Title::newFromText( 'test' ) );
Gadget::loadStructuredList( '* foo | foo.js Gadget::loadStructuredList( '* foo | foo.js
==keep-section1== ==keep-section1==
@ -67,15 +53,11 @@ class GadgetsTest extends MediaWikiTestCase {
* baz [rights=embezzle] |baz.js * baz [rights=embezzle] |baz.js
==keep-section2== ==keep-section2==
* quux [rights=read] | quux.js' ); * quux [rights=read] | quux.js' );
$this->assertTrue( GadgetHooks::getPreferences( $wgUser, $prefs ), 'GetPrefences hook should return true' ); $this->assertTrue( GadgetHooks::getPreferences( new User, $prefs ), 'GetPrefences hook should return true' );
$options = $prefs['gadgets']['options']; $options = $prefs['gadgets']['options'];
$this->assertFalse( isset( $options['<gadget-section-remove-section>'] ), 'Must not show empty sections' ); $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-section1>'] ) );
$this->assertTrue( isset( $options['<gadget-section-keep-section2>'] ) ); $this->assertTrue( isset( $options['<gadget-section-keep-section2>'] ) );
// Restore globals
$wgOut = $old_wgOut;
$wgTitle = $old_wgTitle;
} }
} }