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(); $context = new RequestContext(); $wgOut = $context->getOutput(); $wgOut->setTitle(Title::newFromText('test')); Gadget::loadStructuredList('* foo | foo.js ==keep-section1== * bar| bar.js ==remove-section== * baz [rights=embezzle] |baz.js ==keep-section2== * quux [rights=read] | quux.js'); $this->assertTrue(GadgetHooks::getPreferences($wgUser, $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>'])); // Restore globals $wgOut = $old_wgOut; $wgTitle = $old_wgTitle; }
function testPreferences() { $prefs = array(); Gadget::loadStructuredList('* foo | foo.js ==keep-section1== * bar| bar.js ==remove-section== * baz [rights=embezzle] |baz.js ==keep-section2== * quux [rights=read] | quux.js'); $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>'])); }
public function testPreferences() { $prefs = array(); $repo = TestingAccessWrapper::newFromObject(new MediaWikiGadgetsDefinitionRepo()); // Force usage of a MediaWikiGadgetsDefinitionRepo GadgetRepo::setSingleton($repo); $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']; $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>'])); }