public function testSortByOption() { $user = User::newFromId(1); $user->setOption('flow-topiclist-sortby', ''); // reset flow state, so everything ($container['permissions']) // uses this particular $user \FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = $user; $ctx = $this->getMock('IContextSource'); $ctx->expects($this->any())->method('getUser')->will($this->returnValue($user)); $workflow = Workflow::create('discussion', Title::newFromText('Talk:Flow_QA')); $block = new TopicListBlock($workflow, Container::get('storage')); $block->init($ctx, 'view'); $res = $block->renderApi(array()); $this->assertEquals('newest', $res['sortby'], 'With no sortby defaults to newest'); $res = $block->renderApi(array('sortby' => 'foo')); $this->assertEquals('newest', $res['sortby'], 'With invalid sortby defaults to newest'); $res = $block->renderApi(array('sortby' => 'updated')); $this->assertEquals('updated', $res['sortby'], 'With sortby updated output changes to updated'); $res = $block->renderApi(array()); $this->assertEquals('newest', $res['sortby'], 'Sort still defaults to newest'); $res = $block->renderApi(array('sortby' => 'updated', 'savesortby' => '1')); $this->assertEquals('updated', $res['sortby'], 'Request saving sortby option'); $res = $block->renderApi(array()); $this->assertEquals('updated', $res['sortby'], 'Default sortby now changed to updated'); $res = $block->renderApi(array('sortby' => '')); $this->assertEquals('updated', $res['sortby'], 'Default sortby with blank sortby still uses user default'); }
/** * Reset the container and with it any state */ protected function tearDown() { parent::tearDown(); foreach ($this->revisions as $revision) { try { $this->getStorage()->multiRemove(array($revision)); } catch (\MWException $e) { // ignore - lifecyclehandlers may cause issues with tests, where // not all related stuff is loaded } } foreach ($this->workflows as $workflow) { try { $this->getStorage()->multiRemove(array($workflow)); $found = $this->getStorage()->find('TopicListEntry', array('topic_id' => $workflow->getId())); if ($found) { $this->getStorage()->multiRemove($found); } } catch (FlowException $e) { // nothing, was probably never stored... } } // Needed because not all cases do the reset in setUp yet Container::reset(); }
public function setUp() { parent::setUp(); // reset flow state, so everything ($container['permissions']) // uses this particular $user \FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = User::newFromName('127.0.0.1', false); }
/** * Ensures Flow is reset before passing control on * to parent::doApiRequest. Defaults all requests to * the sysop user if not specified. */ protected function doApiRequest(array $params, array $session = null, $appendModule = false, User $user = null) { if ($user === null) { $user = self::$users['sysop']->user; } // reset flow state before each request FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = $user; return parent::doApiRequest($params, $session, $appendModule, $user); }
/** * {@inheritDoc} */ public function onSubmit($data) { // Replace $c['memcache'] with a hash bag o stuff. This will look to the // application layer like an empty cache, and as such it will populate this // empty cache with all the cache keys required to reload this page. // We then extract the complete list of keys updated from this hash bag o stuff // and delete them from the real memcache. // The container must be reset prior to this because the TitleSquidURLs hook // will initialize memcache before this is run when UseSquid is enabled. Container::reset(); $container = Container::getContainer(); $container->extend('memcache', function ($memcache, $c) { $c['memcache.purge_backup'] = $memcache; return new HashBagOStuff(); }); $this->hashBag = $container['memcache']; $this->realMemcache = $container['memcache.purge_backup']; if (!parent::onSubmit(array())) { return false; } /** @var WorkflowLoaderFactory $loader */ $loader = $container['factory.loader.workflow']; $workflow = $loader->createWorkflowLoader($this->page->getTitle())->getWorkflow(); switch ($workflow->getType()) { case 'discussion': $this->fetchDiscussion($workflow); break; case 'topic': $this->fetchTopics(array($workflow->getId()->getAlphadecimal() => $workflow->getId())); break; default: throw new \MWException('Unknown workflow type: ' . $workflow->getType()); } // delete all the keys we just visited $this->purgeCache(); return true; }
protected function setUp() { Container::reset(); parent::setUp(); }
/** * @dataProvider onIRCLineUrlProvider */ public function testOnIRCLineUrl($message, $metadataGen, $expectedQuery) { $user = User::newFromName('127.0.0.1', false); // reset flow state, so everything ($container['permissions']) // uses this particular $user \FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = $user; $rc = new RecentChange(); $rc->mAttribs = array('rc_namespace' => 0, 'rc_title' => 'Main Page', 'rc_source' => RecentChangesListener::SRC_FLOW); $metadata = $metadataGen($user); Container::get('formatter.irclineurl')->associate($rc, $metadata); $url = 'unset'; $query = 'unset'; $this->assertTrue(FlowHooks::onIRCLineURL($url, $query, $rc)); $expectedQuery['title'] = $metadata['workflow']->getArticleTitle()->getPrefixedDBkey(); $parts = parse_url($url); $this->assertArrayHasKey('query', $parts, $url); parse_str($parts['query'], $queryParts); foreach ($expectedQuery as $key => $value) { $this->assertEquals($value, $queryParts[$key], "Query part {$key}"); } $this->assertEquals('', $query, $message); }